@lingya-ai/agents-sdk 0.1.2 → 0.4.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/dist/client.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Configuration } from './runtime';
2
- import { ChatApi, ConfigurationApi, ConversationsApi, EventsApi, FilesApi, InteractionsApi, KnowledgeApi, MessagesApi, SQLApi, WorkspaceApi } from './apis';
3
2
  import { type OpenApiCredentials } from './hmac';
4
- import { type LingyaAiChatBriefEvent } from './events';
3
+ import { type AiChatBriefEvent } from './events';
4
+ import { AgentsLowLevelApis, ChatApi as BoundChatApi, ConfigurationApi as BoundConfigurationApi, ConversationsApi as BoundConversationsApi, EventsApi as BoundEventsApi, FilesApi as BoundFilesApi, InteractionsApi as BoundInteractionsApi, KnowledgeApi as BoundKnowledgeApi, MessagesApi as BoundMessagesApi, SqlApi, WorkspaceApi as BoundWorkspaceApi } from './bound';
5
5
  /**
6
6
  * Lingya Agents SDK 入口,仅适用于可信服务端。 / Server-side Lingya Agents SDK entry point.
7
7
  *
8
8
  * 客户端保存 channel 范围的凭证,但只有 [forUser] 创建的用户客户端可以发起请求。
9
9
  */
