@pageops/sdk 0.1.30 → 0.1.32
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 +2 -0
- package/dist/pageops-sdk.es.js +20 -8
- package/dist/pageops-sdk.umd.cjs +20 -8
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -13,5 +13,7 @@ export declare class PageOpsClient {
|
|
|
13
13
|
streamQuestion(threadId: string, question: string, userRole: string, signal?: AbortSignal): Promise<Response>;
|
|
14
14
|
private request;
|
|
15
15
|
private base;
|
|
16
|
+
private ownerId;
|
|
17
|
+
private ownerHeaders;
|
|
16
18
|
}
|
|
17
19
|
export declare function responseErrorMessage(response: Response, fallback: string): Promise<string>;
|
package/dist/pageops-sdk.es.js
CHANGED
|
@@ -25,24 +25,26 @@ class K {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
async listConversations() {
|
|
28
|
-
return (await this.request(`/conversations?app_id=${encodeURIComponent(this.options.appId)}
|
|
28
|
+
return this.ownerId() ? (await this.request(`/conversations?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() })).conversations : [];
|
|
29
29
|
}
|
|
30
30
|
async createConversation(e, t) {
|
|
31
31
|
return this.request("/conversations", {
|
|
32
32
|
method: "POST",
|
|
33
|
+
headers: this.ownerHeaders(),
|
|
33
34
|
body: JSON.stringify({ app_id: this.options.appId, context_session_id: e, title: t })
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
async deleteConversation(e) {
|
|
37
38
|
return this.request(`/conversations/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`, {
|
|
38
|
-
method: "DELETE"
|
|
39
|
+
method: "DELETE",
|
|
40
|
+
headers: this.ownerHeaders()
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
async listMessages(e) {
|
|
42
|
-
return (await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}
|
|
44
|
+
return (await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() })).messages;
|
|
43
45
|
}
|
|
44
46
|
async getAgentRun(e) {
|
|
45
|
-
return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}
|
|
47
|
+
return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() });
|
|
46
48
|
}
|
|
47
49
|
async listSources() {
|
|
48
50
|
return (await this.request(`/sources?project_id=${encodeURIComponent(this.options.appId)}`)).sources;
|
|
@@ -55,7 +57,7 @@ class K {
|
|
|
55
57
|
streamQuestion(e, t, s, r) {
|
|
56
58
|
return fetch(`${this.base()}/question/stream`, {
|
|
57
59
|
method: "POST",
|
|
58
|
-
headers: { "content-type": "application/json" },
|
|
60
|
+
headers: { "content-type": "application/json", ...this.ownerHeaders() },
|
|
59
61
|
body: JSON.stringify({ app_id: this.options.appId, thread_id: e, question: t, user_role: s }),
|
|
60
62
|
signal: r
|
|
61
63
|
});
|
|
@@ -72,6 +74,14 @@ class K {
|
|
|
72
74
|
const e = this.options.apiBase.replace(/\/$/, "");
|
|
73
75
|
return e.endsWith("/api") || e.endsWith("/dc/ai") ? e : `${e}/dc/ai`;
|
|
74
76
|
}
|
|
77
|
+
ownerId() {
|
|
78
|
+
return String(this.options.ownerId || "").trim();
|
|
79
|
+
}
|
|
80
|
+
ownerHeaders() {
|
|
81
|
+
const e = this.ownerId();
|
|
82
|
+
if (!e) throw new Error("登录信息加载中,请稍后再试。");
|
|
83
|
+
return { "X-PageOps-Owner-Id": e };
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
async function z(a, e) {
|
|
77
87
|
const t = await a.json().catch(() => null);
|
|
@@ -232,12 +242,14 @@ class V {
|
|
|
232
242
|
}
|
|
233
243
|
updateContext(e) {
|
|
234
244
|
if (!this.options) return;
|
|
235
|
-
const t = this.options.appId;
|
|
236
|
-
this.options = { ...this.options, ...e }, this.client = new K(this.options)
|
|
245
|
+
const t = this.options.appId, s = String(this.options.ownerId || "").trim();
|
|
246
|
+
this.options = { ...this.options, ...e }, this.client = new K(this.options);
|
|
247
|
+
const r = String(this.options.ownerId || "").trim(), n = this.options.appId !== t;
|
|
248
|
+
(n || r !== s) && (n && (this.answerAudience = this.loadAnswerAudience(this.options.appId), this.selectedSourceSnapshotId = null), this.currentThread = null, this.selectedPageKey = "", this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", this.panel && this.loadConversations(), this.renderPanel();
|
|
237
249
|
}
|
|
238
250
|
renderClosed() {
|
|
239
251
|
var e;
|
|
240
|
-
this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = '<button class="po-fab" type="button"
|
|
252
|
+
this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = '<button class="po-fab" type="button">AI 问答</button>', e = this.root.querySelector("button"), e && (this.bindFloatingLauncher(e), e.addEventListener("click", () => this.open())));
|
|
241
253
|
}
|
|
242
254
|
floatingStorageKey() {
|
|
243
255
|
var e;
|
package/dist/pageops-sdk.umd.cjs
CHANGED
|
@@ -25,24 +25,26 @@ class K {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
async listConversations() {
|
|
28
|
-
return (await this.request(`/conversations?app_id=${encodeURIComponent(this.options.appId)}
|
|
28
|
+
return this.ownerId() ? (await this.request(`/conversations?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() })).conversations : [];
|
|
29
29
|
}
|
|
30
30
|
async createConversation(e, t) {
|
|
31
31
|
return this.request("/conversations", {
|
|
32
32
|
method: "POST",
|
|
33
|
+
headers: this.ownerHeaders(),
|
|
33
34
|
body: JSON.stringify({ app_id: this.options.appId, context_session_id: e, title: t })
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
async deleteConversation(e) {
|
|
37
38
|
return this.request(`/conversations/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`, {
|
|
38
|
-
method: "DELETE"
|
|
39
|
+
method: "DELETE",
|
|
40
|
+
headers: this.ownerHeaders()
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
async listMessages(e) {
|
|
42
|
-
return (await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}
|
|
44
|
+
return (await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() })).messages;
|
|
43
45
|
}
|
|
44
46
|
async getAgentRun(e) {
|
|
45
|
-
return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}
|
|
47
|
+
return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`, { headers: this.ownerHeaders() });
|
|
46
48
|
}
|
|
47
49
|
async listSources() {
|
|
48
50
|
return (await this.request(`/sources?project_id=${encodeURIComponent(this.options.appId)}`)).sources;
|
|
@@ -55,7 +57,7 @@ class K {
|
|
|
55
57
|
streamQuestion(e, t, s, r) {
|
|
56
58
|
return fetch(`${this.base()}/question/stream`, {
|
|
57
59
|
method: "POST",
|
|
58
|
-
headers: { "content-type": "application/json" },
|
|
60
|
+
headers: { "content-type": "application/json", ...this.ownerHeaders() },
|
|
59
61
|
body: JSON.stringify({ app_id: this.options.appId, thread_id: e, question: t, user_role: s }),
|
|
60
62
|
signal: r
|
|
61
63
|
});
|
|
@@ -72,6 +74,14 @@ class K {
|
|
|
72
74
|
const e = this.options.apiBase.replace(/\/$/, "");
|
|
73
75
|
return e.endsWith("/api") || e.endsWith("/dc/ai") ? e : `${e}/dc/ai`;
|
|
74
76
|
}
|
|
77
|
+
ownerId() {
|
|
78
|
+
return String(this.options.ownerId || "").trim();
|
|
79
|
+
}
|
|
80
|
+
ownerHeaders() {
|
|
81
|
+
const e = this.ownerId();
|
|
82
|
+
if (!e) throw new Error("登录信息加载中,请稍后再试。");
|
|
83
|
+
return { "X-PageOps-Owner-Id": e };
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
async function z(a, e) {
|
|
77
87
|
const t = await a.json().catch(() => null);
|
|
@@ -232,12 +242,14 @@ class V {
|
|
|
232
242
|
}
|
|
233
243
|
updateContext(e) {
|
|
234
244
|
if (!this.options) return;
|
|
235
|
-
const t = this.options.appId;
|
|
236
|
-
this.options = { ...this.options, ...e }, this.client = new K(this.options)
|
|
245
|
+
const t = this.options.appId, s = String(this.options.ownerId || "").trim();
|
|
246
|
+
this.options = { ...this.options, ...e }, this.client = new K(this.options);
|
|
247
|
+
const r = String(this.options.ownerId || "").trim(), n = this.options.appId !== t;
|
|
248
|
+
(n || r !== s) && (n && (this.answerAudience = this.loadAnswerAudience(this.options.appId), this.selectedSourceSnapshotId = null), this.currentThread = null, this.selectedPageKey = "", this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", this.panel && this.loadConversations(), this.renderPanel();
|
|
237
249
|
}
|
|
238
250
|
renderClosed() {
|
|
239
251
|
var e;
|
|
240
|
-
this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = '<button class="po-fab" type="button"
|
|
252
|
+
this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = '<button class="po-fab" type="button">AI 问答</button>', e = this.root.querySelector("button"), e && (this.bindFloatingLauncher(e), e.addEventListener("click", () => this.open())));
|
|
241
253
|
}
|
|
242
254
|
floatingStorageKey() {
|
|
243
255
|
var e;
|
package/dist/types.d.ts
CHANGED