@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.
@@ -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 {
@@ -7,31 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- 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);
15
- 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); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
19
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
20
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
21
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
22
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
23
- 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]); } }
24
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
25
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
26
- function fulfill(value) { resume("next", value); }
27
- function reject(value) { resume("throw", value); }
28
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
29
- };
30
10
  import { Configuration } from './runtime';
31
11
  import { ChatApi, ConfigurationApi, ConversationsApi, EventsApi, FilesApi, InteractionsApi, KnowledgeApi, MessagesApi, SQLApi, WorkspaceApi } from './apis';
32
12
  import { createSignedFetch } from './hmac';
33
- import { decodeSse } from './sse';
34
- import { decodeAiChatBriefEvent } from './events';
13
+ import { LingyaAgentsLowLevelApis, LingyaChatApi, LingyaConfigurationApi, LingyaConversationsApi, LingyaEventsApi, LingyaFilesApi, LingyaInteractionsApi, LingyaKnowledgeApi, LingyaMessagesApi, LingyaSqlApi, LingyaWorkspaceApi, } from './bound';
35
14
  /**
36
15
  * Lingya Agents SDK 入口,仅适用于可信服务端。 / Server-side Lingya Agents SDK entry point.
37
16
  *
@@ -70,16 +49,28 @@ export class LingyaAgentsUserClient {
70
49
  this.channelId = channelId;
71
50
  this.signedFetch = signedFetch;
72
51
  this.baseUrl = baseUrl;
73
- this.chat = new ChatApi(configuration);
74
- this.configuration = new ConfigurationApi(configuration);
75
- this.conversations = new ConversationsApi(configuration);
76
- this.events = new EventsApi(configuration);
77
- this.files = new FilesApi(configuration);
78
- this.interactions = new InteractionsApi(configuration);
79
- this.knowledge = new KnowledgeApi(configuration);
80
- this.messages = new MessagesApi(configuration);
81
- this.sql = new SQLApi(configuration);
82
- this.workspace = new WorkspaceApi(configuration);
52
+ const chat = new ChatApi(configuration);
53
+ const configurationApi = new ConfigurationApi(configuration);
54
+ const conversations = new ConversationsApi(configuration);
55
+ const events = new EventsApi(configuration);
56
+ const files = new FilesApi(configuration);
57
+ const interactions = new InteractionsApi(configuration);
58
+ const knowledge = new KnowledgeApi(configuration);
59
+ const messages = new MessagesApi(configuration);
60
+ const sql = new SQLApi(configuration);
61
+ const workspace = new WorkspaceApi(configuration);
62
+ this.lowLevel = new LingyaAgentsLowLevelApis(configurationApi, chat, conversations, sql, messages, events, interactions, files, knowledge, workspace);
63
+ const rawRequest = this.rawRequest.bind(this);
64
+ this.chat = new LingyaChatApi(channelId, chat, rawRequest);
65
+ this.configuration = new LingyaConfigurationApi(channelId, configurationApi);
66
+ this.conversations = new LingyaConversationsApi(channelId, conversations);
67
+ this.events = new LingyaEventsApi(channelId, events);
68
+ this.files = new LingyaFilesApi(channelId, files);
69
+ this.interactions = new LingyaInteractionsApi(channelId, interactions);
70
+ this.knowledge = new LingyaKnowledgeApi(channelId, knowledge);
71
+ this.messages = new LingyaMessagesApi(channelId, messages);
72
+ this.sql = new LingyaSqlApi(channelId, sql);
73
+ this.workspace = new LingyaWorkspaceApi(channelId, workspace);
83
74
  }
84
75
  /**
85
76
  * 调用契约端点并按指定类型返回 JSON;优先使用上方生成的强类型 API。 / Calls a contract endpoint and decodes typed JSON.
@@ -91,6 +82,7 @@ export class LingyaAgentsUserClient {
91
82
  * @returns 调用方指定的响应类型。
92
83
  * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
93
84
  */
