@izzai/one-js 1.0.2
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.md +1 -0
- package/dist/customTypes/auth.d.ts +4 -0
- package/dist/customTypes/auth.js +2 -0
- package/dist/customTypes/chat.d.ts +4 -0
- package/dist/customTypes/chat.js +2 -0
- package/dist/customTypes/index.d.ts +2 -0
- package/dist/customTypes/index.js +18 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +25 -0
- package/dist/services/agent.d.ts +5 -0
- package/dist/services/agent.js +18 -0
- package/dist/services/base.d.ts +14 -0
- package/dist/services/base.js +69 -0
- package/dist/services/chat.d.ts +12 -0
- package/dist/services/chat.js +54 -0
- package/dist/services/datasource.d.ts +5 -0
- package/dist/services/datasource.js +13 -0
- package/dist/services/gpt.d.ts +5 -0
- package/dist/services/gpt.js +17 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.js +14 -0
- package/package.json +78 -0
- package/readme.md +56 -0
package/LICENSE.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
United Innovations GmbH
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./auth"), exports);
|
18
|
+
__exportStar(require("./chat"), exports);
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { OneAuth } from './customTypes';
|
2
|
+
import { BaseService } from './services/base';
|
3
|
+
export declare class One extends BaseService {
|
4
|
+
private _services?;
|
5
|
+
constructor(instanceId: string, auth: OneAuth, baseUrl?: string);
|
6
|
+
get agent(): import("./services/agent").AgentService;
|
7
|
+
get chat(): import("./services/chat").ChatService;
|
8
|
+
get datasource(): import("./services/datasource").DatasourceService;
|
9
|
+
get gpt(): import("./services/gpt").GptService;
|
10
|
+
}
|
package/dist/index.js
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.One = void 0;
|
4
|
+
const services_1 = require("./services");
|
5
|
+
const base_1 = require("./services/base");
|
6
|
+
class One extends base_1.BaseService {
|
7
|
+
_services;
|
8
|
+
constructor(instanceId, auth, baseUrl) {
|
9
|
+
super(instanceId, auth, baseUrl);
|
10
|
+
this._services ||= (0, services_1.services)(this.instanceId, this.auth, this.baseUrl);
|
11
|
+
}
|
12
|
+
get agent() {
|
13
|
+
return this._services.agent;
|
14
|
+
}
|
15
|
+
get chat() {
|
16
|
+
return this._services.chat;
|
17
|
+
}
|
18
|
+
get datasource() {
|
19
|
+
return this._services.datasource;
|
20
|
+
}
|
21
|
+
get gpt() {
|
22
|
+
return this._services.gpt;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
exports.One = One;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AgentService = void 0;
|
4
|
+
const qs_1 = require("qs");
|
5
|
+
const base_1 = require("./base");
|
6
|
+
class AgentService extends base_1.BaseService {
|
7
|
+
async list(search = '', limit = 20, offset = 0) {
|
8
|
+
const query = (0, qs_1.stringify)({
|
9
|
+
q: search,
|
10
|
+
limit,
|
11
|
+
offset,
|
12
|
+
populate: [{ path: 'steps' }],
|
13
|
+
});
|
14
|
+
const response = await this.sendGet(`/v1/agent?${query}`).then((res) => res.json());
|
15
|
+
return response.data || [];
|
16
|
+
}
|
17
|
+
}
|
18
|
+
exports.AgentService = AgentService;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { OneAuth } from '../customTypes';
|
2
|
+
export declare class BaseService {
|
3
|
+
protected readonly instanceId: string;
|
4
|
+
protected readonly auth: OneAuth;
|
5
|
+
protected readonly baseUrl: string;
|
6
|
+
constructor(instanceId: string, auth: OneAuth, baseUrl: string);
|
7
|
+
private headers;
|
8
|
+
private _request;
|
9
|
+
protected sendPost(path: string, body: object | FormData): Promise<Response>;
|
10
|
+
protected sendPatch(path: string, body: object | FormData): Promise<Response>;
|
11
|
+
protected sendPut(path: string, body: object | FormData): Promise<Response>;
|
12
|
+
protected sendGet(path: string): Promise<Response>;
|
13
|
+
protected sendDelete(path: string): Promise<Response>;
|
14
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.BaseService = void 0;
|
7
|
+
const http_errors_1 = __importDefault(require("http-errors"));
|
8
|
+
class BaseService {
|
9
|
+
instanceId;
|
10
|
+
auth;
|
11
|
+
baseUrl;
|
12
|
+
constructor(instanceId, auth, baseUrl) {
|
13
|
+
this.instanceId = instanceId;
|
14
|
+
this.auth = auth;
|
15
|
+
this.baseUrl = baseUrl;
|
16
|
+
if (!this.instanceId ||
|
17
|
+
(typeof this.auth === 'string' && !this.auth) ||
|
18
|
+
(typeof this.auth === 'object' && (!this.auth.email || !this.auth.apiKey))) {
|
19
|
+
throw new http_errors_1.default.UnprocessableEntity('izz.ONE service is not properly configured');
|
20
|
+
}
|
21
|
+
}
|
22
|
+
headers(extra = {}) {
|
23
|
+
return {
|
24
|
+
...extra,
|
25
|
+
'x-environment-id': this.instanceId,
|
26
|
+
...(typeof this.auth === 'string'
|
27
|
+
? {
|
28
|
+
'izz-access-token': this.auth,
|
29
|
+
}
|
30
|
+
: {
|
31
|
+
Authorization: `Basic ${Buffer.from([this.auth.email, this.auth.apiKey].join(':')).toString('base64')}`,
|
32
|
+
}),
|
33
|
+
};
|
34
|
+
}
|
35
|
+
async _request(path, options = {}) {
|
36
|
+
options.headers ||= this.headers();
|
37
|
+
return await fetch(new URL(path, this.baseUrl), options);
|
38
|
+
}
|
39
|
+
async sendPost(path, body) {
|
40
|
+
return await this._request(path, {
|
41
|
+
method: 'POST',
|
42
|
+
headers: this.headers(body instanceof FormData ? {} : { 'Content-Type': 'application/json' }),
|
43
|
+
body: body instanceof FormData ? body : JSON.stringify(body),
|
44
|
+
});
|
45
|
+
}
|
46
|
+
async sendPatch(path, body) {
|
47
|
+
return await this._request(path, {
|
48
|
+
method: 'PATCH',
|
49
|
+
body: body instanceof FormData ? body : JSON.stringify(body),
|
50
|
+
});
|
51
|
+
}
|
52
|
+
async sendPut(path, body) {
|
53
|
+
return await this._request(path, {
|
54
|
+
method: 'PUT',
|
55
|
+
body: body instanceof FormData ? body : JSON.stringify(body),
|
56
|
+
});
|
57
|
+
}
|
58
|
+
async sendGet(path) {
|
59
|
+
return await this._request(path, {
|
60
|
+
method: 'GET',
|
61
|
+
});
|
62
|
+
}
|
63
|
+
async sendDelete(path) {
|
64
|
+
return await this._request(path, {
|
65
|
+
method: 'DELETE',
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
69
|
+
exports.BaseService = BaseService;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { IChatBody } from '@izzai/one-api/dist/customTypes/chat';
|
2
|
+
import type { Message } from '@izzai/one-api/dist/models/types/ts-types';
|
3
|
+
import type { ChatWithMessages } from '../customTypes';
|
4
|
+
import { BaseService } from './base';
|
5
|
+
export declare class ChatService extends BaseService {
|
6
|
+
chat(msg: string, options?: IChatBody, messageMode?: 'user-message'): Promise<Message>;
|
7
|
+
chat(msg: string, options?: IChatBody, messageMode?: 'ai-message'): Promise<Message>;
|
8
|
+
chat(msg: string, options?: IChatBody, messageMode?: 'all'): Promise<ChatWithMessages>;
|
9
|
+
chatWithFile(msg: string, file: Blob, fileName?: string, options?: IChatBody, messageMode?: 'user-message'): Promise<Message>;
|
10
|
+
chatWithFile(msg: string, file: Blob, fileName?: string, options?: IChatBody, messageMode?: 'ai-message'): Promise<Message>;
|
11
|
+
chatWithFile(msg: string, file: Blob, fileName?: string, options?: IChatBody, messageMode?: 'all'): Promise<ChatWithMessages>;
|
12
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.ChatService = void 0;
|
7
|
+
const http_errors_1 = __importDefault(require("http-errors"));
|
8
|
+
const defaults_1 = __importDefault(require("lodash/defaults"));
|
9
|
+
const qs_1 = require("qs");
|
10
|
+
const base_1 = require("./base");
|
11
|
+
class ChatService extends base_1.BaseService {
|
12
|
+
async chat(msg, options, messageMode = 'user-message') {
|
13
|
+
const response = await this.sendPost('/v1/chat', {
|
14
|
+
msg,
|
15
|
+
...(0, defaults_1.default)(options, {
|
16
|
+
datasources: [],
|
17
|
+
}),
|
18
|
+
}).then((res) => res.json());
|
19
|
+
if (!response.messages?.length) {
|
20
|
+
throw new http_errors_1.default.InternalServerError('No messages found in response');
|
21
|
+
}
|
22
|
+
if (messageMode === 'user-message') {
|
23
|
+
const userMessage = response.messages.find((m) => m.role === 'user');
|
24
|
+
return userMessage;
|
25
|
+
}
|
26
|
+
if (messageMode === 'ai-message') {
|
27
|
+
const aiMessage = response.messages.find((m) => m.role === 'assistant');
|
28
|
+
return aiMessage;
|
29
|
+
}
|
30
|
+
return response;
|
31
|
+
}
|
32
|
+
async chatWithFile(msg, file, fileName, options, messageMode = 'user-message') {
|
33
|
+
const formData = new FormData();
|
34
|
+
formData.append('file', file, fileName);
|
35
|
+
formData.append('msg', msg);
|
36
|
+
const params = new URLSearchParams((0, qs_1.stringify)((0, defaults_1.default)(options, { datasources: [] }), {
|
37
|
+
allowEmptyArrays: true,
|
38
|
+
}));
|
39
|
+
for (const [key, value] of params.entries()) {
|
40
|
+
formData.append(key, value);
|
41
|
+
}
|
42
|
+
const response = await this.sendPost('/v1/chat', formData).then((res) => res.json());
|
43
|
+
if (messageMode === 'user-message') {
|
44
|
+
const userMessage = response.messages.find((m) => m.role === 'user');
|
45
|
+
return userMessage;
|
46
|
+
}
|
47
|
+
if (messageMode === 'ai-message') {
|
48
|
+
const aiMessage = response.messages.find((m) => m.role === 'assistant');
|
49
|
+
return aiMessage;
|
50
|
+
}
|
51
|
+
return response;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.ChatService = ChatService;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DatasourceService = void 0;
|
4
|
+
const qs_1 = require("qs");
|
5
|
+
const base_1 = require("./base");
|
6
|
+
class DatasourceService extends base_1.BaseService {
|
7
|
+
async list(search = '', limit = 20, offset = 0) {
|
8
|
+
const query = (0, qs_1.stringify)({ q: search, limit, offset });
|
9
|
+
const response = await this.sendGet(`/v1/datasource?${query}`).then((res) => res.json());
|
10
|
+
return response.data || [];
|
11
|
+
}
|
12
|
+
}
|
13
|
+
exports.DatasourceService = DatasourceService;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.GptService = void 0;
|
4
|
+
const qs_1 = require("qs");
|
5
|
+
const base_1 = require("./base");
|
6
|
+
class GptService extends base_1.BaseService {
|
7
|
+
async list(search = '', limit = 20, offset = 0) {
|
8
|
+
const query = (0, qs_1.stringify)({
|
9
|
+
q: search,
|
10
|
+
limit,
|
11
|
+
offset,
|
12
|
+
});
|
13
|
+
const response = await this.sendGet(`/v1/gpt?${query}`).then((res) => res.json());
|
14
|
+
return response.data || [];
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.GptService = GptService;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { OneAuth } from '../customTypes';
|
2
|
+
import { AgentService } from './agent';
|
3
|
+
import { ChatService } from './chat';
|
4
|
+
import { DatasourceService } from './datasource';
|
5
|
+
import { GptService } from './gpt';
|
6
|
+
export declare const services: (instanceId: string, auth: OneAuth, baseUrl: string) => {
|
7
|
+
agent: AgentService;
|
8
|
+
chat: ChatService;
|
9
|
+
datasource: DatasourceService;
|
10
|
+
gpt: GptService;
|
11
|
+
};
|
12
|
+
export type Services = ReturnType<typeof services>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.services = void 0;
|
4
|
+
const agent_1 = require("./agent");
|
5
|
+
const chat_1 = require("./chat");
|
6
|
+
const datasource_1 = require("./datasource");
|
7
|
+
const gpt_1 = require("./gpt");
|
8
|
+
const services = (instanceId, auth, baseUrl) => ({
|
9
|
+
agent: new agent_1.AgentService(instanceId, auth, baseUrl),
|
10
|
+
chat: new chat_1.ChatService(instanceId, auth, baseUrl),
|
11
|
+
datasource: new datasource_1.DatasourceService(instanceId, auth, baseUrl),
|
12
|
+
gpt: new gpt_1.GptService(instanceId, auth, baseUrl),
|
13
|
+
});
|
14
|
+
exports.services = services;
|
package/package.json
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
{
|
2
|
+
"name": "@izzai/one-js",
|
3
|
+
"version": "1.0.2",
|
4
|
+
"description": "One package for typescript and node projects.",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"type": "commonjs",
|
8
|
+
"homepage": "https://www.izz.ai/",
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "https://github.com/izzai/account"
|
12
|
+
},
|
13
|
+
"scripts": {
|
14
|
+
"lint": "eslint src",
|
15
|
+
"build": "run-s \"pre:build\" \"create:build\" \"post:build\"",
|
16
|
+
"fix": "run-p \"lint:prettier --write\" \"lint:eslint --fix\" \"typecheck\"",
|
17
|
+
"lint:prettier": "prettier \"**/*.{js,jsx,ts,tsx,css,scss,json,md,yml,html}\"",
|
18
|
+
"lint:eslint": "eslint \"**/*.{ts,tsx}\"",
|
19
|
+
"lint:all": "run-p \"lint:prettier --check\" \"lint:eslint\" \"typecheck\"",
|
20
|
+
"typecheck": "tsc --noEmit --project ./tsconfig.json",
|
21
|
+
"pre:build": "tsx buildScripts/preBuild.ts",
|
22
|
+
"post:build": "tsx buildScripts/postBuild.ts",
|
23
|
+
"create:build": "tsc"
|
24
|
+
},
|
25
|
+
"keywords": [
|
26
|
+
"one",
|
27
|
+
"izz",
|
28
|
+
"izz one",
|
29
|
+
"nexus",
|
30
|
+
"typescript",
|
31
|
+
"node",
|
32
|
+
"front end",
|
33
|
+
"izz.ONE"
|
34
|
+
],
|
35
|
+
"engines": {
|
36
|
+
"node": ">=22"
|
37
|
+
},
|
38
|
+
"author": {
|
39
|
+
"name": "Adarsh Mohan",
|
40
|
+
"email": "adarsh@izz.ai"
|
41
|
+
},
|
42
|
+
"license": "CHECK LICENSE.md",
|
43
|
+
"files": [
|
44
|
+
"dist",
|
45
|
+
"LICENSE.md"
|
46
|
+
],
|
47
|
+
"dependencies": {
|
48
|
+
"http-errors": "^2.0.0",
|
49
|
+
"lodash": "*",
|
50
|
+
"qs": "*"
|
51
|
+
},
|
52
|
+
"devDependencies": {
|
53
|
+
"@eslint/js": "*",
|
54
|
+
"@izzai/gateway": "workspace:*",
|
55
|
+
"@izzai/one-api": "workspace:*",
|
56
|
+
"@izzai/tsconfig": "workspace:*",
|
57
|
+
"@tsconfig/node22": "^22.0.0",
|
58
|
+
"@types/eslint": "*",
|
59
|
+
"@types/http-errors": "^2.0.4",
|
60
|
+
"@types/lodash": "*",
|
61
|
+
"@types/node": "^*",
|
62
|
+
"@types/prettier": "*",
|
63
|
+
"@types/qs": "*",
|
64
|
+
"@typescript-eslint/eslint-plugin": "*",
|
65
|
+
"@typescript-eslint/parser": "*",
|
66
|
+
"eslint": "*",
|
67
|
+
"eslint-config-prettier": "*",
|
68
|
+
"eslint-plugin-import": "*",
|
69
|
+
"eslint-plugin-prettier": "*",
|
70
|
+
"eslint-plugin-simple-import-sort": "*",
|
71
|
+
"eslint-plugin-unused-imports": "*",
|
72
|
+
"npm-run-all": "*",
|
73
|
+
"prettier": "*",
|
74
|
+
"tsconfig": "*",
|
75
|
+
"typescript": "*",
|
76
|
+
"typescript-eslint": "*"
|
77
|
+
}
|
78
|
+
}
|
package/readme.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# One JS
|
2
|
+
|
3
|
+
This is the official Typescript SDK for [One](https://one.izz.ai).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install @izzai/one-api
|
9
|
+
```
|
10
|
+
|
11
|
+
## Initialization
|
12
|
+
|
13
|
+
```typescript
|
14
|
+
import { One } from '@izzai/one-api'
|
15
|
+
|
16
|
+
const one = new One('YOUR_INSTANCE_ID', {
|
17
|
+
email: 'YOUR_EMAIL',
|
18
|
+
apiKey: 'YOUR_API_KEY',
|
19
|
+
})
|
20
|
+
```
|
21
|
+
|
22
|
+
OR
|
23
|
+
|
24
|
+
```typescript
|
25
|
+
import { One } from '@izzai/one-api'
|
26
|
+
|
27
|
+
const one = new One('YOUR_INSTANCE_ID', 'JWT_TOKEN')
|
28
|
+
```
|
29
|
+
|
30
|
+
> If you are using JWT token, make sure to check for the expiration time and refresh it as needed.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Chat
|
35
|
+
|
36
|
+
```typescript
|
37
|
+
const chat = await one.chat.chat('Hi there')
|
38
|
+
```
|
39
|
+
|
40
|
+
### Datasources
|
41
|
+
|
42
|
+
```typescript
|
43
|
+
const datasources = await one.datasource.list()
|
44
|
+
```
|
45
|
+
|
46
|
+
### GPTs
|
47
|
+
|
48
|
+
```typescript
|
49
|
+
const gpts = await one.gpt.list()
|
50
|
+
```
|
51
|
+
|
52
|
+
### Agents
|
53
|
+
|
54
|
+
```typescript
|
55
|
+
const agents = await one.agent.list()
|
56
|
+
```
|