sarvam-agents-client 0.5.0 → 0.5.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/dist/compat/core/agents.d.ts +53 -0
- package/dist/compat/core/agents.js +338 -0
- package/dist/compat/core/data.d.ts +10 -0
- package/dist/compat/core/data.js +275 -0
- package/dist/compat/core/errors.d.ts +37 -0
- package/dist/compat/core/errors.js +155 -0
- package/dist/compat/core/events.d.ts +107 -0
- package/dist/compat/core/events.js +160 -0
- package/dist/compat/core/files.d.ts +65 -0
- package/dist/compat/core/files.js +851 -0
- package/dist/compat/core/history.d.ts +9 -0
- package/dist/compat/core/history.js +112 -0
- package/dist/compat/core/http.d.ts +112 -0
- package/dist/compat/core/http.js +753 -0
- package/dist/compat/core/ids.d.ts +4 -0
- package/dist/compat/core/ids.js +36 -0
- package/dist/compat/core/index.d.ts +14 -0
- package/dist/compat/core/index.js +30 -0
- package/dist/compat/core/models.d.ts +20 -0
- package/dist/compat/core/models.js +75 -0
- package/dist/compat/core/paging.d.ts +14 -0
- package/dist/compat/core/paging.js +124 -0
- package/dist/compat/core/refusals.d.ts +9 -0
- package/dist/compat/core/refusals.js +25 -0
- package/dist/compat/core/sessions.d.ts +65 -0
- package/dist/compat/core/sessions.js +317 -0
- package/dist/compat/core/toolResults.d.ts +43 -0
- package/dist/compat/core/toolResults.js +208 -0
- package/dist/compat/core/turns.d.ts +104 -0
- package/dist/compat/core/turns.js +504 -0
- package/dist/compat/core/warnings.d.ts +6 -0
- package/dist/compat/core/warnings.js +26 -0
- package/dist/compat/index.d.ts +3 -0
- package/dist/compat/index.js +9 -0
- package/dist/compat/openai/client.d.ts +62 -0
- package/dist/compat/openai/client.js +108 -0
- package/dist/compat/openai/errors.d.ts +72 -0
- package/dist/compat/openai/errors.js +150 -0
- package/dist/compat/openai/index.d.ts +14 -0
- package/dist/compat/openai/index.js +42 -0
- package/dist/compat/openai/pages.d.ts +19 -0
- package/dist/compat/openai/pages.js +39 -0
- package/dist/compat/openai/resources/agents.d.ts +36 -0
- package/dist/compat/openai/resources/agents.js +549 -0
- package/dist/compat/openai/resources/events.d.ts +23 -0
- package/dist/compat/openai/resources/events.js +485 -0
- package/dist/compat/openai/resources/sessions.d.ts +33 -0
- package/dist/compat/openai/resources/sessions.js +283 -0
- package/dist/compat/openai/stream.d.ts +40 -0
- package/dist/compat/openai/stream.js +585 -0
- package/dist/compat/openai/types.d.ts +125 -0
- package/dist/compat/openai/types.js +98 -0
- package/dist/compose/agent.d.ts +2 -0
- package/dist/compose/agent.js +27 -0
- package/dist/compose/functionTool.d.ts +2 -0
- package/dist/compose/functionTool.js +46 -0
- package/dist/compose/output.d.ts +2 -0
- package/dist/compose/output.js +15 -7
- package/dist/esm/compat/core/agents.d.ts +53 -0
- package/dist/esm/compat/core/agents.js +334 -0
- package/dist/esm/compat/core/data.d.ts +10 -0
- package/dist/esm/compat/core/data.js +272 -0
- package/dist/esm/compat/core/errors.d.ts +37 -0
- package/dist/esm/compat/core/errors.js +146 -0
- package/dist/esm/compat/core/events.d.ts +107 -0
- package/dist/esm/compat/core/events.js +156 -0
- package/dist/esm/compat/core/files.d.ts +65 -0
- package/dist/esm/compat/core/files.js +829 -0
- package/dist/esm/compat/core/history.d.ts +9 -0
- package/dist/esm/compat/core/history.js +109 -0
- package/dist/esm/compat/core/http.d.ts +112 -0
- package/dist/esm/compat/core/http.js +746 -0
- package/dist/esm/compat/core/ids.d.ts +4 -0
- package/dist/esm/compat/core/ids.js +30 -0
- package/dist/esm/compat/core/index.d.ts +14 -0
- package/dist/esm/compat/core/index.js +14 -0
- package/dist/esm/compat/core/models.d.ts +20 -0
- package/dist/esm/compat/core/models.js +71 -0
- package/dist/esm/compat/core/paging.d.ts +14 -0
- package/dist/esm/compat/core/paging.js +118 -0
- package/dist/esm/compat/core/refusals.d.ts +9 -0
- package/dist/esm/compat/core/refusals.js +21 -0
- package/dist/esm/compat/core/sessions.d.ts +65 -0
- package/dist/esm/compat/core/sessions.js +312 -0
- package/dist/esm/compat/core/toolResults.d.ts +43 -0
- package/dist/esm/compat/core/toolResults.js +203 -0
- package/dist/esm/compat/core/turns.d.ts +104 -0
- package/dist/esm/compat/core/turns.js +497 -0
- package/dist/esm/compat/core/warnings.d.ts +6 -0
- package/dist/esm/compat/core/warnings.js +20 -0
- package/dist/esm/compat/index.d.ts +3 -0
- package/dist/esm/compat/index.js +3 -0
- package/dist/esm/compat/openai/client.d.ts +62 -0
- package/dist/esm/compat/openai/client.js +104 -0
- package/dist/esm/compat/openai/errors.d.ts +72 -0
- package/dist/esm/compat/openai/errors.js +130 -0
- package/dist/esm/compat/openai/index.d.ts +14 -0
- package/dist/esm/compat/openai/index.js +17 -0
- package/dist/esm/compat/openai/pages.d.ts +19 -0
- package/dist/esm/compat/openai/pages.js +35 -0
- package/dist/esm/compat/openai/resources/agents.d.ts +36 -0
- package/dist/esm/compat/openai/resources/agents.js +540 -0
- package/dist/esm/compat/openai/resources/events.d.ts +23 -0
- package/dist/esm/compat/openai/resources/events.js +479 -0
- package/dist/esm/compat/openai/resources/sessions.d.ts +33 -0
- package/dist/esm/compat/openai/resources/sessions.js +278 -0
- package/dist/esm/compat/openai/stream.d.ts +40 -0
- package/dist/esm/compat/openai/stream.js +579 -0
- package/dist/esm/compat/openai/types.d.ts +125 -0
- package/dist/esm/compat/openai/types.js +91 -0
- package/dist/esm/compose/agent.d.ts +2 -0
- package/dist/esm/compose/agent.js +28 -2
- package/dist/esm/compose/functionTool.d.ts +2 -0
- package/dist/esm/compose/functionTool.js +45 -0
- package/dist/esm/compose/output.d.ts +2 -0
- package/dist/esm/compose/output.js +14 -7
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/package.json +53 -11
- package/src/compat/core/agents.ts +437 -0
- package/src/compat/core/data.ts +283 -0
- package/src/compat/core/errors.ts +162 -0
- package/src/compat/core/events.ts +198 -0
- package/src/compat/core/files.ts +913 -0
- package/src/compat/core/history.ts +116 -0
- package/src/compat/core/http.ts +827 -0
- package/src/compat/core/ids.ts +35 -0
- package/src/compat/core/index.ts +14 -0
- package/src/compat/core/models.ts +85 -0
- package/src/compat/core/paging.ts +119 -0
- package/src/compat/core/refusals.ts +31 -0
- package/src/compat/core/sessions.ts +358 -0
- package/src/compat/core/toolResults.ts +235 -0
- package/src/compat/core/turns.ts +622 -0
- package/src/compat/core/warnings.ts +23 -0
- package/src/compat/index.ts +3 -0
- package/src/compat/openai/client.ts +177 -0
- package/src/compat/openai/errors.ts +165 -0
- package/src/compat/openai/index.ts +65 -0
- package/src/compat/openai/pages.ts +55 -0
- package/src/compat/openai/resources/agents.ts +603 -0
- package/src/compat/openai/resources/events.ts +523 -0
- package/src/compat/openai/resources/sessions.ts +369 -0
- package/src/compat/openai/stream.ts +599 -0
- package/src/compat/openai/types.ts +217 -0
- package/src/compose/agent.ts +30 -3
- package/src/compose/functionTool.ts +44 -0
- package/src/compose/output.ts +14 -8
- package/src/index.ts +3 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAI = void 0;
|
|
4
|
+
/** OpenAI drop-in client (client.beta.agents...) backed by compat/core. */
|
|
5
|
+
const agents_js_1 = require("../core/agents.js");
|
|
6
|
+
const errors_js_1 = require("../core/errors.js");
|
|
7
|
+
const files_js_1 = require("../core/files.js");
|
|
8
|
+
const http_js_1 = require("../core/http.js");
|
|
9
|
+
const models_js_1 = require("../core/models.js");
|
|
10
|
+
const sessions_js_1 = require("../core/sessions.js");
|
|
11
|
+
const toolResults_js_1 = require("../core/toolResults.js");
|
|
12
|
+
const turns_js_1 = require("../core/turns.js");
|
|
13
|
+
const errors_js_2 = require("./errors.js");
|
|
14
|
+
const agents_js_2 = require("./resources/agents.js");
|
|
15
|
+
const events_js_1 = require("./resources/events.js");
|
|
16
|
+
const sessions_js_2 = require("./resources/sessions.js");
|
|
17
|
+
function makeRawProxy(target, http) {
|
|
18
|
+
return new Proxy(target, {
|
|
19
|
+
get(obj, prop, receiver) {
|
|
20
|
+
const val = Reflect.get(obj, prop, receiver);
|
|
21
|
+
if (typeof val === "function") {
|
|
22
|
+
return async (...args) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const { data, raw } = await http.captureRawResponse(() => val.apply(obj, args));
|
|
25
|
+
return {
|
|
26
|
+
status: (_a = raw === null || raw === void 0 ? void 0 : raw.status) !== null && _a !== void 0 ? _a : 200,
|
|
27
|
+
headers: (_b = raw === null || raw === void 0 ? void 0 : raw.headers) !== null && _b !== void 0 ? _b : {},
|
|
28
|
+
data,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (val !== null && typeof val === "object") {
|
|
33
|
+
return makeRawProxy(val, http);
|
|
34
|
+
}
|
|
35
|
+
return val;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
class OpenAI {
|
|
40
|
+
constructor(opts = {}) {
|
|
41
|
+
var _a, _b, _c, _d, _e, _f;
|
|
42
|
+
this.initOpts = { ...opts };
|
|
43
|
+
try {
|
|
44
|
+
this.http = new http_js_1.Http({
|
|
45
|
+
apiKey: opts.apiKey,
|
|
46
|
+
baseURL: opts.baseURL,
|
|
47
|
+
timeout: (_a = opts.timeout) !== null && _a !== void 0 ? _a : http_js_1.DEFAULT_TIMEOUT_MS,
|
|
48
|
+
maxRetries: (_b = opts.maxRetries) !== null && _b !== void 0 ? _b : http_js_1.DEFAULT_MAX_RETRIES,
|
|
49
|
+
defaultHeaders: opts.defaultHeaders,
|
|
50
|
+
defaultQuery: opts.defaultQuery,
|
|
51
|
+
provider: "openai",
|
|
52
|
+
fetch: opts.fetch,
|
|
53
|
+
allowPrivateRemoteUrls: opts.allowPrivateRemoteUrls,
|
|
54
|
+
}, {
|
|
55
|
+
...(opts._sleep ? { sleep: opts._sleep } : {}),
|
|
56
|
+
...(opts._resolveHost ? { resolveHost: opts._resolveHost } : {}),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err instanceof errors_js_1.CoreAPIError)
|
|
61
|
+
throw (0, errors_js_2.toOpenAIError)(err);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
const models = new models_js_1.ModelResolver(this.http, {
|
|
65
|
+
modelMap: opts.modelMap,
|
|
66
|
+
strict: opts.strictModels,
|
|
67
|
+
provider: "openai",
|
|
68
|
+
});
|
|
69
|
+
const agentsCore = new agents_js_1.Agents(this.http, models);
|
|
70
|
+
this.sessionUpdateQueue = (_c = opts._sharedSessionQueue) !== null && _c !== void 0 ? _c : new sessions_js_1.SessionUpdateQueue();
|
|
71
|
+
const sessionsCore = new sessions_js_1.Sessions(this.http, { provider: "openai", updateQueue: this.sessionUpdateQueue });
|
|
72
|
+
this.listenerRegistry = (_d = opts._sharedRegistry) !== null && _d !== void 0 ? _d : new turns_js_1.ListenerRegistry();
|
|
73
|
+
this.toolResultStore = (_e = opts._sharedToolStore) !== null && _e !== void 0 ? _e : new toolResults_js_1.ToolResultStore();
|
|
74
|
+
this.uploadCache = (_f = opts._sharedUploadCache) !== null && _f !== void 0 ? _f : new files_js_1.AttachmentUploadCache();
|
|
75
|
+
const turnsCore = new turns_js_1.Turns(this.http, sessionsCore, {
|
|
76
|
+
pollIntervalMs: opts._pollIntervalMs,
|
|
77
|
+
provider: "openai",
|
|
78
|
+
registry: this.listenerRegistry,
|
|
79
|
+
uploadCache: this.uploadCache,
|
|
80
|
+
});
|
|
81
|
+
const toolResultsCore = new toolResults_js_1.ToolResults(this.http, sessionsCore, turnsCore, {
|
|
82
|
+
store: this.toolResultStore,
|
|
83
|
+
});
|
|
84
|
+
const eventsRes = new events_js_1.EventsResource(this.http, sessionsCore, turnsCore, toolResultsCore);
|
|
85
|
+
const itemsRes = new events_js_1.ItemsResource(this.http);
|
|
86
|
+
const sessionsRes = new sessions_js_2.SessionsResource(this.http, agentsCore, sessionsCore, turnsCore, eventsRes, itemsRes);
|
|
87
|
+
const agentsRes = new agents_js_2.AgentsResource(this.http, agentsCore, sessionsRes);
|
|
88
|
+
this.beta = { agents: agentsRes };
|
|
89
|
+
}
|
|
90
|
+
get withRawResponse() {
|
|
91
|
+
return makeRawProxy(this, this.http);
|
|
92
|
+
}
|
|
93
|
+
withOptions(overrides) {
|
|
94
|
+
// Share only listener registry and tool-result buffers so each options view uses its own Http credentials & config.
|
|
95
|
+
return new OpenAI({
|
|
96
|
+
...this.initOpts,
|
|
97
|
+
...overrides,
|
|
98
|
+
_sharedRegistry: this.listenerRegistry,
|
|
99
|
+
_sharedToolStore: this.toolResultStore,
|
|
100
|
+
_sharedSessionQueue: this.sessionUpdateQueue,
|
|
101
|
+
_sharedUploadCache: this.uploadCache,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
// No persistent sockets to tear down in fetch-based client; provided for Python parity.
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.OpenAI = OpenAI;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** OpenAI-shaped error hierarchy backed by compat/core CoreAPIError (spec §6). */
|
|
2
|
+
import { CoreAPIError } from "../core/errors.js";
|
|
3
|
+
export interface ErrorResponseSnapshot {
|
|
4
|
+
status: number;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class OpenAIError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class APIError extends OpenAIError {
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
readonly param?: string;
|
|
15
|
+
readonly type?: string;
|
|
16
|
+
readonly requestID?: string;
|
|
17
|
+
readonly request_id?: string;
|
|
18
|
+
readonly body?: unknown;
|
|
19
|
+
readonly headers: Record<string, string>;
|
|
20
|
+
readonly response?: ErrorResponseSnapshot;
|
|
21
|
+
constructor(message: string, opts?: {
|
|
22
|
+
status?: number;
|
|
23
|
+
code?: string;
|
|
24
|
+
param?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
requestId?: string;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
response?: ErrorResponseSnapshot;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export declare class APIConnectionError extends APIError {
|
|
33
|
+
}
|
|
34
|
+
export declare class APITimeoutError extends APIConnectionError {
|
|
35
|
+
}
|
|
36
|
+
export declare class APIUserAbortError extends APIError {
|
|
37
|
+
}
|
|
38
|
+
export declare class APIStatusError extends APIError {
|
|
39
|
+
}
|
|
40
|
+
export declare class BadRequestError extends APIStatusError {
|
|
41
|
+
}
|
|
42
|
+
export declare class UnsupportedFeatureError extends BadRequestError {
|
|
43
|
+
readonly feature?: string;
|
|
44
|
+
readonly needs?: string;
|
|
45
|
+
constructor(message: string, opts?: {
|
|
46
|
+
status?: number;
|
|
47
|
+
code?: string;
|
|
48
|
+
param?: string;
|
|
49
|
+
type?: string;
|
|
50
|
+
requestId?: string;
|
|
51
|
+
body?: unknown;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
feature?: string;
|
|
54
|
+
needs?: string;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export declare class AuthenticationError extends APIStatusError {
|
|
58
|
+
}
|
|
59
|
+
export declare class PermissionDeniedError extends APIStatusError {
|
|
60
|
+
}
|
|
61
|
+
export declare class NotFoundError extends APIStatusError {
|
|
62
|
+
}
|
|
63
|
+
export declare class ConflictError extends APIStatusError {
|
|
64
|
+
}
|
|
65
|
+
export declare class UnprocessableEntityError extends APIStatusError {
|
|
66
|
+
}
|
|
67
|
+
export declare class RateLimitError extends APIStatusError {
|
|
68
|
+
}
|
|
69
|
+
export declare class InternalServerError extends APIStatusError {
|
|
70
|
+
}
|
|
71
|
+
export declare function toOpenAIError(err: CoreAPIError): APIError;
|
|
72
|
+
export declare function wrapCoreErrors<T>(fn: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.UnsupportedFeatureError = exports.BadRequestError = exports.APIStatusError = exports.APIUserAbortError = exports.APITimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = void 0;
|
|
4
|
+
exports.toOpenAIError = toOpenAIError;
|
|
5
|
+
exports.wrapCoreErrors = wrapCoreErrors;
|
|
6
|
+
/** OpenAI-shaped error hierarchy backed by compat/core CoreAPIError (spec §6). */
|
|
7
|
+
const errors_js_1 = require("../core/errors.js");
|
|
8
|
+
class OpenAIError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = new.target.name;
|
|
12
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.OpenAIError = OpenAIError;
|
|
16
|
+
class APIError extends OpenAIError {
|
|
17
|
+
constructor(message, opts = {}) {
|
|
18
|
+
var _a;
|
|
19
|
+
super(message);
|
|
20
|
+
this.status = opts.status;
|
|
21
|
+
this.code = opts.code;
|
|
22
|
+
this.param = opts.param;
|
|
23
|
+
this.type = opts.type;
|
|
24
|
+
this.requestID = opts.requestId;
|
|
25
|
+
this.request_id = opts.requestId;
|
|
26
|
+
this.body = opts.body;
|
|
27
|
+
this.headers = { ...((_a = opts.headers) !== null && _a !== void 0 ? _a : {}) };
|
|
28
|
+
if (opts.response) {
|
|
29
|
+
this.response = opts.response;
|
|
30
|
+
}
|
|
31
|
+
else if (opts.status !== undefined) {
|
|
32
|
+
const text = typeof opts.body === "string"
|
|
33
|
+
? opts.body
|
|
34
|
+
: opts.body !== undefined && opts.body !== null
|
|
35
|
+
? JSON.stringify(opts.body)
|
|
36
|
+
: "";
|
|
37
|
+
this.response = { status: opts.status, headers: { ...this.headers }, text };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.APIError = APIError;
|
|
42
|
+
class APIConnectionError extends APIError {
|
|
43
|
+
}
|
|
44
|
+
exports.APIConnectionError = APIConnectionError;
|
|
45
|
+
class APITimeoutError extends APIConnectionError {
|
|
46
|
+
}
|
|
47
|
+
exports.APITimeoutError = APITimeoutError;
|
|
48
|
+
class APIUserAbortError extends APIError {
|
|
49
|
+
}
|
|
50
|
+
exports.APIUserAbortError = APIUserAbortError;
|
|
51
|
+
class APIStatusError extends APIError {
|
|
52
|
+
}
|
|
53
|
+
exports.APIStatusError = APIStatusError;
|
|
54
|
+
class BadRequestError extends APIStatusError {
|
|
55
|
+
}
|
|
56
|
+
exports.BadRequestError = BadRequestError;
|
|
57
|
+
class UnsupportedFeatureError extends BadRequestError {
|
|
58
|
+
constructor(message, opts = {}) {
|
|
59
|
+
super(message, {
|
|
60
|
+
status: 400,
|
|
61
|
+
code: "unsupported_by_sarvam",
|
|
62
|
+
type: "invalid_request_error",
|
|
63
|
+
...opts,
|
|
64
|
+
});
|
|
65
|
+
this.feature = opts.feature;
|
|
66
|
+
this.needs = opts.needs;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.UnsupportedFeatureError = UnsupportedFeatureError;
|
|
70
|
+
class AuthenticationError extends APIStatusError {
|
|
71
|
+
}
|
|
72
|
+
exports.AuthenticationError = AuthenticationError;
|
|
73
|
+
class PermissionDeniedError extends APIStatusError {
|
|
74
|
+
}
|
|
75
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
76
|
+
class NotFoundError extends APIStatusError {
|
|
77
|
+
}
|
|
78
|
+
exports.NotFoundError = NotFoundError;
|
|
79
|
+
class ConflictError extends APIStatusError {
|
|
80
|
+
}
|
|
81
|
+
exports.ConflictError = ConflictError;
|
|
82
|
+
class UnprocessableEntityError extends APIStatusError {
|
|
83
|
+
}
|
|
84
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
85
|
+
class RateLimitError extends APIStatusError {
|
|
86
|
+
}
|
|
87
|
+
exports.RateLimitError = RateLimitError;
|
|
88
|
+
class InternalServerError extends APIStatusError {
|
|
89
|
+
}
|
|
90
|
+
exports.InternalServerError = InternalServerError;
|
|
91
|
+
function toOpenAIError(err) {
|
|
92
|
+
var _a, _b, _c, _d, _e, _f;
|
|
93
|
+
const opts = {
|
|
94
|
+
status: (_a = err.status) !== null && _a !== void 0 ? _a : undefined,
|
|
95
|
+
code: (_b = err.code) !== null && _b !== void 0 ? _b : undefined,
|
|
96
|
+
param: (_c = err.param) !== null && _c !== void 0 ? _c : undefined,
|
|
97
|
+
type: err instanceof errors_js_1.Unsupported ? "invalid_request_error" : undefined,
|
|
98
|
+
requestId: (_d = err.requestId) !== null && _d !== void 0 ? _d : undefined,
|
|
99
|
+
body: err.body,
|
|
100
|
+
headers: err.headers,
|
|
101
|
+
};
|
|
102
|
+
if (err instanceof errors_js_1.CoreUserAbortError)
|
|
103
|
+
return new APIUserAbortError(err.message, opts);
|
|
104
|
+
if (err instanceof errors_js_1.CoreTimeoutError)
|
|
105
|
+
return new APITimeoutError(err.message, opts);
|
|
106
|
+
if (err instanceof errors_js_1.CoreConnectionError)
|
|
107
|
+
return new APIConnectionError(err.message, opts);
|
|
108
|
+
if (err instanceof errors_js_1.Unsupported) {
|
|
109
|
+
return new UnsupportedFeatureError(err.message, {
|
|
110
|
+
...opts,
|
|
111
|
+
status: (_e = err.status) !== null && _e !== void 0 ? _e : 400,
|
|
112
|
+
feature: err.feature,
|
|
113
|
+
needs: (_f = err.needs) !== null && _f !== void 0 ? _f : undefined,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (err.status === null) {
|
|
117
|
+
return new APIError(err.message, opts);
|
|
118
|
+
}
|
|
119
|
+
// OpenAI maps Panja 413/422 validation/size errors to 400 BadRequestError per shared errors.json.
|
|
120
|
+
const status = err.status === 413 || err.status === 422 ? 400 : err.status;
|
|
121
|
+
switch (status) {
|
|
122
|
+
case 400:
|
|
123
|
+
return new BadRequestError(err.message, { ...opts, status: 400 });
|
|
124
|
+
case 401:
|
|
125
|
+
return new AuthenticationError(err.message, { ...opts, status: 401 });
|
|
126
|
+
case 403:
|
|
127
|
+
return new PermissionDeniedError(err.message, { ...opts, status: 403 });
|
|
128
|
+
case 404:
|
|
129
|
+
return new NotFoundError(err.message, { ...opts, status: 404 });
|
|
130
|
+
case 409:
|
|
131
|
+
return new ConflictError(err.message, { ...opts, status: 409 });
|
|
132
|
+
case 429:
|
|
133
|
+
return new RateLimitError(err.message, { ...opts, status: 429 });
|
|
134
|
+
default:
|
|
135
|
+
if (status >= 500) {
|
|
136
|
+
return new InternalServerError(err.message, { ...opts, status });
|
|
137
|
+
}
|
|
138
|
+
return new APIStatusError(err.message, { ...opts, status });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function wrapCoreErrors(fn) {
|
|
142
|
+
try {
|
|
143
|
+
return await fn();
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
if (err instanceof errors_js_1.CoreAPIError)
|
|
147
|
+
throw toOpenAIError(err);
|
|
148
|
+
throw err;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** OpenAI Hosted Agents API drop-in compatibility module. */
|
|
2
|
+
export { SarvamCompatWarning } from "../core/warnings.js";
|
|
3
|
+
export { OpenAIError, APIError, APIConnectionError, APITimeoutError, APIUserAbortError, APIStatusError, BadRequestError, UnsupportedFeatureError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./errors.js";
|
|
4
|
+
export { NOT_GIVEN, NotGiven } from "./types.js";
|
|
5
|
+
export type { OmitSentinel as Omit, RequestOptions, RawResponse, Agent, AgentDeleted, AgentSession, AgentSessionDeleted, AgentSessionItem, RequiredAction, Usage, TurnError, AgentSessionEvent, FinalResult, } from "./types.js";
|
|
6
|
+
export { SyncCursorPage } from "./pages.js";
|
|
7
|
+
export { AgentSessionEventStream } from "./stream.js";
|
|
8
|
+
export { OpenAI, type OpenAIOptions, type RawResponseClient, type RawResponseAgentsResource, type RawResponseSessionsResource, type RawResponseProxy, } from "./client.js";
|
|
9
|
+
import { OpenAI, type OpenAIOptions } from "./client.js";
|
|
10
|
+
export interface SarvamAgentsOptions extends OpenAIOptions {
|
|
11
|
+
provider?: "openai";
|
|
12
|
+
}
|
|
13
|
+
export declare function SarvamAgents(opts?: SarvamAgentsOptions): OpenAI;
|
|
14
|
+
export default OpenAI;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAI = exports.AgentSessionEventStream = exports.SyncCursorPage = exports.NotGiven = exports.NOT_GIVEN = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.UnsupportedFeatureError = exports.BadRequestError = exports.APIStatusError = exports.APIUserAbortError = exports.APITimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.SarvamCompatWarning = void 0;
|
|
4
|
+
exports.SarvamAgents = SarvamAgents;
|
|
5
|
+
/** OpenAI Hosted Agents API drop-in compatibility module. */
|
|
6
|
+
var warnings_js_1 = require("../core/warnings.js");
|
|
7
|
+
Object.defineProperty(exports, "SarvamCompatWarning", { enumerable: true, get: function () { return warnings_js_1.SarvamCompatWarning; } });
|
|
8
|
+
var errors_js_1 = require("./errors.js");
|
|
9
|
+
Object.defineProperty(exports, "OpenAIError", { enumerable: true, get: function () { return errors_js_1.OpenAIError; } });
|
|
10
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
|
|
11
|
+
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return errors_js_1.APIConnectionError; } });
|
|
12
|
+
Object.defineProperty(exports, "APITimeoutError", { enumerable: true, get: function () { return errors_js_1.APITimeoutError; } });
|
|
13
|
+
Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return errors_js_1.APIUserAbortError; } });
|
|
14
|
+
Object.defineProperty(exports, "APIStatusError", { enumerable: true, get: function () { return errors_js_1.APIStatusError; } });
|
|
15
|
+
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
|
|
16
|
+
Object.defineProperty(exports, "UnsupportedFeatureError", { enumerable: true, get: function () { return errors_js_1.UnsupportedFeatureError; } });
|
|
17
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
|
|
18
|
+
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return errors_js_1.PermissionDeniedError; } });
|
|
19
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
|
|
20
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
|
|
21
|
+
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return errors_js_1.UnprocessableEntityError; } });
|
|
22
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
|
|
23
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return errors_js_1.InternalServerError; } });
|
|
24
|
+
var types_js_1 = require("./types.js");
|
|
25
|
+
Object.defineProperty(exports, "NOT_GIVEN", { enumerable: true, get: function () { return types_js_1.NOT_GIVEN; } });
|
|
26
|
+
Object.defineProperty(exports, "NotGiven", { enumerable: true, get: function () { return types_js_1.NotGiven; } });
|
|
27
|
+
var pages_js_1 = require("./pages.js");
|
|
28
|
+
Object.defineProperty(exports, "SyncCursorPage", { enumerable: true, get: function () { return pages_js_1.SyncCursorPage; } });
|
|
29
|
+
var stream_js_1 = require("./stream.js");
|
|
30
|
+
Object.defineProperty(exports, "AgentSessionEventStream", { enumerable: true, get: function () { return stream_js_1.AgentSessionEventStream; } });
|
|
31
|
+
var client_js_1 = require("./client.js");
|
|
32
|
+
Object.defineProperty(exports, "OpenAI", { enumerable: true, get: function () { return client_js_1.OpenAI; } });
|
|
33
|
+
const client_js_2 = require("./client.js");
|
|
34
|
+
const errors_js_2 = require("./errors.js");
|
|
35
|
+
function SarvamAgents(opts = {}) {
|
|
36
|
+
const { provider = "openai", ...rest } = opts;
|
|
37
|
+
if (provider === "openai") {
|
|
38
|
+
return new client_js_2.OpenAI(rest);
|
|
39
|
+
}
|
|
40
|
+
throw new errors_js_2.UnsupportedFeatureError(`provider=${JSON.stringify(provider)}: not supported by Sarvam (only provider='openai' is available in this release).`, { param: "provider", feature: "compat.provider" });
|
|
41
|
+
}
|
|
42
|
+
exports.default = client_js_2.OpenAI;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** OpenAI SyncCursorPage<T> with auto-pagination via AsyncIterable (spec §2.3). */
|
|
2
|
+
export interface CursorPageData<T> {
|
|
3
|
+
data: T[];
|
|
4
|
+
hasMore: boolean;
|
|
5
|
+
firstId: string | null;
|
|
6
|
+
lastId: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare class SyncCursorPage<T> implements AsyncIterable<T> {
|
|
9
|
+
readonly data: T[];
|
|
10
|
+
readonly has_more: boolean;
|
|
11
|
+
readonly first_id: string | null;
|
|
12
|
+
readonly last_id: string | null;
|
|
13
|
+
private readonly fetchNext?;
|
|
14
|
+
constructor(page: CursorPageData<T>, fetchNext?: (after: string) => Promise<SyncCursorPage<T>>);
|
|
15
|
+
hasNextPage(): boolean;
|
|
16
|
+
getNextPage(): Promise<SyncCursorPage<T>>;
|
|
17
|
+
iterPages(): AsyncGenerator<SyncCursorPage<T>, void, unknown>;
|
|
18
|
+
[Symbol.asyncIterator](): AsyncGenerator<T, void, unknown>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** OpenAI SyncCursorPage<T> with auto-pagination via AsyncIterable (spec §2.3). */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SyncCursorPage = void 0;
|
|
5
|
+
class SyncCursorPage {
|
|
6
|
+
constructor(page, fetchNext) {
|
|
7
|
+
this.data = page.data;
|
|
8
|
+
this.has_more = page.hasMore;
|
|
9
|
+
this.first_id = page.firstId;
|
|
10
|
+
this.last_id = page.lastId;
|
|
11
|
+
this.fetchNext = fetchNext;
|
|
12
|
+
}
|
|
13
|
+
hasNextPage() {
|
|
14
|
+
return this.has_more && this.last_id !== null && this.fetchNext !== undefined;
|
|
15
|
+
}
|
|
16
|
+
async getNextPage() {
|
|
17
|
+
if (!this.hasNextPage() || !this.fetchNext || this.last_id === null) {
|
|
18
|
+
return new SyncCursorPage({ data: [], hasMore: false, firstId: null, lastId: null });
|
|
19
|
+
}
|
|
20
|
+
return this.fetchNext(this.last_id);
|
|
21
|
+
}
|
|
22
|
+
async *iterPages() {
|
|
23
|
+
let page = this;
|
|
24
|
+
while (true) {
|
|
25
|
+
yield page;
|
|
26
|
+
if (!page.hasNextPage())
|
|
27
|
+
break;
|
|
28
|
+
page = await page.getNextPage();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async *[Symbol.asyncIterator]() {
|
|
32
|
+
for await (const page of this.iterPages()) {
|
|
33
|
+
for (const item of page.data) {
|
|
34
|
+
yield item;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.SyncCursorPage = SyncCursorPage;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Agents, type AgentRecord, type AgentSpec } from "../../core/agents.js";
|
|
2
|
+
import { Http } from "../../core/http.js";
|
|
3
|
+
import { SyncCursorPage } from "../pages.js";
|
|
4
|
+
import { NOT_GIVEN, type Agent, type AgentDeleted, type RequestOptions } from "../types.js";
|
|
5
|
+
import type { SessionsResource } from "./sessions.js";
|
|
6
|
+
export declare function makePathOfComposeField(fnToolIndices?: number[]): (composeField: string) => string;
|
|
7
|
+
export declare function pathOfComposeField(composeField: string): string;
|
|
8
|
+
export declare function openaiToSpec(params: Record<string, unknown>, sandboxOn?: boolean | null, extraSarvam?: Record<string, unknown>): AgentSpec;
|
|
9
|
+
export declare function recordToAgent(rec: AgentRecord): Agent;
|
|
10
|
+
export declare class RefusedResource {
|
|
11
|
+
private readonly resourcePath;
|
|
12
|
+
constructor(resourcePath: string);
|
|
13
|
+
create(_params?: Record<string, unknown>): Promise<never>;
|
|
14
|
+
retrieve(_id?: string, _params?: Record<string, unknown>): Promise<never>;
|
|
15
|
+
update(_id?: string, _params?: Record<string, unknown>): Promise<never>;
|
|
16
|
+
list(_params?: Record<string, unknown>): Promise<never>;
|
|
17
|
+
delete(_id?: string, _params?: Record<string, unknown>): Promise<never>;
|
|
18
|
+
private err;
|
|
19
|
+
}
|
|
20
|
+
export declare class AgentsResource {
|
|
21
|
+
private readonly http;
|
|
22
|
+
private readonly core;
|
|
23
|
+
readonly sessions: SessionsResource;
|
|
24
|
+
readonly environments: RefusedResource;
|
|
25
|
+
readonly templates: RefusedResource;
|
|
26
|
+
readonly files: RefusedResource;
|
|
27
|
+
readonly vaults: RefusedResource;
|
|
28
|
+
readonly credentials: RefusedResource;
|
|
29
|
+
constructor(http: Http, core: Agents, sessions: SessionsResource);
|
|
30
|
+
create(params?: Record<string, unknown>, options?: RequestOptions): Promise<Agent>;
|
|
31
|
+
retrieve(agentId: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<Agent>;
|
|
32
|
+
update(agentId: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<Agent>;
|
|
33
|
+
list(params?: Record<string, unknown>, options?: RequestOptions): Promise<SyncCursorPage<Agent>>;
|
|
34
|
+
delete(agentId: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<AgentDeleted>;
|
|
35
|
+
}
|
|
36
|
+
export { NOT_GIVEN };
|