@or-sdk/agents 1.12.0-beta.2532.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/CHANGELOG.md +0 -0
- package/README.md +137 -0
- package/dist/cjs/Agents.js +175 -0
- package/dist/cjs/Agents.js.map +1 -0
- package/dist/cjs/constants.js +5 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/error-parser/OrNetworkError.js +37 -0
- package/dist/cjs/error-parser/OrNetworkError.js.map +1 -0
- package/dist/cjs/error-parser/index.js +34 -0
- package/dist/cjs/error-parser/index.js.map +1 -0
- package/dist/cjs/error-parser/parse-axios-error.js +31 -0
- package/dist/cjs/error-parser/parse-axios-error.js.map +1 -0
- package/dist/cjs/error-parser/processors.js +22 -0
- package/dist/cjs/error-parser/processors.js.map +1 -0
- package/dist/cjs/error-parser/types.js +3 -0
- package/dist/cjs/error-parser/types.js.map +1 -0
- package/dist/cjs/guards.js +9 -0
- package/dist/cjs/guards.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/Agents.js +71 -0
- package/dist/esm/Agents.js.map +1 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/error-parser/OrNetworkError.js +10 -0
- package/dist/esm/error-parser/OrNetworkError.js.map +1 -0
- package/dist/esm/error-parser/index.js +12 -0
- package/dist/esm/error-parser/index.js.map +1 -0
- package/dist/esm/error-parser/parse-axios-error.js +27 -0
- package/dist/esm/error-parser/parse-axios-error.js.map +1 -0
- package/dist/esm/error-parser/processors.js +16 -0
- package/dist/esm/error-parser/processors.js.map +1 -0
- package/dist/esm/error-parser/types.js +2 -0
- package/dist/esm/error-parser/types.js.map +1 -0
- package/dist/esm/guards.js +5 -0
- package/dist/esm/guards.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/Agents.d.ts +14 -0
- package/dist/types/Agents.d.ts.map +1 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/error-parser/OrNetworkError.d.ts +12 -0
- package/dist/types/error-parser/OrNetworkError.d.ts.map +1 -0
- package/dist/types/error-parser/index.d.ts +5 -0
- package/dist/types/error-parser/index.d.ts.map +1 -0
- package/dist/types/error-parser/parse-axios-error.d.ts +3 -0
- package/dist/types/error-parser/parse-axios-error.d.ts.map +1 -0
- package/dist/types/error-parser/processors.d.ts +7 -0
- package/dist/types/error-parser/processors.d.ts.map +1 -0
- package/dist/types/error-parser/types.d.ts +6 -0
- package/dist/types/error-parser/types.d.ts.map +1 -0
- package/dist/types/guards.d.ts +3 -0
- package/dist/types/guards.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +55 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +38 -0
- package/src/Agents.ts +125 -0
- package/src/constants.ts +1 -0
- package/src/error-parser/OrNetworkError.ts +17 -0
- package/src/error-parser/index.ts +16 -0
- package/src/error-parser/parse-axios-error.ts +33 -0
- package/src/error-parser/processors.ts +21 -0
- package/src/error-parser/types.ts +6 -0
- package/src/guards.ts +5 -0
- package/src/index.ts +4 -0
- package/src/types.ts +205 -0
- package/tsconfig.dev.json +8 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +7 -0
- package/tsconfig.types.json +10 -0
- package/vitest.config.js +24 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OrNetworkError } from './OrNetworkError';
|
|
2
|
+
const MESSAGES = {
|
|
3
|
+
401: 'We are not able to authenticate you',
|
|
4
|
+
500: 'Internal server error',
|
|
5
|
+
};
|
|
6
|
+
export function parseAxiosError(e) {
|
|
7
|
+
if (e.response) {
|
|
8
|
+
const data = e.response.data;
|
|
9
|
+
const status = e.response.status;
|
|
10
|
+
const generalMessage = MESSAGES[status] || e.message;
|
|
11
|
+
const message = normalizeMessage(data.message || data.error) || generalMessage;
|
|
12
|
+
return new OrNetworkError({
|
|
13
|
+
message,
|
|
14
|
+
status,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return new Error(e.message);
|
|
18
|
+
}
|
|
19
|
+
function normalizeMessage(message) {
|
|
20
|
+
if (typeof message === 'string') {
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(message)) {
|
|
24
|
+
return message.join('. ');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=parse-axios-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-axios-error.js","sourceRoot":"","sources":["../../../src/error-parser/parse-axios-error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,QAAQ,GAA2B;IACvC,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,uBAAuB;CAC7B,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,CAAa;IAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE;QACd,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,IAA+B,CAAC;QACxD,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACjC,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;QACrD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC;QAE/E,OAAO,IAAI,cAAc,CAAC;YACxB,OAAO;YACP,MAAM;SACP,CAAC,CAAC;KACJ;IAED,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAgB;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,OAAO,CAAC;KAChB;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC3B;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parseAxiosError as deprecatedParseAxiosError } from '@or-sdk/base';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { parseAxiosError } from './parse-axios-error';
|
|
4
|
+
const DEPRECATED_AXIOS = {
|
|
5
|
+
guard: axios.isAxiosError,
|
|
6
|
+
convertError: deprecatedParseAxiosError,
|
|
7
|
+
};
|
|
8
|
+
const AXIOS = {
|
|
9
|
+
guard: axios.isAxiosError,
|
|
10
|
+
convertError: parseAxiosError,
|
|
11
|
+
};
|
|
12
|
+
export const processors = {
|
|
13
|
+
AXIOS,
|
|
14
|
+
DEPRECATED_AXIOS,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=processors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processors.js","sourceRoot":"","sources":["../../../src/error-parser/processors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,MAAM,gBAAgB,GAA+B;IACnD,KAAK,EAAE,KAAK,CAAC,YAAY;IACzB,YAAY,EAAE,yBAAoD;CACnE,CAAC;AAEF,MAAM,KAAK,GAA+B;IACxC,KAAK,EAAE,KAAK,CAAC,YAAY;IACzB,YAAY,EAAE,eAAe;CAC9B,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK;IACL,gBAAgB;CACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/error-parser/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,OAAO,GAAG,YAAY,cAAc,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Base, List } from '@or-sdk/base';
|
|
2
|
+
import { Agent, CreateAgent, UpdateAgent, FindAgentsOptions, CallOptions, AgentsConfig } from './types';
|
|
3
|
+
export declare class Agents extends Base {
|
|
4
|
+
private readonly _feature;
|
|
5
|
+
constructor(params: AgentsConfig);
|
|
6
|
+
private makeRequest;
|
|
7
|
+
parseError(err: unknown): Error;
|
|
8
|
+
createAgent(params: CreateAgent, options?: CallOptions): Promise<Agent>;
|
|
9
|
+
findAgents(params?: FindAgentsOptions, options?: CallOptions): Promise<List<Agent>>;
|
|
10
|
+
getAgent(agentId: string, options?: CallOptions): Promise<Agent>;
|
|
11
|
+
updateAgent(agentId: string, params: UpdateAgent, options?: CallOptions): Promise<Agent>;
|
|
12
|
+
deleteAgent(agentId: string, options?: CallOptions): Promise<Agent>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Agents.d.ts","sourceRoot":"","sources":["../../src/Agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,IAAI,EAAY,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKxG,qBAAa,MAAO,SAAQ,IAAI;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAE7B,MAAM,EAAE,YAAY;YAgBlB,WAAW;IAUzB,UAAU,CAAC,GAAG,EAAE,OAAO;IAUjB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,KAAK,CAAC;IAiB3E,UAAU,CAAC,MAAM,GAAE,iBAAsB,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAiB3F,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,KAAK,CAAC;IAiBpE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,KAAK,CAAC;IAiB5F,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,KAAK,CAAC;CAS9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type CtorOptions = {
|
|
2
|
+
message: string;
|
|
3
|
+
status?: number;
|
|
4
|
+
};
|
|
5
|
+
export declare class OrNetworkError extends Error {
|
|
6
|
+
private _status;
|
|
7
|
+
private _description;
|
|
8
|
+
constructor({ message, status }: CtorOptions);
|
|
9
|
+
get status(): number | undefined;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=OrNetworkError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrNetworkError.d.ts","sourceRoot":"","sources":["../../../src/error-parser/OrNetworkError.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,YAAY,CAAqB;gBAC7B,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW;IAK5C,IAAI,MAAM,uBAET;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error-parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAE7B,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,WACnC,OAAO,WAS1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-axios-error.d.ts","sourceRoot":"","sources":["../../../src/error-parser/parse-axios-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AASxC,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,GAAG,KAAK,CAcpD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AxiosError } from 'axios';
|
|
2
|
+
import type { ErrorProcessor } from './types';
|
|
3
|
+
export declare const processors: {
|
|
4
|
+
AXIOS: ErrorProcessor<AxiosError<unknown, any>>;
|
|
5
|
+
DEPRECATED_AXIOS: ErrorProcessor<AxiosError<unknown, any>>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=processors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processors.d.ts","sourceRoot":"","sources":["../../../src/error-parser/processors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,SAAS,CAAC;AAY3D,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/error-parser/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC;AAEjD,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;IACtC,YAAY,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAEpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { OrderDirection, Token } from '@or-sdk/base';
|
|
2
|
+
import type { SearchMode } from '@or-sdk/lookup';
|
|
3
|
+
export type CallOptions = {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
};
|
|
6
|
+
export type AgentsConfig = {
|
|
7
|
+
token: Token;
|
|
8
|
+
discoveryUrl?: string;
|
|
9
|
+
accountId?: string;
|
|
10
|
+
serviceUrl?: string;
|
|
11
|
+
feature?: string;
|
|
12
|
+
};
|
|
13
|
+
export type AgentModelOptions = {
|
|
14
|
+
temperature?: number;
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
frequencyPenalty?: number;
|
|
17
|
+
presencePenalty?: number;
|
|
18
|
+
modelName?: string;
|
|
19
|
+
};
|
|
20
|
+
export type CreateAgent = {
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
typeDefs?: string;
|
|
24
|
+
objective?: string;
|
|
25
|
+
image?: string;
|
|
26
|
+
model?: AgentModelOptions;
|
|
27
|
+
};
|
|
28
|
+
export type UpdateAgent = {
|
|
29
|
+
description?: string;
|
|
30
|
+
image?: string;
|
|
31
|
+
typeDefs?: string;
|
|
32
|
+
objective?: string;
|
|
33
|
+
model?: AgentModelOptions;
|
|
34
|
+
};
|
|
35
|
+
export type Agent = {
|
|
36
|
+
id: string;
|
|
37
|
+
accountId: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
image?: string;
|
|
41
|
+
typeDefs?: string;
|
|
42
|
+
objective?: string;
|
|
43
|
+
model?: AgentModelOptions;
|
|
44
|
+
createdAt: string | Date;
|
|
45
|
+
updatedAt: string | Date;
|
|
46
|
+
};
|
|
47
|
+
export type FindAgentsOptions = {
|
|
48
|
+
from?: number;
|
|
49
|
+
size?: number;
|
|
50
|
+
query?: string;
|
|
51
|
+
mode?: SearchMode;
|
|
52
|
+
orderProperty?: string;
|
|
53
|
+
orderDirection?: OrderDirection;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAIzB,KAAK,EAAE,KAAK,CAAC;IAKb,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,UAAU,CAAC,EAAE,MAAM,CAAC;IAKpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAI9B,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAK1B,eAAe,CAAC,EAAE,MAAM,CAAC;IAKzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAKxB,IAAI,EAAE,MAAM,CAAC;IAKb,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAIxB,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAIlB,EAAE,EAAE,MAAM,CAAC;IAKX,SAAS,EAAE,MAAM,CAAC;IAMlB,IAAI,EAAE,MAAM,CAAC;IAKb,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAK1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAKzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAI9B,IAAI,CAAC,EAAE,MAAM,CAAC;IAKd,IAAI,CAAC,EAAE,MAAM,CAAC;IAKd,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,IAAI,CAAC,EAAE,UAAU,CAAC;IAKlB,aAAa,CAAC,EAAE,MAAM,CAAC;IAKvB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@or-sdk/agents",
|
|
3
|
+
"version": "1.12.0-beta.2532.0",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
|
|
9
|
+
"build:cjs": "tsc --project tsconfig.json",
|
|
10
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
11
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
12
|
+
"build:watch": "concurrently -r --hide 1,2 \"pnpm build:watch:cjs\" \"pnpm build:watch:esm\" \"pnpm build:watch:types\"",
|
|
13
|
+
"build:watch:cjs": "tsc --project tsconfig.json -w",
|
|
14
|
+
"build:watch:esm": "tsc --project tsconfig.esm.json -w",
|
|
15
|
+
"build:watch:types": "tsc --project tsconfig.types.json -w",
|
|
16
|
+
"coverage": "vitest run --coverage",
|
|
17
|
+
"clean": "rm -rf ./dist",
|
|
18
|
+
"dev": "pnpm build:watch:esm",
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"test:watch": "vitest --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@or-sdk/base": "^0.34.1",
|
|
24
|
+
"lodash": "^4.17.21"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@or-sdk/lookup": "^1.0.0",
|
|
28
|
+
"@types/lodash": "^4.14.176",
|
|
29
|
+
"@vitest/coverage-c8": "^0.31.1",
|
|
30
|
+
"concurrently": "^6.4.0",
|
|
31
|
+
"msw": "^1.2.1",
|
|
32
|
+
"typescript": "^4.4.4",
|
|
33
|
+
"vitest": "^0.31.1"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Agents.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Base, CalApiParams, List, makeList } from '@or-sdk/base';
|
|
2
|
+
import { SERVICE_KEY } from './constants';
|
|
3
|
+
import { Agent, CreateAgent, UpdateAgent, FindAgentsOptions, CallOptions, AgentsConfig } from './types';
|
|
4
|
+
import { createErrorParser, processors } from './error-parser';
|
|
5
|
+
|
|
6
|
+
const errorParser = createErrorParser(processors.AXIOS);
|
|
7
|
+
|
|
8
|
+
export class Agents extends Base {
|
|
9
|
+
private readonly _feature: string | null;
|
|
10
|
+
|
|
11
|
+
constructor(params: AgentsConfig) {
|
|
12
|
+
const { token, discoveryUrl, accountId, serviceUrl, feature = 'master' } = params;
|
|
13
|
+
|
|
14
|
+
super({
|
|
15
|
+
token,
|
|
16
|
+
discoveryUrl,
|
|
17
|
+
serviceKey: SERVICE_KEY,
|
|
18
|
+
accountId,
|
|
19
|
+
serviceUrl,
|
|
20
|
+
feature,
|
|
21
|
+
useDefaultSerializer: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
this._feature = feature;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async makeRequest<T>(params: CalApiParams): Promise<T> {
|
|
28
|
+
if (this._feature && this._feature !== 'master') {
|
|
29
|
+
params.params ||= {};
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
(params.params as any).feature = this._feature;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return this.callApiV2<T>(params);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
parseError(err: unknown) {
|
|
38
|
+
return errorParser(err);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a new agent.
|
|
43
|
+
* @param params - The agent creation parameters.
|
|
44
|
+
* @param options - The API call options.
|
|
45
|
+
* @returns The created agent.
|
|
46
|
+
*/
|
|
47
|
+
async createAgent(params: CreateAgent, options: CallOptions = {}): Promise<Agent> {
|
|
48
|
+
const response = await this.makeRequest<Agent>({
|
|
49
|
+
method: 'POST',
|
|
50
|
+
route: 'agents',
|
|
51
|
+
data: params,
|
|
52
|
+
...options,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Find agents with optional pagination and query.
|
|
60
|
+
* @param params - Optional find parameters.
|
|
61
|
+
* @param options - The API call options.
|
|
62
|
+
* @returns An array of agents.
|
|
63
|
+
*/
|
|
64
|
+
async findAgents(params: FindAgentsOptions = {}, options: CallOptions = {}): Promise<List<Agent>> {
|
|
65
|
+
const response = await this.makeRequest<Agent[]>({
|
|
66
|
+
method: 'GET',
|
|
67
|
+
route: 'agents',
|
|
68
|
+
params,
|
|
69
|
+
...options,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return makeList(response);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get an agent by its ID.
|
|
77
|
+
* @param agentId - The ID of the agent to retrieve.
|
|
78
|
+
* @param options - The API call options.
|
|
79
|
+
* @returns The retrieved agent.
|
|
80
|
+
*/
|
|
81
|
+
async getAgent(agentId: string, options: CallOptions = {}): Promise<Agent> {
|
|
82
|
+
const response = await this.makeRequest<Agent>({
|
|
83
|
+
method: 'GET',
|
|
84
|
+
route: `agents/${agentId}`,
|
|
85
|
+
...options,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return response;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Update an agent by its ID.
|
|
93
|
+
* @param agentId - The ID of the agent to update.
|
|
94
|
+
* @param params - The update agent parameters.
|
|
95
|
+
* @param options - The API call options.
|
|
96
|
+
* @returns The updated agent.
|
|
97
|
+
*/
|
|
98
|
+
async updateAgent(agentId: string, params: UpdateAgent, options: CallOptions = {}): Promise<Agent> {
|
|
99
|
+
const response = await this.makeRequest<Agent>({
|
|
100
|
+
method: 'PUT',
|
|
101
|
+
route: `agents/${agentId}`,
|
|
102
|
+
data: params,
|
|
103
|
+
...options,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return response;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Delete an agent by its ID.
|
|
111
|
+
* @param agentId - The ID of the agent to delete.
|
|
112
|
+
* @param options - The API call options.
|
|
113
|
+
* @returns The deleted agent.
|
|
114
|
+
*/
|
|
115
|
+
async deleteAgent(agentId: string, options: CallOptions = {}): Promise<Agent> {
|
|
116
|
+
const response = await this.makeRequest<Agent>({
|
|
117
|
+
method: 'DELETE',
|
|
118
|
+
route: `agents/${agentId}`,
|
|
119
|
+
...options,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return response;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SERVICE_KEY = 'agents-api';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type CtorOptions = {
|
|
2
|
+
message: string;
|
|
3
|
+
status?: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export class OrNetworkError extends Error {
|
|
7
|
+
private _status: number | undefined;
|
|
8
|
+
private _description: string | undefined;
|
|
9
|
+
constructor({ message, status }: CtorOptions) {
|
|
10
|
+
super(message);
|
|
11
|
+
this._status = status;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get status() {
|
|
15
|
+
return this._status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ErrorProcessor } from './types';
|
|
2
|
+
|
|
3
|
+
export * from './OrNetworkError';
|
|
4
|
+
export * from './processors';
|
|
5
|
+
|
|
6
|
+
export function createErrorParser<E>(...processors: ErrorProcessor<E>[]) {
|
|
7
|
+
return function parseError(error: unknown) {
|
|
8
|
+
const processor = processors.find((p) => p.guard(error));
|
|
9
|
+
|
|
10
|
+
if (processor) {
|
|
11
|
+
return processor.convertError(error as E);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return new Error('Unknown Error');
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AxiosError } from 'axios';
|
|
2
|
+
|
|
3
|
+
import { OrNetworkError } from './OrNetworkError';
|
|
4
|
+
|
|
5
|
+
const MESSAGES: Record<number, string> = {
|
|
6
|
+
401: 'We are not able to authenticate you',
|
|
7
|
+
500: 'Internal server error',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function parseAxiosError(e: AxiosError): Error {
|
|
11
|
+
if (e.response) {
|
|
12
|
+
const data = e.response.data as Record<string, unknown>;
|
|
13
|
+
const status = e.response.status;
|
|
14
|
+
const generalMessage = MESSAGES[status] || e.message;
|
|
15
|
+
const message = normalizeMessage(data.message || data.error) || generalMessage;
|
|
16
|
+
|
|
17
|
+
return new OrNetworkError({
|
|
18
|
+
message,
|
|
19
|
+
status,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return new Error(e.message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeMessage(message: unknown): string | undefined {
|
|
27
|
+
if (typeof message === 'string') {
|
|
28
|
+
return message;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(message)) {
|
|
31
|
+
return message.join('. ');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parseAxiosError as deprecatedParseAxiosError } from '@or-sdk/base';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import type { AxiosError } from 'axios';
|
|
4
|
+
|
|
5
|
+
import { parseAxiosError } from './parse-axios-error';
|
|
6
|
+
import type { ErrorParser, ErrorProcessor } from './types';
|
|
7
|
+
|
|
8
|
+
const DEPRECATED_AXIOS: ErrorProcessor<AxiosError> = {
|
|
9
|
+
guard: axios.isAxiosError,
|
|
10
|
+
convertError: deprecatedParseAxiosError as ErrorParser<AxiosError>,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const AXIOS: ErrorProcessor<AxiosError> = {
|
|
14
|
+
guard: axios.isAxiosError,
|
|
15
|
+
convertError: parseAxiosError,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const processors = {
|
|
19
|
+
AXIOS,
|
|
20
|
+
DEPRECATED_AXIOS,
|
|
21
|
+
};
|
package/src/guards.ts
ADDED
package/src/index.ts
ADDED