10
- export declare class LingyaAgentsClient {
10
+ export declare class AgentsClient {
11
11
  private readonly baseUrl;
12
12
  readonly channelId: string;
13
13
  private readonly credentials;
@@ -25,33 +25,39 @@ export declare class LingyaAgentsClient {
25
25
  * @param externalUserId - 调用方系统的稳定用户 ID,UTF-8 编码后为 1..256 字节且不能含 NUL。
26
26
  * @returns 注入用户身份并可调用全部契约 API 的客户端。
27
27
  */
28
- forUser(externalUserId: string): LingyaAgentsUserClient;
28
+ forUser(externalUserId: string): AgentsUserClient;
29
29
  }
30
30
  /** 已绑定外部用户的强类型 API 集合。 / Strongly typed API collection bound to one external user. */
31
- export declare class LingyaAgentsUserClient {
31
+ export declare class AgentsUserClient {
32
32
  readonly channelId: string;
33
33
  private readonly signedFetch;
34
34
  private readonly baseUrl;
35
35
  /** 发起新聊天和流探针。 / Starts chats and stream probes. */
36
- readonly chat: ChatApi;
36
+ readonly chat: BoundChatApi;
37
37
  /** 读取 Agent 与会话配置。 / Reads Agent and conversation configuration. */
38
- readonly configuration: ConfigurationApi;
38
+ readonly configuration: BoundConfigurationApi;
39
39
  /** 管理会话、状态、分享和异步任务。 / Manages conversations, status, shares, and async tasks. */
40
- readonly conversations: ConversationsApi;
40
+ readonly conversations: BoundConversationsApi;
41
41
  /** 查询已持久化事件。 / Reads persisted events. */
42
- readonly events: EventsApi;
42
+ readonly events: BoundEventsApi;
43
43
  /** 管理附件与预签名 URL。 / Manages attachments and pre-signed URLs. */
44
- readonly files: FilesApi;
44
+ readonly files: BoundFilesApi;
45
45
  /** 回答用户问题并处理计划审批。 / Handles user answers and plan approval. */
46
- readonly interactions: InteractionsApi;
46
+ readonly interactions: BoundInteractionsApi;
47
47
  /** 查询引用元数据。 / Reads citation metadata. */
48
- readonly knowledge: KnowledgeApi;
48
+ readonly knowledge: BoundKnowledgeApi;
49
49
  /** 查询消息并控制排队消息。 / Reads messages and controls queued messages. */
50
- readonly messages: MessagesApi;
50
+ readonly messages: BoundMessagesApi;
51
51
  /** 查询、导出 SQL 结果与图表数据。 / Reads and exports SQL results and chart data. */
52
- readonly sql: SQLApi;
52
+ readonly sql: SqlApi;
53
53
  /** 查询工作区文件及预览。 / Reads workspace files and previews. */
54
- readonly workspace: WorkspaceApi;
54
+ readonly workspace: BoundWorkspaceApi;
55
+ /**
56
+ * 兼容旧版本的原始生成 API;正常业务调用应使用绑定门面。 / Raw generated APIs retained for migration only.
57
+ *
58
+ * @deprecated 将在 1.0 移除。 / Scheduled for removal in 1.0.
59
+ */
60
+ readonly lowLevel: AgentsLowLevelApis;
55
61
  constructor(channelId: string, configuration: Configuration, signedFetch: typeof fetch, baseUrl: string);
56
62
  /**
57
63
  * 调用契约端点并按指定类型返回 JSON;优先使用上方生成的强类型 API。 / Calls a contract endpoint and decodes typed JSON.
@@ -61,8 +67,9 @@ export declare class LingyaAgentsUserClient {
61
67
  * @param bodyJson - 最终发送并参与签名的 UTF-8 JSON 字符串;无请求体时省略。
62
68
  * @param query - 已按最终顺序组装的查询参数,允许重复键。
63
69
  * @returns 调用方指定的响应类型。
64
- * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
70
+ * @throws [ApiError] 当服务端返回非 2xx 状态。
65
71
  */
72
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
66
73
  request<T>(method: string, suffix: string, bodyJson?: string, query?: URLSearchParams): Promise<T>;
67
74
  /**
68
75
  * 调用无响应正文的契约端点。 / Calls a contract endpoint that has no response body.
@@ -73,6 +80,7 @@ export declare class LingyaAgentsUserClient {
73
80
  * @param query - 保留顺序的查询参数。
74
81
  * @returns 2xx HTTP 状态码。
75
82
  */
83
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
76
84
  requestStatus(method: string, suffix: string, bodyJson?: string, query?: URLSearchParams): Promise<number>;
77
85
  /**
78
86
  * 下载二进制响应,返回精确响应字节。 / Downloads an exact binary response.
@@ -82,6 +90,7 @@ export declare class LingyaAgentsUserClient {
82
90
  * @param query - 保留顺序的查询参数。
83
91
  * @returns 未经文本转换的响应字节。
84
92
  */
93
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
85
94
  requestBinary(method: string, suffix: string, query?: URLSearchParams): Promise<Uint8Array>;
86
95
  /**
87
96
  * 订阅对话 SSE,事件按契约判别联合返回。 / Streams SSE as the contract discriminated union.
@@ -90,7 +99,8 @@ export declare class LingyaAgentsUserClient {
90
99
  * @param messageId - 触发本次生成的消息 ID。
91
100
  * @returns 支持取消的异步事件序列;未知 type 保留 `rawJson`。
92
101
  */
93
- streamChatEvents(conversationId: string, messageId: string): AsyncGenerator<LingyaAiChatBriefEvent>;
102
+ /** @deprecated 使用 `chat.streamChatEvents(conversationId, { messageId })`。 / Use the channel-bound chat facade. */
103
+ streamChatEvents(conversationId: string, messageId: string): AsyncGenerator<AiChatBriefEvent>;
94
104
  /**
95
105
  * 发送底层受控请求;调用前固定最终 path、query、Content-Type 与 body 字节。 / Sends an exactly signed low-level request.
96
106
  *
@@ -102,15 +112,22 @@ export declare class LingyaAgentsUserClient {
102
112
  * @param query - 最终查询参数;顺序和重复键均参与签名。
103
113
  * @param accept - 精确的 Accept 值,例如 `application/json`、`text/event-stream` 或 `text/csv`。
104
114
  * @returns 成功的原始 Fetch Response。
105
- * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
115
+ * @throws [ApiError] 当服务端返回非 2xx 状态。
106
116
  */
107
- rawRequest(method: string, suffix: string, bodyJson?: string, query?: URLSearchParams, accept?: string): Promise<Response>;
117
+ /** @deprecated 使用 `lowLevel`,或使用对应的业务分组方法。 / Use `lowLevel` or a grouped facade operation. */
118
+ rawRequest(method: string, suffix: string, bodyJson?: string, query?: URLSearchParams, accept?: string, requestId?: string): Promise<Response>;
108
119
  }
109
120
  /** 不含凭证的 HTTP 错误。 / HTTP failure that never includes credentials. */
110
- export declare class LingyaApiError extends Error {
121
+ export declare class ApiError extends Error {
111
122
  readonly method: string;
112
123
  readonly path: string;
113
124
  readonly status: number;
114
125
  readonly responseBody: string;
115
126
  constructor(method: string, path: string, status: number, responseBody: string);
116
127
  }
128
+ /** @deprecated Use [AgentsClient]. */
129
+ export { AgentsClient as LingyaAgentsClient };
130
+ /** @deprecated Use [AgentsUserClient]. */
131
+ export { AgentsUserClient as LingyaAgentsUserClient };
132
+ /** @deprecated Use [ApiError]. */
133
+ export { ApiError as LingyaApiError };
package/dist/client.js CHANGED
@@ -8,39 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
12
- var __asyncValues = (this && this.__asyncValues) || function (o) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var m = o[Symbol.asyncIterator], i;
15
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
16
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
17
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
18
- };
19
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
20
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
21
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
22
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
23
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
24
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
25
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
26
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
27
- function fulfill(value) { resume("next", value); }
28
- function reject(value) { resume("throw", value); }
29
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
30
- };
31
11
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.LingyaApiError = exports.LingyaAgentsUserClient = exports.LingyaAgentsClient = void 0;
12
+ exports.LingyaApiError = exports.LingyaAgentsUserClient = exports.LingyaAgentsClient = exports.ApiError = exports.AgentsUserClient = exports.AgentsClient = void 0;
33
13
  const runtime_1 = require("./runtime");
34
14
  const apis_1 = require("./apis");
35
15
  const hmac_1 = require("./hmac");
36
- const sse_1 = require("./sse");
37
- const events_1 = require("./events");
16
+ const bound_1 = require("./bound");
38
17
  /**
39
18
  * Lingya Agents SDK 入口,仅适用于可信服务端。 / Server-side Lingya Agents SDK entry point.
40
19
  *
41
20
  * 客户端保存 channel 范围的凭证,但只有 [forUser] 创建的用户客户端可以发起请求。
42
21
  */
43
- class LingyaAgentsClient {
22
+ class AgentsClient {
44
23
  /**
45
24
  * 创建 channel 范围的客户端。 / Creates a channel-scoped client.
46
25
  *
@@ -64,26 +43,39 @@ class LingyaAgentsClient {
64
43
  forUser(externalUserId) {
65
44
  const signedFetch = (0, hmac_1.createSignedFetch)(this.credentials, externalUserId);
66
45
  const configuration = new runtime_1.Configuration({ basePath: this.baseUrl.replace(/\/+$/, ''), fetchApi: signedFetch });
67
- return new LingyaAgentsUserClient(this.channelId, configuration, signedFetch, this.baseUrl);
46
+ return new AgentsUserClient(this.channelId, configuration, signedFetch, this.baseUrl);
68
47
  }
69
48
  }
70
- exports.LingyaAgentsClient = LingyaAgentsClient;
49
+ exports.AgentsClient = AgentsClient;
50
+ exports.LingyaAgentsClient = AgentsClient;
71
51
  /** 已绑定外部用户的强类型 API 集合。 / Strongly typed API collection bound to one external user. */
72
- class LingyaAgentsUserClient {
52
+ class AgentsUserClient {
73
53
  constructor(channelId, configuration, signedFetch, baseUrl) {
74
54
  this.channelId = channelId;
75
55
  this.signedFetch = signedFetch;
76
56
  this.baseUrl = baseUrl;
77
- this.chat = new apis_1.ChatApi(configuration);
78
- this.configuration = new apis_1.ConfigurationApi(configuration);
79
- this.conversations = new apis_1.ConversationsApi(configuration);
80
- this.events = new apis_1.EventsApi(configuration);
81
- this.files = new apis_1.FilesApi(configuration);
82
- this.interactions = new apis_1.InteractionsApi(configuration);
83
- this.knowledge = new apis_1.KnowledgeApi(configuration);
84
- this.messages = new apis_1.MessagesApi(configuration);
85
- this.sql = new apis_1.SQLApi(configuration);
86
- this.workspace = new apis_1.WorkspaceApi(configuration);
57
+ const chat = new apis_1.ChatApi(configuration);
58
+ const configurationApi = new apis_1.ConfigurationApi(configuration);
59
+ const conversations = new apis_1.ConversationsApi(configuration);
60
+ const events = new apis_1.EventsApi(configuration);
61
+ const files = new apis_1.FilesApi(configuration);
62
+ const interactions = new apis_1.InteractionsApi(configuration);
63
+ const knowledge = new apis_1.KnowledgeApi(configuration);
64
+ const messages = new apis_1.MessagesApi(configuration);
65
+ const sql = new apis_1.SQLApi(configuration);
66
+ const workspace = new apis_1.WorkspaceApi(configuration);
67
+ this.lowLevel = new bound_1.AgentsLowLevelApis(configurationApi, chat, conversations, sql, messages, events, interactions, files, knowledge, workspace);
68
+ const rawRequest = this.rawRequest.bind(this);
69
+ this.chat = new bound_1.ChatApi(channelId, chat, rawRequest);
70
+ this.configuration = new bound_1.ConfigurationApi(channelId, configurationApi);
71
+ this.conversations = new bound_1.ConversationsApi(channelId, conversations);
72
+ this.events = new bound_1.EventsApi(channelId, events);
73
+ this.files = new bound_1.FilesApi(channelId, files);
74
+ this.interactions = new bound_1.InteractionsApi(channelId, interactions);
75
+ this.knowledge = new bound_1.KnowledgeApi(channelId, knowledge);
76
+ this.messages = new bound_1.MessagesApi(channelId, messages);
77
+ this.sql = new bound_1.SqlApi(channelId, sql);
78
+ this.workspace = new bound_1.WorkspaceApi(channelId, workspace);
87
79
  }
88
80
  /**
89
81
  * 调用契约端点并按指定类型返回 JSON;优先使用上方生成的强类型 API。 / Calls a contract endpoint and decodes typed JSON.
@@ -93,8 +85,9 @@ class LingyaAgentsUserClient {
93
85
  * @param bodyJson - 最终发送并参与签名的 UTF-8 JSON 字符串;无请求体时省略。
94
86
  * @param query - 已按最终顺序组装的查询参数,允许重复键。
95
87
  * @returns 调用方指定的响应类型。
96
- * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
88
+ * @throws [ApiError] 当服务端返回非 2xx 状态。
97
89
  */
90
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
98
91
  request(method, suffix, bodyJson, query) {
99
92
  return __awaiter(this, void 0, void 0, function* () {
100
93
  const response = yield this.rawRequest(method, suffix, bodyJson, query, 'application/json');
@@ -110,6 +103,7 @@ class LingyaAgentsUserClient {
110
103
  * @param query - 保留顺序的查询参数。
111
104
  * @returns 2xx HTTP 状态码。
112
105
  */
106
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
113
107
  requestStatus(method, suffix, bodyJson, query) {
114
108
  return __awaiter(this, void 0, void 0, function* () {
115
109
  return (yield this.rawRequest(method, suffix, bodyJson, query, 'application/json')).status;
@@ -123,6 +117,7 @@ class LingyaAgentsUserClient {
123
117
  * @param query - 保留顺序的查询参数。
124
118
  * @returns 未经文本转换的响应字节。
125
119
  */
120
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
126
121
  requestBinary(method, suffix, query) {
127
122
  return __awaiter(this, void 0, void 0, function* () {
128
123
  const response = yield this.rawRequest(method, suffix, undefined, query, 'application/octet-stream');
@@ -136,27 +131,9 @@ class LingyaAgentsUserClient {
136
131
  * @param messageId - 触发本次生成的消息 ID。
137
132
  * @returns 支持取消的异步事件序列;未知 type 保留 `rawJson`。
138
133
  */
134
+ /** @deprecated 使用 `chat.streamChatEvents(conversationId, { messageId })`。 / Use the channel-bound chat facade. */
139
135
  streamChatEvents(conversationId, messageId) {
140
- return __asyncGenerator(this, arguments, function* streamChatEvents_1() {
141
- var _a, e_1, _b, _c;
142
- const suffix = `/conversations/${encodeURIComponent(conversationId)}/stream`;
143
- const response = yield __await(this.rawRequest('POST', suffix, JSON.stringify({ messageId }), undefined, 'text/event-stream'));
144
- try {
145
- for (var _d = true, _e = __asyncValues((0, sse_1.decodeSse)(response)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
146
- _c = _f.value;
147
- _d = false;
148
- const data = _c;
149
- yield yield __await((0, events_1.decodeAiChatBriefEvent)(data));
150
- }
151
- }
152
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
153
- finally {
154
- try {
155
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
156
- }
157
- finally { if (e_1) throw e_1.error; }
158
- }
159
- });
136
+ return this.chat.streamChatEvents(conversationId, { messageId });
160
137
  }
161
138
  /**
162
139
  * 发送底层受控请求;调用前固定最终 path、query、Content-Type 与 body 字节。 / Sends an exactly signed low-level request.
@@ -169,33 +146,36 @@ class LingyaAgentsUserClient {
169
146
  * @param query - 最终查询参数;顺序和重复键均参与签名。
170
147
  * @param accept - 精确的 Accept 值,例如 `application/json`、`text/event-stream` 或 `text/csv`。
171
148
  * @returns 成功的原始 Fetch Response。
172
- * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
149
+ * @throws [ApiError] 当服务端返回非 2xx 状态。
173
150
  */
151
+ /** @deprecated 使用 `lowLevel`,或使用对应的业务分组方法。 / Use `lowLevel` or a grouped facade operation. */
174
152
  rawRequest(method_1, suffix_1, bodyJson_1, query_1) {
175
- return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json') {
153
+ return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json', requestId) {
176
154
  const root = `${this.baseUrl.replace(/\/+$/, '')}/api/agents/channel/openapi/v1/${encodeURIComponent(this.channelId)}/chat`;
177
155
  const url = `${root}${suffix}${query === undefined || query.size === 0 ? '' : `?${query.toString()}`}`;
178
156
  const response = yield this.signedFetch(url, {
179
157
  method,
180
- headers: Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })),
158
+ headers: Object.assign(Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })), (requestId === undefined ? {} : { 'X-Request-ID': requestId })),
181
159
  body: bodyJson,
182
160
  });
183
161
  if (!response.ok)
184
- throw new LingyaApiError(method, suffix, response.status, yield response.text());
162
+ throw new ApiError(method, suffix, response.status, yield response.text());
185
163
  return response;
186
164
  });
187
165
  }
188
166
  }
189
- exports.LingyaAgentsUserClient = LingyaAgentsUserClient;
167
+ exports.AgentsUserClient = AgentsUserClient;
168
+ exports.LingyaAgentsUserClient = AgentsUserClient;
190
169
  /** 不含凭证的 HTTP 错误。 / HTTP failure that never includes credentials. */
191
- class LingyaApiError extends Error {
170
+ class ApiError extends Error {
192
171
  constructor(method, path, status, responseBody) {
193
172
  super(`${method} ${path} returned HTTP ${status}`);
194
173
  this.method = method;
195
174
  this.path = path;
196
175
  this.status = status;
197
176
  this.responseBody = responseBody;
198
- this.name = 'LingyaApiError';
177
+ this.name = 'ApiError';
199
178
  }
200
179
  }
201
- exports.LingyaApiError = LingyaApiError;
180
+ exports.ApiError = ApiError;
181
+ exports.LingyaApiError = ApiError;