@lingya-ai/agents-sdk 0.1.2 → 0.3.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,7 +1,7 @@
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
3
  import { type LingyaAiChatBriefEvent } from './events';
4
+ import { LingyaAgentsLowLevelApis, LingyaChatApi, LingyaConfigurationApi, LingyaConversationsApi, LingyaEventsApi, LingyaFilesApi, LingyaInteractionsApi, LingyaKnowledgeApi, LingyaMessagesApi, LingyaSqlApi, LingyaWorkspaceApi } from './bound';
5
5
  /**
6
6
  * Lingya Agents SDK 入口,仅适用于可信服务端。 / Server-side Lingya Agents SDK entry point.
7
7
  *
@@ -33,25 +33,31 @@ export declare class LingyaAgentsUserClient {
33
33
  private readonly signedFetch;
34
34
  private readonly baseUrl;
35
35
  /** 发起新聊天和流探针。 / Starts chats and stream probes. */
36
- readonly chat: ChatApi;
36
+ readonly chat: LingyaChatApi;
37
37
  /** 读取 Agent 与会话配置。 / Reads Agent and conversation configuration. */
38
- readonly configuration: ConfigurationApi;
38
+ readonly configuration: LingyaConfigurationApi;
39
39
  /** 管理会话、状态、分享和异步任务。 / Manages conversations, status, shares, and async tasks. */
40
- readonly conversations: ConversationsApi;
40
+ readonly conversations: LingyaConversationsApi;
41
41
  /** 查询已持久化事件。 / Reads persisted events. */
42
- readonly events: EventsApi;
42
+ readonly events: LingyaEventsApi;
43
43
  /** 管理附件与预签名 URL。 / Manages attachments and pre-signed URLs. */
44
- readonly files: FilesApi;
44
+ readonly files: LingyaFilesApi;
45
45
  /** 回答用户问题并处理计划审批。 / Handles user answers and plan approval. */
46
- readonly interactions: InteractionsApi;
46
+ readonly interactions: LingyaInteractionsApi;
47
47
  /** 查询引用元数据。 / Reads citation metadata. */
48
- readonly knowledge: KnowledgeApi;
48
+ readonly knowledge: LingyaKnowledgeApi;
49
49
  /** 查询消息并控制排队消息。 / Reads messages and controls queued messages. */
50
- readonly messages: MessagesApi;
50
+ readonly messages: LingyaMessagesApi;
51
51
  /** 查询、导出 SQL 结果与图表数据。 / Reads and exports SQL results and chart data. */
52
- readonly sql: SQLApi;
52
+ readonly sql: LingyaSqlApi;
53
53
  /** 查询工作区文件及预览。 / Reads workspace files and previews. */
