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.
Files changed (151) hide show
  1. package/dist/compat/core/agents.d.ts +53 -0
  2. package/dist/compat/core/agents.js +338 -0
  3. package/dist/compat/core/data.d.ts +10 -0
  4. package/dist/compat/core/data.js +275 -0
  5. package/dist/compat/core/errors.d.ts +37 -0
  6. package/dist/compat/core/errors.js +155 -0
  7. package/dist/compat/core/events.d.ts +107 -0
  8. package/dist/compat/core/events.js +160 -0
  9. package/dist/compat/core/files.d.ts +65 -0
  10. package/dist/compat/core/files.js +851 -0
  11. package/dist/compat/core/history.d.ts +9 -0
  12. package/dist/compat/core/history.js +112 -0
  13. package/dist/compat/core/http.d.ts +112 -0
  14. package/dist/compat/core/http.js +753 -0
  15. package/dist/compat/core/ids.d.ts +4 -0
  16. package/dist/compat/core/ids.js +36 -0
  17. package/dist/compat/core/index.d.ts +14 -0
  18. package/dist/compat/core/index.js +30 -0
  19. package/dist/compat/core/models.d.ts +20 -0
  20. package/dist/compat/core/models.js +75 -0
  21. package/dist/compat/core/paging.d.ts +14 -0
  22. package/dist/compat/core/paging.js +124 -0
  23. package/dist/compat/core/refusals.d.ts +9 -0
  24. package/dist/compat/core/refusals.js +25 -0
  25. package/dist/compat/core/sessions.d.ts +65 -0
  26. package/dist/compat/core/sessions.js +317 -0
  27. package/dist/compat/core/toolResults.d.ts +43 -0
  28. package/dist/compat/core/toolResults.js +208 -0
  29. package/dist/compat/core/turns.d.ts +104 -0
  30. package/dist/compat/core/turns.js +504 -0
  31. package/dist/compat/core/warnings.d.ts +6 -0
  32. package/dist/compat/core/warnings.js +26 -0
  33. package/dist/compat/index.d.ts +3 -0
  34. package/dist/compat/index.js +9 -0
  35. package/dist/compat/openai/client.d.ts +62 -0
  36. package/dist/compat/openai/client.js +108 -0
  37. package/dist/compat/openai/errors.d.ts +72 -0
  38. package/dist/compat/openai/errors.js +150 -0
  39. package/dist/compat/openai/index.d.ts +14 -0
  40. package/dist/compat/openai/index.js +42 -0
  41. package/dist/compat/openai/pages.d.ts +19 -0
  42. package/dist/compat/openai/pages.js +39 -0
  43. package/dist/compat/openai/resources/agents.d.ts +36 -0
  44. package/dist/compat/openai/resources/agents.js +549 -0
  45. package/dist/compat/openai/resources/events.d.ts +23 -0
  46. package/dist/compat/openai/resources/events.js +485 -0
  47. package/dist/compat/openai/resources/sessions.d.ts +33 -0
  48. package/dist/compat/openai/resources/sessions.js +283 -0
  49. package/dist/compat/openai/stream.d.ts +40 -0
  50. package/dist/compat/openai/stream.js +585 -0
  51. package/dist/compat/openai/types.d.ts +125 -0
  52. package/dist/compat/openai/types.js +98 -0
  53. package/dist/compose/agent.d.ts +2 -0
  54. package/dist/compose/agent.js +27 -0
  55. package/dist/compose/functionTool.d.ts +2 -0
  56. package/dist/compose/functionTool.js +46 -0
  57. package/dist/compose/output.d.ts +2 -0
  58. package/dist/compose/output.js +15 -7
  59. package/dist/esm/compat/core/agents.d.ts +53 -0
  60. package/dist/esm/compat/core/agents.js +334 -0
  61. package/dist/esm/compat/core/data.d.ts +10 -0
  62. package/dist/esm/compat/core/data.js +272 -0
  63. package/dist/esm/compat/core/errors.d.ts +37 -0
  64. package/dist/esm/compat/core/errors.js +146 -0
  65. package/dist/esm/compat/core/events.d.ts +107 -0
  66. package/dist/esm/compat/core/events.js +156 -0
  67. package/dist/esm/compat/core/files.d.ts +65 -0
  68. package/dist/esm/compat/core/files.js +829 -0
  69. package/dist/esm/compat/core/history.d.ts +9 -0
  70. package/dist/esm/compat/core/history.js +109 -0
  71. package/dist/esm/compat/core/http.d.ts +112 -0
  72. package/dist/esm/compat/core/http.js +746 -0
  73. package/dist/esm/compat/core/ids.d.ts +4 -0
  74. package/dist/esm/compat/core/ids.js +30 -0
  75. package/dist/esm/compat/core/index.d.ts +14 -0
  76. package/dist/esm/compat/core/index.js +14 -0
  77. package/dist/esm/compat/core/models.d.ts +20 -0
  78. package/dist/esm/compat/core/models.js +71 -0
  79. package/dist/esm/compat/core/paging.d.ts +14 -0
  80. package/dist/esm/compat/core/paging.js +118 -0
  81. package/dist/esm/compat/core/refusals.d.ts +9 -0
  82. package/dist/esm/compat/core/refusals.js +21 -0
  83. package/dist/esm/compat/core/sessions.d.ts +65 -0
  84. package/dist/esm/compat/core/sessions.js +312 -0
  85. package/dist/esm/compat/core/toolResults.d.ts +43 -0
  86. package/dist/esm/compat/core/toolResults.js +203 -0
  87. package/dist/esm/compat/core/turns.d.ts +104 -0
  88. package/dist/esm/compat/core/turns.js +497 -0
  89. package/dist/esm/compat/core/warnings.d.ts +6 -0
  90. package/dist/esm/compat/core/warnings.js +20 -0
  91. package/dist/esm/compat/index.d.ts +3 -0
  92. package/dist/esm/compat/index.js +3 -0
  93. package/dist/esm/compat/openai/client.d.ts +62 -0
  94. package/dist/esm/compat/openai/client.js +104 -0
  95. package/dist/esm/compat/openai/errors.d.ts +72 -0
  96. package/dist/esm/compat/openai/errors.js +130 -0
  97. package/dist/esm/compat/openai/index.d.ts +14 -0
  98. package/dist/esm/compat/openai/index.js +17 -0
  99. package/dist/esm/compat/openai/pages.d.ts +19 -0
  100. package/dist/esm/compat/openai/pages.js +35 -0
  101. package/dist/esm/compat/openai/resources/agents.d.ts +36 -0
  102. package/dist/esm/compat/openai/resources/agents.js +540 -0
  103. package/dist/esm/compat/openai/resources/events.d.ts +23 -0
  104. package/dist/esm/compat/openai/resources/events.js +479 -0
  105. package/dist/esm/compat/openai/resources/sessions.d.ts +33 -0
  106. package/dist/esm/compat/openai/resources/sessions.js +278 -0
  107. package/dist/esm/compat/openai/stream.d.ts +40 -0
  108. package/dist/esm/compat/openai/stream.js +579 -0
  109. package/dist/esm/compat/openai/types.d.ts +125 -0
  110. package/dist/esm/compat/openai/types.js +91 -0
  111. package/dist/esm/compose/agent.d.ts +2 -0
  112. package/dist/esm/compose/agent.js +28 -2
  113. package/dist/esm/compose/functionTool.d.ts +2 -0
  114. package/dist/esm/compose/functionTool.js +45 -0
  115. package/dist/esm/compose/output.d.ts +2 -0
  116. package/dist/esm/compose/output.js +14 -7
  117. package/dist/esm/index.d.ts +2 -0
  118. package/dist/esm/index.js +2 -0
  119. package/dist/index.d.ts +2 -0
  120. package/dist/index.js +5 -1
  121. package/package.json +53 -11
  122. package/src/compat/core/agents.ts +437 -0
  123. package/src/compat/core/data.ts +283 -0
  124. package/src/compat/core/errors.ts +162 -0
  125. package/src/compat/core/events.ts +198 -0
  126. package/src/compat/core/files.ts +913 -0
  127. package/src/compat/core/history.ts +116 -0
  128. package/src/compat/core/http.ts +827 -0
  129. package/src/compat/core/ids.ts +35 -0
  130. package/src/compat/core/index.ts +14 -0
  131. package/src/compat/core/models.ts +85 -0
  132. package/src/compat/core/paging.ts +119 -0
  133. package/src/compat/core/refusals.ts +31 -0
  134. package/src/compat/core/sessions.ts +358 -0
  135. package/src/compat/core/toolResults.ts +235 -0
  136. package/src/compat/core/turns.ts +622 -0
  137. package/src/compat/core/warnings.ts +23 -0
  138. package/src/compat/index.ts +3 -0
  139. package/src/compat/openai/client.ts +177 -0
  140. package/src/compat/openai/errors.ts +165 -0
  141. package/src/compat/openai/index.ts +65 -0
  142. package/src/compat/openai/pages.ts +55 -0
  143. package/src/compat/openai/resources/agents.ts +603 -0
  144. package/src/compat/openai/resources/events.ts +523 -0
  145. package/src/compat/openai/resources/sessions.ts +369 -0
  146. package/src/compat/openai/stream.ts +599 -0
  147. package/src/compat/openai/types.ts +217 -0
  148. package/src/compose/agent.ts +30 -3
  149. package/src/compose/functionTool.ts +44 -0
  150. package/src/compose/output.ts +14 -8
  151. package/src/index.ts +3 -0