85
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
94
86
  request(method, suffix, bodyJson, query) {
95
87
  return __awaiter(this, void 0, void 0, function* () {
96
88
  const response = yield this.rawRequest(method, suffix, bodyJson, query, 'application/json');
@@ -106,6 +98,7 @@ export class LingyaAgentsUserClient {
106
98
  * @param query - 保留顺序的查询参数。
107
99
  * @returns 2xx HTTP 状态码。
108
100
  */
101
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
109
102
  requestStatus(method, suffix, bodyJson, query) {
110
103
  return __awaiter(this, void 0, void 0, function* () {
111
104
  return (yield this.rawRequest(method, suffix, bodyJson, query, 'application/json')).status;
@@ -119,6 +112,7 @@ export class LingyaAgentsUserClient {
119
112
  * @param query - 保留顺序的查询参数。
120
113
  * @returns 未经文本转换的响应字节。
121
114
  */
115
+ /** @deprecated 使用对应的业务分组方法。 / Use the matching grouped facade operation. */
122
116
  requestBinary(method, suffix, query) {
123
117
  return __awaiter(this, void 0, void 0, function* () {
124
118
  const response = yield this.rawRequest(method, suffix, undefined, query, 'application/octet-stream');
@@ -132,27 +126,9 @@ export class LingyaAgentsUserClient {
132
126
  * @param messageId - 触发本次生成的消息 ID。
133
127
  * @returns 支持取消的异步事件序列;未知 type 保留 `rawJson`。
134
128
  */
129
+ /** @deprecated 使用 `chat.streamChatEvents(conversationId, { messageId })`。 / Use the channel-bound chat facade. */
135
130
  streamChatEvents(conversationId, messageId) {
136
- return __asyncGenerator(this, arguments, function* streamChatEvents_1() {
137
- var _a, e_1, _b, _c;
138
- const suffix = `/conversations/${encodeURIComponent(conversationId)}/stream`;
139
- const response = yield __await(this.rawRequest('POST', suffix, JSON.stringify({ messageId }), undefined, 'text/event-stream'));
140
- try {
141
- for (var _d = true, _e = __asyncValues(decodeSse(response)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
142
- _c = _f.value;
143
- _d = false;
144
- const data = _c;
145
- yield yield __await(decodeAiChatBriefEvent(data));
146
- }
147
- }
148
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
149
- finally {
150
- try {
151
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
152
- }
153
- finally { if (e_1) throw e_1.error; }
154
- }
155
- });
131
+ return this.chat.streamChatEvents(conversationId, { messageId });
156
132
  }
157
133
  /**
158
134
  * 发送底层受控请求;调用前固定最终 path、query、Content-Type 与 body 字节。 / Sends an exactly signed low-level request.
@@ -167,13 +143,14 @@ export class LingyaAgentsUserClient {
167
143
  * @returns 成功的原始 Fetch Response。
168
144
  * @throws [LingyaApiError] 当服务端返回非 2xx 状态。
169
145
  */
146
+ /** @deprecated 使用 `lowLevel`,或使用对应的业务分组方法。 / Use `lowLevel` or a grouped facade operation. */
170
147
  rawRequest(method_1, suffix_1, bodyJson_1, query_1) {
171
- return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json') {
148
+ return __awaiter(this, arguments, void 0, function* (method, suffix, bodyJson, query, accept = 'application/json', requestId) {
172
149
  const root = `${this.baseUrl.replace(/\/+$/, '')}/api/agents/channel/openapi/v1/${encodeURIComponent(this.channelId)}/chat`;
173
150
  const url = `${root}${suffix}${query === undefined || query.size === 0 ? '' : `?${query.toString()}`}`;
174
151
  const response = yield this.signedFetch(url, {
175
152
  method,
176
- headers: Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })),
153
+ headers: Object.assign(Object.assign({ Accept: accept }, (bodyJson === undefined ? {} : { 'Content-Type': 'application/json' })), (requestId === undefined ? {} : { 'X-Request-ID': requestId })),
177
154
  body: bodyJson,
178
155
  });
179
156
  if (!response.ok)
@@ -2,6 +2,7 @@ export * from './runtime';
2
2
  export * from './apis/index';
3
3
  export * from './models/index';
4
4
  export * from './client';
5
+ export * from './bound';
5
6
  export * from './hmac';
6
7
  export * from './sse';
7
8
  export * from './events';
package/dist/esm/index.js CHANGED
@@ -4,6 +4,7 @@ export * from './runtime';
4
4
  export * from './apis/index';
5
5
  export * from './models/index';
6
6
  export * from './client';
7
+ export * from './bound';
7
8
  export * from './hmac';
8
9
  export * from './sse';
9
10
  export * from './events';
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './runtime';
2
2
  export * from './apis/index';
3
3
  export * from './models/index';
4
4
  export * from './client';
5
+ export * from './bound';
5
6
  export * from './hmac';
6
7
  export * from './sse';
7
8
  export * from './events';
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ __exportStar(require("./runtime"), exports);
20
20
  __exportStar(require("./apis/index"), exports);
21
21
  __exportStar(require("./models/index"), exports);
22
22
  __exportStar(require("./client"), exports);
23
+ __exportStar(require("./bound"), exports);
23
24
  __exportStar(require("./hmac"), exports);
24
25
  __exportStar(require("./sse"), exports);
25
26
  __exportStar(require("./events"), exports);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@lingya-ai/agents-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Strongly typed server-side TypeScript SDK for Lingya Agents OpenAPI",
5
5
  "author": "Lingya AI",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/lingya-ai/lingya-agents-sdk-typescript.git"
9
+ "url": "git+https://github.com/lingya-ai/lingya-agents-sdk-typescript.git"
10
10
  },
11
11
  "homepage": "https://github.com/lingya-ai/lingya-agents-sdk-typescript#readme",
12
12
  "bugs": {
@@ -40,8 +40,10 @@
40
40
  "registry": "https://registry.npmjs.org"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsc && tsc -p tsconfig.esm.json",
44
- "check": "npm run build && npm run test && npm run audit:models && npm run package:smoke",
43
+ "generate:bound": "node scripts/generate-bound-api.mjs",
44
+ "build": "npm run generate:bound && tsc && tsc -p tsconfig.esm.json",
45
+ "check": "npm run build && npm run typecheck && npm run test && npm run audit:models && npm run package:smoke",
46
+ "typecheck": "tsc -p tsconfig.types.json",
45
47
  "test": "tsx --test test/*.test.ts",
46
48
  "test:live": "tsx --test test/live.test.ts",
47
49
  "audit:models": "node scripts/audit-models.mjs",