@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 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>;
@@ -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)}`)).conversations;
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)}`)).messages;
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), this.options.appId !== t && (this.answerAudience = this.loadAnswerAudience(this.options.appId), this.selectedSourceSnapshotId = null, this.currentThread = null, this.selectedPageKey = "", this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", this.renderPanel();
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">多轮问答</button>', e = this.root.querySelector("button"), e && (this.bindFloatingLauncher(e), e.addEventListener("click", () => this.open())));
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;
@@ -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)}`)).conversations;
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)}`)).messages;
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), this.options.appId !== t && (this.answerAudience = this.loadAnswerAudience(this.options.appId), this.selectedSourceSnapshotId = null, this.currentThread = null, this.selectedPageKey = "", this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", this.renderPanel();
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">多轮问答</button>', e = this.root.querySelector("button"), e && (this.bindFloatingLauncher(e), e.addEventListener("click", () => this.open())));
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
@@ -12,6 +12,7 @@ export interface PageOpsMountOptions {
12
12
  apiBase: string;
13
13
  appId: string;
14
14
  env: string;
15
+ ownerId?: string;
15
16
  uploader?: string;
16
17
  getPageContext?: () => PageOpsContext;
17
18
  container?: HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageops/sdk",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "PageOps embeddable frontend SDK",
5
5
  "type": "module",
6
6
  "main": "dist/pageops-sdk.umd.cjs",