@@ -0,0 +1,4 @@
1
+ export declare const ENVIRONMENT_ID = "env_sarvam_default";
2
+ export declare function itemId(responseId: string, partIndex: number): string;
3
+ export declare function eventId(responseId: string, partIndex: number, kind: string): string;
4
+ export declare function inlineAgentName(fingerprintHex: string): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENT_ID = void 0;
4
+ exports.itemId = itemId;
5
+ exports.eventId = eventId;
6
+ exports.inlineAgentName = inlineAgentName;
7
+ /** Deterministic IDs shared across live streams and stored history. */
8
+ const node_crypto_1 = require("node:crypto");
9
+ exports.ENVIRONMENT_ID = "env_sarvam_default";
10
+ const BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
11
+ function toBase32(bytes) {
12
+ let out = "";
13
+ let bits = 0;
14
+ let value = 0;
15
+ for (let i = 0; i < bytes.length; i++) {
16
+ value = (value << 8) | bytes[i];
17
+ bits += 8;
18
+ while (bits >= 5) {
19
+ out += BASE32_ALPHABET[(value >>> (bits - 5)) & 31];
20
+ bits -= 5;
21
+ }
22
+ }
23
+ if (bits > 0)
24
+ out += BASE32_ALPHABET[(value << (5 - bits)) & 31];
25
+ return out;
26
+ }
27
+ function itemId(responseId, partIndex) {
28
+ return `${responseId}:${partIndex}`;
29
+ }
30
+ function eventId(responseId, partIndex, kind) {
31
+ const digest = (0, node_crypto_1.createHash)("sha256").update(`${responseId}|${partIndex}|${kind}`, "utf8").digest();
32
+ return `evt_${toBase32(digest).slice(0, 26)}`;
33
+ }
34
+ function inlineAgentName(fingerprintHex) {
35
+ return `sdk-inline-${fingerprintHex.slice(0, 12)}`;
36
+ }
@@ -0,0 +1,14 @@
1
+ /** Provider-neutral translation core for sarvam-agents-client/compat. */
2
+ export * from "./errors.js";
3
+ export * from "./refusals.js";
4
+ export * from "./warnings.js";
5
+ export * from "./http.js";
6
+ export * from "./models.js";
7
+ export * from "./ids.js";
8
+ export * from "./paging.js";
9
+ export * from "./agents.js";
10
+ export * from "./sessions.js";
11
+ export * from "./events.js";
12
+ export * from "./turns.js";
13
+ export * from "./toolResults.js";
14
+ export * from "./history.js";
@@ -0,0 +1,30 @@
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
+ /** Provider-neutral translation core for sarvam-agents-client/compat. */
18
+ __exportStar(require("./errors.js"), exports);
19
+ __exportStar(require("./refusals.js"), exports);
20
+ __exportStar(require("./warnings.js"), exports);
21
+ __exportStar(require("./http.js"), exports);
22
+ __exportStar(require("./models.js"), exports);
23
+ __exportStar(require("./ids.js"), exports);
24
+ __exportStar(require("./paging.js"), exports);
25
+ __exportStar(require("./agents.js"), exports);
26
+ __exportStar(require("./sessions.js"), exports);
27
+ __exportStar(require("./events.js"), exports);
28
+ __exportStar(require("./turns.js"), exports);
29
+ __exportStar(require("./toolResults.js"), exports);
30
+ __exportStar(require("./history.js"), exports);
@@ -0,0 +1,20 @@
1
+ import { Http } from "./http.js";
2
+ export interface ResolvedModel {
3
+ sarvamId: string | null;
4
+ requested: string | null;
5
+ substituted: boolean;
6
+ }
7
+ export declare class ModelResolver {
8
+ private readonly http;
9
+ private readonly map;
10
+ private readonly strict;
11
+ private readonly provider;
12
+ private catalog;
13
+ constructor(http: Http, opts?: {
14
+ modelMap?: Record<string, string>;
15
+ strict?: boolean;
16
+ provider?: string;
17
+ });
18
+ private getCatalog;
19
+ resolve(requested: string | null | undefined): Promise<ResolvedModel>;
20
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModelResolver = void 0;
4
+ /** Model catalog lookup and provider-model substitution (R2). */
5
+ const ModelsApi_js_1 = require("../../apis/ModelsApi.js");
6
+ const refusals_js_1 = require("./refusals.js");
7
+ const warnings_js_1 = require("./warnings.js");
8
+ const PROVIDER_MODEL_RE = /^(gpt-|o\d|chatgpt-|claude-)/i;
9
+ function envModelMap() {
10
+ const raw = typeof process !== "undefined" ? process.env["SARVAM_MODEL_MAP"] : undefined;
11
+ if (!raw)
12
+ return {};
13
+ try {
14
+ const parsed = JSON.parse(raw);
15
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
16
+ return {};
17
+ const out = {};
18
+ for (const [k, v] of Object.entries(parsed)) {
19
+ if (typeof v === "string")
20
+ out[k] = v;
21
+ }
22
+ return out;
23
+ }
24
+ catch (_a) {
25
+ return {};
26
+ }
27
+ }
28
+ class ModelResolver {
29
+ constructor(http, opts = {}) {
30
+ var _a, _b;
31
+ this.http = http;
32
+ this.catalog = null;
33
+ this.map = opts.modelMap ? { ...opts.modelMap } : envModelMap();
34
+ this.strict = (_a = opts.strict) !== null && _a !== void 0 ? _a : false;
35
+ this.provider = (_b = opts.provider) !== null && _b !== void 0 ? _b : "openai";
36
+ }
37
+ async getCatalog() {
38
+ var _a;
39
+ if (this.catalog === null) {
40
+ const resp = await this.http.call(() => new ModelsApi_js_1.ModelsApi(this.http.sdkConfig).listModels(), { idempotent: true });
41
+ const names = new Set();
42
+ for (const m of (_a = resp.data) !== null && _a !== void 0 ? _a : []) {
43
+ if (typeof m.name === "string" && m.name)
44
+ names.add(m.name);
45
+ }
46
+ this.catalog = names;
47
+ }
48
+ return this.catalog;
49
+ }
50
+ async resolve(requested) {
51
+ if (requested === null || requested === undefined) {
52
+ return { sarvamId: null, requested: null, substituted: false };
53
+ }
54
+ if (Object.prototype.hasOwnProperty.call(this.map, requested)) {
55
+ return { sarvamId: this.map[requested], requested, substituted: false };
56
+ }
57
+ const catalog = await this.getCatalog();
58
+ if (catalog.has(requested)) {
59
+ return { sarvamId: requested, requested, substituted: false };
60
+ }
61
+ if (PROVIDER_MODEL_RE.test(requested)) {
62
+ if (this.strict) {
63
+ (0, refusals_js_1.refuse)(this.provider, "model", {
64
+ reason: `model ${JSON.stringify(requested)} is not in the Sarvam catalog (strictModels=true)`,
65
+ });
66
+ }
67
+ (0, warnings_js_1.warnOnce)("model_substituted", `Provider model ${JSON.stringify(requested)} is running on the Sarvam default model; pass a Sarvam model ID or set modelMap / SARVAM_MODEL_MAP.`);
68
+ return { sarvamId: null, requested, substituted: true };
69
+ }
70
+ (0, refusals_js_1.refuse)(this.provider, "model", {
71
+ reason: `unknown model ${JSON.stringify(requested)} is not in the Sarvam model catalog`,
72
+ });
73
+ }
74
+ }
75
+ exports.ModelResolver = ModelResolver;
@@ -0,0 +1,14 @@
1
+ export declare function encodePageToken(offset: number): string;
2
+ export declare function decodePageToken(token: string): number;
3
+ export declare class CursorPager<T> {
4
+ private readonly fetch;
5
+ private readonly idOf;
6
+ constructor(fetch: (offset: number, limit: number) => Promise<[T[], boolean]>, idOf: (item: T) => string);
7
+ page(opts?: {
8
+ after?: string;
9
+ limit?: number;
10
+ order?: string;
11
+ }): Promise<[T[], boolean]>;
12
+ private fetchAll;
13
+ private sliceAfter;
14
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CursorPager = void 0;
4
+ exports.encodePageToken = encodePageToken;
5
+ exports.decodePageToken = decodePageToken;
6
+ /** Cursor pagination and opaque page tokens over Panja's offset lists. */
7
+ const errors_js_1 = require("./errors.js");
8
+ const LIMIT_MIN = 1;
9
+ const LIMIT_MAX = 100;
10
+ const BATCH_SIZE = 100;
11
+ function encodePageToken(offset) {
12
+ if (!Number.isInteger(offset) || offset < 0) {
13
+ throw new errors_js_1.CoreAPIError("page offset must be >= 0", {
14
+ status: 400,
15
+ code: "invalid_request_error",
16
+ param: "page",
17
+ });
18
+ }
19
+ return Buffer.from(`o:${offset}`, "utf8").toString("base64");
20
+ }
21
+ function decodePageToken(token) {
22
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(token) || token.length % 4 !== 0) {
23
+ throw new errors_js_1.CoreAPIError("Invalid page token", { status: 400, code: "invalid_request_error", param: "page" });
24
+ }
25
+ const raw = Buffer.from(token, "base64").toString("utf8");
26
+ if (!raw.startsWith("o:")) {
27
+ throw new errors_js_1.CoreAPIError("Invalid page token", { status: 400, code: "invalid_request_error", param: "page" });
28
+ }
29
+ const numStr = raw.slice(2);
30
+ if (!/^\d+$/.test(numStr)) {
31
+ throw new errors_js_1.CoreAPIError("Invalid page token", { status: 400, code: "invalid_request_error", param: "page" });
32
+ }
33
+ return Number(numStr);
34
+ }
35
+ class CursorPager {
36
+ constructor(fetch, idOf) {
37
+ this.fetch = fetch;
38
+ this.idOf = idOf;
39
+ }
40
+ async page(opts = {}) {
41
+ var _a, _b;
42
+ const limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 20;
43
+ const order = (_b = opts.order) !== null && _b !== void 0 ? _b : "desc";
44
+ const after = opts.after;
45
+ if (!Number.isInteger(limit) || limit < LIMIT_MIN || limit > LIMIT_MAX) {
46
+ throw new errors_js_1.CoreAPIError(`limit must be an integer between ${LIMIT_MIN} and ${LIMIT_MAX}`, {
47
+ status: 400,
48
+ code: "invalid_request_error",
49
+ param: "limit",
50
+ });
51
+ }
52
+ if (order !== "asc" && order !== "desc") {
53
+ throw new errors_js_1.CoreAPIError("order must be 'asc' or 'desc'", {
54
+ status: 400,
55
+ code: "invalid_request_error",
56
+ param: "order",
57
+ });
58
+ }
59
+ if (order === "asc") {
60
+ const all = await this.fetchAll();
61
+ all.reverse();
62
+ return this.sliceAfter(all, after, limit);
63
+ }
64
+ let foundAfter = after === undefined;
65
+ const collected = [];
66
+ let offset = 0;
67
+ for (;;) {
68
+ const batchLimit = after !== undefined ? Math.max(limit + 1, BATCH_SIZE) : Math.min(limit + 1, BATCH_SIZE);
69
+ const [items, hasMore] = await this.fetch(offset, batchLimit);
70
+ if (items.length === 0)
71
+ break;
72
+ for (const item of items) {
73
+ if (!foundAfter) {
74
+ if (this.idOf(item) === after)
75
+ foundAfter = true;
76
+ continue;
77
+ }
78
+ collected.push(item);
79
+ if (collected.length > limit)
80
+ return [collected.slice(0, limit), true];
81
+ }
82
+ offset += items.length;
83
+ if (!hasMore)
84
+ break;
85
+ }
86
+ if (!foundAfter) {
87
+ throw new errors_js_1.CoreAPIError(`No item found with id ${JSON.stringify(after)} for 'after' cursor.`, {
88
+ status: 400,
89
+ code: "invalid_request_error",
90
+ param: "after",
91
+ });
92
+ }
93
+ return [collected.slice(0, limit), collected.length > limit];
94
+ }
95
+ async fetchAll() {
96
+ const out = [];
97
+ let offset = 0;
98
+ for (;;) {
99
+ const [items, hasMore] = await this.fetch(offset, BATCH_SIZE);
100
+ if (items.length === 0)
101
+ break;
102
+ out.push(...items);
103
+ offset += items.length;
104
+ if (!hasMore)
105
+ break;
106
+ }
107
+ return out;
108
+ }
109
+ sliceAfter(items, after, limit) {
110
+ if (after === undefined)
111
+ return [items.slice(0, limit), items.length > limit];
112
+ const idx = items.findIndex((x) => this.idOf(x) === after);
113
+ if (idx === -1) {
114
+ throw new errors_js_1.CoreAPIError(`No item found with id ${JSON.stringify(after)} for 'after' cursor.`, {
115
+ status: 400,
116
+ code: "invalid_request_error",
117
+ param: "after",
118
+ });
119
+ }
120
+ const rest = items.slice(idx + 1);
121
+ return [rest.slice(0, limit), rest.length > limit];
122
+ }
123
+ }
124
+ exports.CursorPager = CursorPager;
@@ -0,0 +1,9 @@
1
+ export declare function formatRefusalMessage(path: string, reason: string, hint?: string): string;
2
+ export interface RefuseOverrides {
3
+ reason?: string;
4
+ hint?: string;
5
+ param?: string | null;
6
+ feature?: string;
7
+ needs?: string | null;
8
+ }
9
+ export declare function refuse(provider: string, path: string, overrides?: RefuseOverrides): never;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatRefusalMessage = formatRefusalMessage;
4
+ exports.refuse = refuse;
5
+ /** Local refusals backed by bundled shared/compat/refusals.json. */
6
+ const data_js_1 = require("./data.js");
7
+ const errors_js_1 = require("./errors.js");
8
+ const byKey = new Map();
9
+ for (const r of data_js_1.REFUSALS) {
10
+ byKey.set(`${r.provider}:${r.path}`, r);
11
+ }
12
+ function formatRefusalMessage(path, reason, hint) {
13
+ const base = `${path}: not supported by Sarvam (${reason}).`;
14
+ return hint ? `${base} ${hint}` : base;
15
+ }
16
+ function refuse(provider, path, overrides = {}) {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ const entry = byKey.get(`${provider}:${path}`);
19
+ const reason = (_b = (_a = overrides.reason) !== null && _a !== void 0 ? _a : entry === null || entry === void 0 ? void 0 : entry.reason) !== null && _b !== void 0 ? _b : "unsupported field";
20
+ const hint = overrides.hint !== undefined ? overrides.hint : ((_c = entry === null || entry === void 0 ? void 0 : entry.hint) !== null && _c !== void 0 ? _c : "");
21
+ const param = overrides.param !== undefined ? overrides.param : ((_d = entry === null || entry === void 0 ? void 0 : entry.param) !== null && _d !== void 0 ? _d : path.split("=")[0]);
22
+ const feature = (_f = (_e = overrides.feature) !== null && _e !== void 0 ? _e : entry === null || entry === void 0 ? void 0 : entry.feature) !== null && _f !== void 0 ? _f : `${provider}.unsupported.${param !== null && param !== void 0 ? param : path}`;
23
+ const needs = overrides.needs !== undefined ? overrides.needs : ((_g = entry === null || entry === void 0 ? void 0 : entry.needs) !== null && _g !== void 0 ? _g : null);
24
+ throw new errors_js_1.Unsupported(formatRefusalMessage(path, reason, hint), { param, feature, needs });
25
+ }
@@ -0,0 +1,65 @@
1
+ import type { FunctionCallRequest } from "../../compose/events.js";
2
+ import { Http } from "./http.js";
3
+ export type SessionStatus = "idle" | "running" | "requires_action" | "failed";
4
+ export interface PendingStep {
5
+ requestId: string;
6
+ responseId: string;
7
+ kind: "function" | "clarify";
8
+ calls: FunctionCallRequest[];
9
+ questions: Record<string, unknown>[];
10
+ }
11
+ export interface SessionRecord {
12
+ id: string;
13
+ agentId: string | null;
14
+ metadata: Record<string, string>;
15
+ title: string | null;
16
+ status: SessionStatus;
17
+ activeResponseId: string | null;
18
+ required: PendingStep[];
19
+ createdAt: string;
20
+ archived: boolean;
21
+ rawMetadata: Record<string, unknown>;
22
+ }
23
+ export declare class SessionUpdateQueue {
24
+ private readonly tails;
25
+ run<T>(sessionId: string, fn: () => Promise<T>): Promise<T>;
26
+ }
27
+ export declare class Sessions {
28
+ private readonly http;
29
+ private readonly api;
30
+ private readonly provider;
31
+ private readonly updateQueue;
32
+ constructor(http: Http, opts?: {
33
+ provider?: string;
34
+ updateQueue?: SessionUpdateQueue;
35
+ });
36
+ create(opts: {
37
+ agentId: string;
38
+ metadata?: Record<string, string>;
39
+ title?: string;
40
+ provider?: string;
41
+ }): Promise<SessionRecord>;
42
+ retrieve(sessionId: string): Promise<SessionRecord>;
43
+ update(sessionId: string, opts: {
44
+ metadata?: Record<string, string | null>;
45
+ title?: string;
46
+ }): Promise<SessionRecord>;
47
+ listCursor(opts?: {
48
+ cursor?: string;
49
+ limit?: number;
50
+ agentId?: string;
51
+ metadata?: Record<string, string>;
52
+ buffered?: SessionRecord[];
53
+ }): Promise<{
54
+ items: SessionRecord[];
55
+ nextCursor: string | null;
56
+ hasMore: boolean;
57
+ leftover: SessionRecord[];
58
+ }>;
59
+ list(offset?: number, limit?: number, filters?: {
60
+ agentId?: string;
61
+ metadata?: Record<string, string>;
62
+ }): Promise<[SessionRecord[], boolean]>;
63
+ delete(sessionId: string): Promise<void>;
64
+ ensureNotArchived(sessionId: string): Promise<SessionRecord>;
65
+ }