54
- readonly workspace: WorkspaceApi;
54
+ readonly workspace: LingyaWorkspaceApi;
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: LingyaAgentsLowLevelApis;
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.
@@ -63,6 +69,7 @@ export declare class LingyaAgentsUserClient {
63
69
  * @returns 调用方指定的响应类型。
64
70
  * @throws [LingyaApiError] 当服务端返回非 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,6 +99,7 @@ export declare class LingyaAgentsUserClient {
90
99
  * @param messageId - 触发本次生成的消息 ID。
91
100
  * @returns 支持取消的异步事件序列;未知 type 保留 `rawJson`。
92
101
  */
102
+ /** @deprecated 使用 `chat.streamChatEvents(conversationId, { messageId })`。 / Use the channel-bound chat facade. */
93
103
  streamChatEvents(conversationId: string, messageId: string): AsyncGenerator<LingyaAiChatBriefEvent>;
94
104
  /**
95
105
  * 发送底层受控请求;调用前固定最终 path、query、Content-Type 与 body 字节。 / Sends an exactly signed low-level request.
@@ -104,7 +114,8 @@ export declare class LingyaAgentsUserClient {
104
114
  * @returns 成功的原始 Fetch Response。
105
115
  * @throws [LingyaApiError] 当服务端返回非 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
121
  export declare class LingyaApiError extends Error {
package/dist/client.js CHANGED
@@ -8,33 +8,12 @@ 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
12
  exports.LingyaApiError = exports.LingyaAgentsUserClient = exports.LingyaAgentsClient = 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
  *
@@ -74,16 +53,28 @@ class LingyaAgentsUserClient {
74
53
  this.channelId = channelId;
75
54
  this.signedFetch = signedFetch;
76
55
  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);
56
+ const chat = new apis_1.ChatApi(configuration);
57
+ const configurationApi = new apis_1.ConfigurationApi(configuration);
58
+ const conversations = new apis_1.ConversationsApi(configuration);
59
+ const events = new apis_1.EventsApi(configuration);
60
+ const files = new apis_1.FilesApi(configuration);
61
+ const interactions = new apis_1.InteractionsApi(configuration);
62
+ const knowledge = new apis_1.KnowledgeApi(configuration);
63
+ const messages = new apis_1.MessagesApi(configuration);
64
+ const sql = new apis_1.SQLApi(configuration);
65
+ const workspace = new apis_1.WorkspaceApi(configuration);
66
+ this.lowLevel = new bound_1.LingyaAgentsLowLevelApis(configurationApi, chat, conversations, sql, messages, events, interactions, files, knowledge, workspace);
67
+ const rawRequest = this.rawRequest.bind(this);
68
+ this.chat = new bound_1.LingyaChatApi(channelId, chat, rawRequest);
69
+ this.configuration = new bound_1.LingyaConfigurationApi(channelId, configurationApi);
70
+ this.conversations = new bound_1.LingyaConversationsApi(channelId, conversations);
71
+ this.events = new bound_1.LingyaEventsApi(channelId, events);
72
+ this.files = new bound_1.LingyaFilesApi(channelId, files);
73
+ this.interactions = new bound_1.LingyaInteractionsApi(channelId, interactions);
74
+ this.knowledge = new bound_1.LingyaKnowledgeApi(channelId, knowledge);
75
+ this.messages = new bound_1.LingyaMessagesApi(channelId, messages);
76
+ this.sql = new bound_1.LingyaSqlApi(channelId, sql);
77
+ this.workspace = new bound_1.LingyaWorkspaceApi(channelId, workspace);
87
78
  }
88
79
  /**
89
80
  * 调用契约端点并按指定类型返回 JSON;优先使用上方生成的强类型 API。 / Calls a contract endpoint and decodes typed JSON.
@@ -95,6 +86,7 @@ class LingyaAgentsUserClient {
95
86
  * @returns 调用方指定的响应类型。
96
87
  * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
97
88
  */
89
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
98
90
  request(method, suffix, bodyJson, query) {
99
91
  return __awaiter(this, void 0, void 0, function* () {
100
92
  const response = yield this.rawRequest(method, suffix, bodyJson, query, 'application/json');
@@ -110,6 +102,7 @@ class LingyaAgentsUserClient {
110
102
  * @param query - 保留顺序的查询参数。
111
103
  * @returns 2xx HTTP 状态码。
112
104
  */
105
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
113
106
  requestStatus(method, suffix, bodyJson, query) {
114
107
  return __awaiter(this, void 0, void 0, function* () {
115
108
  return (yield this.rawRequest(method, suffix, bodyJson, query, 'application/json')).status;
@@ -123,6 +116,7 @@ class LingyaAgentsUserClient {
123
116
  * @param query - 保留顺序的查询参数。
124
117
  * @returns 未经文本转换的响应字节。
125
118
  */
119
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
126
120
  requestBinary(method, suffix, query) {
127
121
  return __awaiter(this, void 0, void 0, function* () {
128
122
  const response = yield this.rawRequest(method, suffix, undefined, query, 'application/octet-stream');
@@ -136,27 +130,9 @@ class LingyaAgentsUserClient {
136
130
  * @param messageId - 触发本次生成的消息 ID。
137
131
  * @returns 支持取消的异步事件序列;未知 type 保留 `rawJson`。
138
132
  */
133
+ /** @deprecated 使用 `chat.streamChatEvents(conversationId, { messageId })`。 / Use the channel-bound chat facade. */
139
134
  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
- });
135
+ return this.chat.streamChatEvents(conversationId, { messageId });
160
136
  }
161
137
  /**
162
138
  * 发送底层受控请求;调用前固定最终 path、query、Content-Type 与 body 字节。 / Sends an exactly signed low-level request.
@@ -171,13 +147,14 @@ class LingyaAgentsUserClient {
171
147
  * @returns 成功的原始 Fetch Response。
172
148
  * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
173
149
  */
150
+ /** @deprecated 使用 `lowLevel`,或使用对应的业务分组方法。 / Use `lowLevel` or a grouped facade operation. */
174
151
  rawRequest(method_1, suffix_1, bodyJson_1, query_1) {
175
- return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json') {
152
+ return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json', requestId) {
176
153
  const root = `${this.baseUrl.replace(/\/+$/, '')}/api/agents/channel/openapi/v1/${encodeURIComponent(this.channelId)}/chat`;
177
154
  const url = `${root}${suffix}${query === undefined || query.size === 0 ? '' : `?${query.toString()}`}`;
178
155
  const response = yield this.signedFetch(url, {
179
156
  method,
180
- headers: Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })),
157
+ headers: Object.assign(Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })), (requestId === undefined ? {} : { 'X-Request-ID': requestId })),
181
158
  body: bodyJson,
182
159
  });
183
160
  if (!response.ok)