@pageops/sdk 0.1.34 → 0.1.36

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/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # PageOps SDK source baseline
2
+
3
+ This directory restores the maintainable SDK boundary from the verified public
4
+ `@pageops/sdk@0.1.34` artifacts. Version `0.1.35` added developer-gated source
5
+ controls and conversation presentation behavior directly to the SDK. Version
6
+ `0.1.36` renders the public execution timeline as thought/tool/read/search/data
7
+ activity, collapses it when answer text starts, and allows casual chat without
8
+ injecting page/source business context.
9
+
10
+ `src/index.js` is the readable ESM runtime baseline, `src/styles.css` preserves
11
+ the 0.1.34 styles, and `src/extensions.css` contains the new non-minified style
12
+ rules. `npm run build` synchronizes ESM, UMD, and CSS under `dist/` without
13
+ network access or a bundler. Declarations remain explicit under `src/*.d.ts`
14
+ and `dist/*.d.ts`.
15
+
16
+ The host supplies `developerAccessUrl`. The endpoint result controls only the
17
+ source-package UI. Failed/missing access checks hide those controls. It does not
18
+ replace authorization on source APIs.
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ declare class PageOpsSDKController {
23
23
  private sourceLoadError;
24
24
  private sourceUploading;
25
25
  private sourceRefreshTimer;
26
+ private developerAccess;
26
27
  private streaming;
27
28
  private asking;
28
29
  private waitingForFirstContent;
@@ -35,6 +36,7 @@ declare class PageOpsSDKController {
35
36
  private deletingThreadId;
36
37
  private streamFailure;
37
38
  private streamDone;
39
+ private activeQuestionStartedAt;
38
40
  private answerAudience;
39
41
  private floatingRatio;
40
42
  private floatingCleanup;
@@ -51,6 +53,7 @@ declare class PageOpsSDKController {
51
53
  private setFloatingPosition;
52
54
  private bindFloatingLauncher;
53
55
  private cleanupFloatingLauncher;
56
+ private loadDeveloperAccess;
54
57
  private ensureContext;
55
58
  private getPageContext;
56
59
  private answerAudienceStorageKey;
@@ -85,6 +88,7 @@ declare class PageOpsSDKController {
85
88
  private renderSourceUploader;
86
89
  private renderSourceItem;
87
90
  private renderSteps;
91
+ private renderThinkingProcess;
88
92
  private renderExecutionSteps;
89
93
  private bindPanelEvents;
90
94
  }
@@ -1 +1,142 @@
1
1
  .pageops-sdk{--po-text: #172033;--po-muted: #64748b;--po-border: #dbe5f5;--po-soft-border: #e2e8f0;--po-surface: #ffffff;--po-soft: #f8fafc;--po-panel: #fbfdff;--po-primary: #2563eb;--po-primary-dark: #1d4ed8;--po-shadow: 0 24px 70px rgb(15 23 42 / 18%);color:var(--po-text);font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.pageops-sdk *,.pageops-sdk *:before,.pageops-sdk *:after{box-sizing:border-box}.pageops-sdk button,.pageops-sdk input,.pageops-sdk textarea,.pageops-sdk select{font:inherit}.pageops-sdk button{cursor:pointer}.po-fab{position:fixed;top:var(--pageops-fab-top,50%);right:24px;bottom:auto;z-index:2147483000;border:0;border-radius:999px;padding:12px 18px;background:linear-gradient(135deg,#2563eb,#14b8a6);color:#fff;font-weight:800;box-shadow:0 18px 42px #2563eb47;transform:translateY(-50%);cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none}.po-fab.po-fab-dragging{cursor:grabbing}.po-panel{position:fixed;inset:40px;z-index:2147483000;display:grid;grid-template-columns:250px minmax(0,1fr) 340px;min-height:520px;overflow:hidden;border:1px solid var(--po-border);border-radius:24px;background:var(--po-surface);box-shadow:var(--po-shadow)}.po-sidebar{display:flex;min-width:0;min-height:0;flex-direction:column;gap:12px;overflow:hidden;border-right:1px solid #dbeafe;background:#eef5ff;padding:16px}.po-brand{display:flex;align-items:center;gap:10px}.po-brand strong,.po-brand span{display:block}.po-brand span{margin-top:2px;color:var(--po-muted);font-size:12px}.po-logo{width:34px;height:34px;flex:0 0 auto;border-radius:12px;background:linear-gradient(135deg,#5eead4,#2563eb)}.po-new,.po-composer button{border:0;border-radius:10px;background:var(--po-primary);color:#fff;font-weight:750}.po-new{width:100%;padding:10px 12px}.po-search,.po-composer textarea{width:100%;border:1px solid #cbd5e1;border-radius:10px;background:#fff;color:var(--po-text);outline:none}.po-search{padding:9px 10px}.po-thread-list{display:grid;align-content:start;gap:8px;min-height:0;overflow:auto}.po-thread-row{position:relative;display:grid;grid-template-columns:minmax(0,1fr) 32px;align-items:center;border:1px solid transparent;border-radius:10px}.po-thread-row.active{border-color:#bfdbfe;background:#fff}.po-thread{display:grid;gap:4px;width:100%;border:0;border-radius:10px;background:transparent;color:#334155;padding:9px 10px;text-align:left}.po-thread-row.active .po-thread{color:var(--po-text)}.po-thread span{color:#94a3b8;font-size:12px}.po-thread-delete{display:grid;width:28px;height:28px;place-items:center;border:0;border-radius:6px;background:transparent;color:#94a3b8;opacity:0}.po-thread-row:hover .po-thread-delete,.po-thread-row:focus-within .po-thread-delete{opacity:1}.po-thread-delete:hover{background:#fee2e2;color:#b91c1c}.po-thread-delete:disabled{cursor:not-allowed;opacity:.35}.po-trash-icon{position:relative;width:11px;height:12px;border:1.5px solid currentcolor;border-top:0;border-radius:0 0 2px 2px}.po-trash-icon:before{position:absolute;top:-4px;left:-2px;width:13px;border-top:1.5px solid currentcolor;content:""}.po-trash-icon:after{position:absolute;top:-6px;left:3px;width:4px;height:2px;border:1.5px solid currentcolor;border-bottom:0;border-radius:2px 2px 0 0;content:""}.po-conversation-error{margin:0;color:#b91c1c;font-size:12px}.po-chat{display:flex;min-width:0;min-height:0;flex-direction:column;background:linear-gradient(180deg,#fff,var(--po-panel));padding:22px 26px}.po-chat header,.po-trace header{display:flex;align-items:center;justify-content:space-between;gap:12px;border-bottom:1px solid var(--po-soft-border);padding-bottom:14px}.po-chat header p,.po-chat header h2,.po-trace header h2{margin:0}.po-chat header p,.po-chat header span{color:var(--po-muted);font-size:12px}.po-chat header h2,.po-trace header h2{font-size:20px;letter-spacing:0}.po-chat-title{min-width:0}.po-chat-title h2{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.po-audience{display:none;flex:0 0 auto;align-items:center;gap:8px}.po-audience>span{white-space:nowrap}.po-audience-options{display:grid;grid-template-columns:44px;height:32px;overflow:hidden;border:1px solid #cbd5e1;border-radius:6px;background:#f8fafc}.po-audience-options button{min-width:0;border:0;border-right:1px solid #e2e8f0;background:transparent;color:#475569;padding:0 8px;font-size:12px;font-weight:650}.po-audience-options button:last-child{border-right:0}.po-audience-options button[aria-pressed=true]{background:var(--po-primary);color:#fff}.po-audience-options button:disabled{cursor:not-allowed;opacity:.55}.po-messages{display:grid;align-content:start;gap:14px;min-height:0;flex:1;overflow:auto;padding:18px 4px 18px 0}.po-message{display:grid;max-width:82%;gap:6px;border:1px solid var(--po-soft-border);border-radius:14px;padding:11px 13px;line-height:1.55;white-space:pre-wrap;word-break:break-word}.po-message b{font-size:12px;opacity:.78}.po-message.user{justify-self:end;border-color:var(--po-primary);background:var(--po-primary);color:#fff}.po-message.assistant{justify-self:start;background:var(--po-soft)}.po-message.run-selected{border-color:#93c5fd;box-shadow:0 0 0 2px #3b82f614}.po-answer-meta{display:flex;min-width:0;align-items:center;flex-wrap:wrap;gap:6px 10px;border-top:1px solid var(--po-soft-border);margin-top:5px;padding-top:8px;color:var(--po-muted);font-size:11px}.po-answer-meta.selected{color:#1d4ed8}.po-run-id{display:flex;min-width:0;max-width:100%;align-items:center;gap:5px}.po-run-id code{display:block;max-width:148px;overflow:hidden;background:transparent;color:inherit;padding:0;text-overflow:ellipsis;white-space:nowrap}.po-answer-meta button{border:0;background:transparent;color:var(--po-primary-dark);padding:2px 0;font-size:11px;font-weight:700}.po-answer-meta button:hover{text-decoration:underline}.po-message.streaming{border-color:#bfdbfe;background:#eff6ff}.po-message.answer-error{border-color:#fecaca;background:#fff7f7;color:#991b1b}.po-message.answer-error>strong{color:#7f1d1d}.po-stream-stopped{justify-self:start;color:var(--po-muted);font-size:12px}.po-ai-waiting{display:inline-flex;align-items:center;gap:9px;min-height:24px;color:#475569}.po-ai-spinner{width:16px;height:16px;flex:0 0 auto;border:2px solid #bfdbfe;border-top-color:var(--po-primary);border-radius:50%;animation:po-ai-spin .7s linear infinite}.po-typing-cursor{display:inline-block;width:2px;height:1em;margin-left:3px;background:var(--po-primary);vertical-align:-.12em;animation:po-typing-cursor .8s steps(1,end) infinite}@keyframes po-ai-spin{to{transform:rotate(360deg)}}@keyframes po-typing-cursor{50%{opacity:0}}.po-message code{border-radius:5px;background:#eaf0ff;color:var(--po-primary-dark);padding:1px 5px}.po-message pre{max-width:100%;margin:8px 0;overflow:auto;border:1px solid var(--po-border);border-radius:6px;background:#f8fafc;padding:10px 12px;white-space:pre}.po-message pre code{border-radius:0;background:transparent;color:#1f2937;padding:0}.po-message h2,.po-message h3,.po-message h4,.po-message p{margin:8px 0}.po-message table{width:100%;margin:12px 0;border-collapse:collapse;border-radius:10px;font-size:14px}.po-message th,.po-message td{border:1px solid var(--po-border);padding:8px 10px;text-align:left;vertical-align:top}.po-message th{background:#eef5ff;color:#334155;font-weight:800}.po-composer{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:end;gap:10px;border-top:1px solid var(--po-soft-border);padding-top:12px}.po-composer textarea{min-height:88px;resize:vertical;padding:10px}.po-composer button{min-height:44px;padding:0 16px}.po-composer .po-stop{display:grid;width:44px;height:44px;min-height:44px;place-items:center;border:1px solid #fecaca;background:#fff;color:#dc2626;padding:0}.po-stop span{width:12px;height:12px;border-radius:2px;background:currentcolor}.po-trace{display:flex;min-height:0;flex-direction:column;border-left:1px solid var(--po-soft-border);background:#fafbff}.po-trace header{padding:18px}.po-trace header button{width:32px;height:32px;border:1px solid #cbd5e1;border-radius:10px;background:#fff;color:#334155;font-size:20px;line-height:1}.po-trace section{display:grid;align-content:start;gap:12px;min-height:0;overflow:auto;padding:16px}.po-steps{display:grid;gap:12px}.po-source-uploader{display:grid;gap:8px;padding-bottom:4px}.po-source-uploader p{margin:0;color:var(--po-muted);font-size:12px;line-height:1.5}.po-upload-button{display:inline-flex;justify-content:center;border:1px solid #bfdbfe;border-radius:6px;background:#eff6ff;color:var(--po-primary-dark);padding:8px 10px;font-weight:750;cursor:pointer}.po-source-reference{display:grid;grid-template-columns:1fr 1fr;overflow:hidden;border:1px solid #cbd5e1;border-radius:6px;background:#fff}.po-source-reference label{display:flex;align-items:center;justify-content:center;gap:6px;min-height:32px;color:#475569;font-size:12px;font-weight:700;cursor:pointer}.po-source-reference label+label{border-left:1px solid #cbd5e1}.po-source-reference label:has(input:checked){background:#eef2ff;color:var(--po-primary-dark)}.po-source-reference input{accent-color:var(--po-primary)}.po-source-reference-value,.po-source-remark{box-sizing:border-box;width:100%;border:1px solid #cbd5e1;border-radius:6px;background:#fff;color:var(--po-text);padding:8px 9px;font:inherit;font-size:12px;outline:none}.po-source-reference-value:focus,.po-source-remark:focus{border-color:var(--po-primary);box-shadow:0 0 0 2px #4f46e51f}.po-source-remark{min-height:54px;resize:vertical}.po-upload-button input{display:none}.po-upload-status{color:#166534!important}.po-upload-progress{height:7px;overflow:hidden;border-radius:999px;background:#dbeafe}.po-upload-progress span{display:block;height:100%;border-radius:inherit;background:linear-gradient(90deg,#2563eb,#14b8a6);transition:width .2s ease}.po-upload-empty{color:#92400e!important}.po-source-selector{display:grid;gap:5px;color:var(--po-muted);font-size:12px;font-weight:700}.po-source-selector select{width:100%;border:1px solid #cbd5e1;border-radius:6px;background:#fff;color:var(--po-text);padding:7px 8px;font-size:12px;outline:none}.po-source-selector select:focus{border-color:var(--po-primary);box-shadow:0 0 0 2px #4f46e51f}.po-source-selector select:disabled{cursor:not-allowed;opacity:.62}.po-source-list{display:grid;gap:6px}.po-source-item{display:grid;gap:3px;border:1px solid #dbeafe;border-radius:6px;background:#f8fbff;padding:8px}.po-source-item.selected{border-color:#93c5fd;background:#eff6ff;box-shadow:0 0 0 1px #3b82f61f}.po-source-item strong{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.po-source-item span{color:var(--po-muted);font-size:12px}.po-composer textarea:disabled,.po-composer button:disabled{cursor:not-allowed;opacity:.62}.po-upload-error{color:#b91c1c!important}.po-step{border:1px solid var(--po-soft-border);border-radius:8px;background:#fff;padding:12px}.po-step.running{border-color:#bfdbfe;background:#eff6ff}.po-step.completed{border-color:#bbf7d0}.po-step.failed{border-color:#fecaca;background:#fff1f2}.po-step.cancelled{border-color:#cbd5e1;background:#f8fafc}.po-step summary{display:grid;grid-template-columns:9px minmax(0,1fr) auto;align-items:start;gap:9px;cursor:pointer}.po-step summary::marker{display:none;content:""}.po-step[data-static] summary{cursor:default}.po-step-dot{width:8px;height:8px;margin-top:5px;border:2px solid #94a3b8;border-radius:50%;background:#fff}.po-step.running .po-step-dot{border-color:#2563eb;animation:po-step-pulse 1.2s ease-in-out infinite}.po-step.completed .po-step-dot{border-color:#16a34a;background:#16a34a}.po-step.failed .po-step-dot{border-color:#dc2626;background:#dc2626}.po-step-copy{display:grid;min-width:0;gap:4px}.po-step-copy strong{font-size:13px}.po-step-copy small{color:var(--po-muted);font-size:12px;font-weight:500;line-height:1.45}.po-step-status{color:var(--po-muted);font-size:11px;white-space:nowrap}.po-step-metrics{display:flex;flex-wrap:wrap;gap:6px;margin:10px 0 0}.po-step-metrics span{border:1px solid #dbeafe;border-radius:4px;background:#f8fbff;color:#475569;padding:2px 6px;font-size:11px}.po-step-details{display:grid;gap:8px;margin:10px 0 0 18px;border-top:1px solid var(--po-soft-border);padding-top:9px}.po-step-details div{display:grid;gap:3px}.po-step-details span{color:var(--po-muted);font-size:11px}.po-step-details p{overflow-wrap:anywhere;margin:0;color:#334155;font-size:12px;line-height:1.5;white-space:pre-wrap}.po-trace-state{display:flex;align-items:center;gap:8px;border:1px solid var(--po-soft-border);border-radius:8px;background:#fff;color:var(--po-muted);padding:12px;font-size:12px}.po-trace-state.failed{border-color:#fecaca;color:#b91c1c}@keyframes po-step-pulse{50%{opacity:.35}}@media(max-width:900px){.po-panel{inset:12px;grid-template-columns:1fr;overflow:auto}.po-sidebar,.po-trace{min-height:220px;border:0}.po-chat{min-height:520px}.po-chat header{align-items:flex-start;flex-wrap:wrap}.po-audience{width:100%;justify-content:space-between}.po-message{max-width:94%}}@media(max-width:600px){.po-fab{right:12px}}@media(prefers-reduced-motion:reduce){.po-ai-spinner,.po-step-dot,.po-typing-cursor{animation:none}}
2
+ .po-thinking-process {
3
+ margin: 14px 0 4px;
4
+ border-top: 1px solid #e2e8f0;
5
+ border-bottom: 1px solid #e2e8f0;
6
+ color: #334155;
7
+ }
8
+
9
+ .po-thinking-process > summary {
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: space-between;
13
+ gap: 12px;
14
+ min-height: 40px;
15
+ padding: 0 2px;
16
+ cursor: pointer;
17
+ font-size: 12px;
18
+ }
19
+
20
+ .po-thinking-process > summary strong {
21
+ color: #64748b;
22
+ font-size: 13px;
23
+ font-weight: 700;
24
+ }
25
+
26
+ .po-thinking-process > summary span {
27
+ color: #7b8798;
28
+ font-size: 11px;
29
+ }
30
+
31
+ .po-thinking-content {
32
+ display: grid;
33
+ gap: 10px;
34
+ padding: 12px 2px 14px;
35
+ }
36
+
37
+ .po-thinking-note,
38
+ .po-thinking-activity {
39
+ display: grid;
40
+ grid-template-columns: 20px minmax(0, 1fr);
41
+ gap: 8px;
42
+ align-items: start;
43
+ }
44
+
45
+ .po-thinking-note {
46
+ padding-bottom: 4px;
47
+ color: #1f2937;
48
+ }
49
+
50
+ .po-thinking-note strong,
51
+ .po-thinking-activity strong {
52
+ display: block;
53
+ color: #475569;
54
+ font-size: 12px;
55
+ font-weight: 700;
56
+ }
57
+
58
+ .po-thinking-note p {
59
+ margin: 4px 0 0;
60
+ color: #334155;
61
+ font-size: 13px;
62
+ line-height: 1.65;
63
+ }
64
+
65
+ .po-thinking-activity-copy > span:not(.po-thinking-metrics) {
66
+ display: block;
67
+ margin-top: 2px;
68
+ color: #7b8798;
69
+ font-size: 12px;
70
+ line-height: 1.45;
71
+ }
72
+
73
+ .po-thinking-icon {
74
+ width: 17px;
75
+ height: 17px;
76
+ margin-top: 1px;
77
+ fill: none;
78
+ stroke: #8491a5;
79
+ stroke-linecap: round;
80
+ stroke-linejoin: round;
81
+ stroke-width: 1.7;
82
+ }
83
+
84
+ .po-thinking-activity.running .po-thinking-icon,
85
+ .po-thinking-note.running .po-thinking-icon {
86
+ stroke: #2563eb;
87
+ }
88
+
89
+ .po-thinking-activity.failed .po-thinking-icon,
90
+ .po-thinking-note.failed .po-thinking-icon {
91
+ stroke: #b91c1c;
92
+ }
93
+
94
+ .po-thinking-metrics {
95
+ display: block;
96
+ margin-top: 3px;
97
+ color: #94a3b8;
98
+ font-size: 11px;
99
+ }
100
+
101
+ .po-thinking-detail {
102
+ display: flex;
103
+ flex-wrap: wrap;
104
+ gap: 4px 7px;
105
+ margin-top: 5px;
106
+ color: #94a3b8;
107
+ font-size: 11px;
108
+ }
109
+
110
+ .po-thinking-detail code {
111
+ overflow: hidden;
112
+ max-width: 100%;
113
+ padding: 0;
114
+ background: transparent;
115
+ color: #64748b;
116
+ text-overflow: ellipsis;
117
+ white-space: nowrap;
118
+ }
119
+
120
+ .po-thinking-state {
121
+ display: flex;
122
+ align-items: center;
123
+ gap: 8px;
124
+ color: #64748b;
125
+ font-size: 12px;
126
+ }
127
+
128
+ .po-thinking-state.failed {
129
+ color: #b91c1c;
130
+ }
131
+
132
+ .po-message-time {
133
+ color: inherit;
134
+ font-size: 11px;
135
+ font-variant-numeric: tabular-nums;
136
+ line-height: 1.3;
137
+ opacity: .62;
138
+ }
139
+
140
+ .po-message.user > div {
141
+ margin-top: 1px;
142
+ }
@@ -205,6 +205,7 @@ class V {
205
205
  i(this, "sourceLoadError", "");
206
206
  i(this, "sourceUploading", !1);
207
207
  i(this, "sourceRefreshTimer", null);
208
+ i(this, "developerAccess", !1);
208
209
  i(this, "streaming", "");
209
210
  i(this, "asking", !1);
210
211
  i(this, "waitingForFirstContent", !1);
@@ -217,6 +218,7 @@ class V {
217
218
  i(this, "deletingThreadId", "");
218
219
  i(this, "streamFailure", "");
219
220
  i(this, "streamDone", null);
221
+ i(this, "activeQuestionStartedAt", "");
220
222
  i(this, "answerAudience", "developer");
221
223
  i(this, "floatingRatio", 0.5);
222
224
  i(this, "floatingCleanup", null);
@@ -230,10 +232,10 @@ class V {
230
232
  }
231
233
  unmount() {
232
234
  var e;
233
- this.cleanupFloatingLauncher(), this.stopSourceRefresh(), this.cancelActiveAnswer(!1), this.resetAnswerState(), (e = this.root) == null || e.remove(), this.root = null, this.panel = null, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoading = !1, this.runLoadError = "", this.clearCopyFeedback(), this.sourceSnapshots = [], this.selectedSourceSnapshotId = null, this.sourceUploadStatus = "", this.sourceUploadProgress = null, this.sourceUploadError = "", this.sourceLoadError = "", this.sourceUploading = !1, this.answerAudience = "developer";
235
+ this.cleanupFloatingLauncher(), this.stopSourceRefresh(), this.cancelActiveAnswer(!1), this.resetAnswerState(), (e = this.root) == null || e.remove(), this.root = null, this.panel = null, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoading = !1, this.runLoadError = "", this.clearCopyFeedback(), this.sourceSnapshots = [], this.selectedSourceSnapshotId = null, this.sourceUploadStatus = "", this.sourceUploadProgress = null, this.sourceUploadError = "", this.sourceLoadError = "", this.sourceUploading = !1, this.developerAccess = !1, this.activeQuestionStartedAt = "", this.answerAudience = "developer";
234
236
  }
235
237
  open() {
236
- this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = "", this.panel = document.createElement("div"), this.panel.className = "po-panel", this.root.appendChild(this.panel), this.loadSources(), this.loadConversations(), this.renderPanel());
238
+ this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = "", this.panel = document.createElement("div"), this.panel.className = "po-panel", this.root.appendChild(this.panel), this.loadDeveloperAccess(), this.loadSources(), this.loadConversations(), this.renderPanel());
237
239
  }
238
240
  close() {
239
241
  this.stopSourceRefresh(), this.cancelActiveAnswer(!1), this.renderClosed();
@@ -243,7 +245,7 @@ class V {
243
245
  const t = this.options.appId, s = String(this.options.ownerId || "").trim();
244
246
  this.options = { ...this.options, ...e }, this.client = new K(this.options);
245
247
  const r = String(this.options.ownerId || "").trim(), n = this.options.appId !== t;
246
- (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();
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 = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
247
249
  }
248
250
  renderClosed() {
249
251
  var e;
@@ -300,6 +302,19 @@ class V {
300
302
  cleanupFloatingLauncher() {
301
303
  this.floatingCleanup && (this.floatingCleanup(), this.floatingCleanup = null), this.root && this.root.style.removeProperty("--pageops-fab-top");
302
304
  }
305
+ async loadDeveloperAccess() {
306
+ var e, t;
307
+ this.developerAccess = !1, this.renderPanel();
308
+ const s = String(((e = this.options) == null ? void 0 : e.developerAccessUrl) || "").trim();
309
+ if (!s) return;
310
+ try {
311
+ const r = await fetch(s, { credentials: "same-origin", headers: { Accept: "application/json" } }), n = await r.json().catch(() => null);
312
+ this.developerAccess = !!(r.ok && (n == null ? void 0 : n.code) === 1e4 && ((t = n == null ? void 0 : n.data) == null ? void 0 : t.developer) === !0);
313
+ } catch (r) {
314
+ this.developerAccess = !1;
315
+ }
316
+ this.renderPanel();
317
+ }
303
318
  async ensureContext() {
304
319
  if (!this.client || !this.options) throw new Error("PageOps SDK 未初始化");
305
320
  const e = this.getPageContext(), t = this.getPageContextKey(e);
@@ -377,11 +392,11 @@ class V {
377
392
  async loadConversations() {
378
393
  this.client && (this.conversations = await this.client.listConversations(), this.renderPanel());
379
394
  }
380
- async newConversation() {
395
+ async newConversation(e = "") {
381
396
  var s;
382
397
  if (!this.client) return;
383
- const e = await this.ensureContext(), t = (s = e.menu_path) != null && s.length ? e.menu_path.join(" / ") : e.route || document.title || "新的问答";
384
- this.currentThread = await this.client.createConversation(e.id, t), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
398
+ const t = await this.ensureContext(), r = e ? conversationTitle(t, e) : (s = t.menu_path) != null && s.length ? t.menu_path.join(" / ") : t.route || document.title || "新的问答";
399
+ this.currentThread = await this.client.createConversation(t.id, r), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
385
400
  }
386
401
  async selectThread(e) {
387
402
  if (!this.client) return;
@@ -428,13 +443,13 @@ class V {
428
443
  this.sourceUploadError = t, this.renderPanel();
429
444
  return;
430
445
  }
431
- this.resetAnswerState();
446
+ this.resetAnswerState(), this.activeQuestionStartedAt = (/* @__PURE__ */ new Date()).toISOString();
432
447
  const s = ++this.activeRunId, r = new AbortController();
433
448
  this.abortController = r, this.stoppedRunId = -1, this.asking = !0, this.waitingForFirstContent = !0, this.renderPanel();
434
449
  try {
435
450
  const n = this.getPageContextKey(this.getPageContext());
436
- if (this.currentThread && this.selectedPageKey && this.selectedPageKey !== n && (this.currentThread = null), this.currentThread || await this.newConversation(), !this.currentThread) throw new Error("无法创建问答会话,请稍后重试。");
437
- this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {} }), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
451
+ if (this.currentThread && this.selectedPageKey && this.selectedPageKey !== n && (this.currentThread = null), this.currentThread || await this.newConversation(e), !this.currentThread) throw new Error("无法创建问答会话,请稍后重试。");
452
+ this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {}, created_at: this.activeQuestionStartedAt }), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
438
453
  const c = await this.client.streamQuestion(this.currentThread.id, e, this.answerAudience, r.signal);
439
454
  if (!c.ok) throw new Error(await z(c, "服务暂时无法回答,请稍后重试。"));
440
455
  if (!c.body) throw new Error("服务未返回有效的流式响应,请稍后重试。");
@@ -485,6 +500,12 @@ class V {
485
500
  return;
486
501
  }
487
502
  e.innerHTML = R(this.streaming);
503
+ const thinking = e.closest(".po-message") == null ? void 0 : e.closest(".po-message").querySelector(".po-thinking-process");
504
+ if (thinking) {
505
+ thinking.open = !1;
506
+ const status = thinking.querySelector("summary span");
507
+ status && (status.textContent = "已思考完成");
508
+ }
488
509
  const t = (r = this.panel) == null ? void 0 : r.querySelector(".po-messages");
489
510
  t && (t.scrollTop = t.scrollHeight);
490
511
  }
@@ -549,7 +570,7 @@ class V {
549
570
  return ["pending", "running"].includes(this.latestAnalysisStatus());
550
571
  }
551
572
  questionUnavailableReason() {
552
- return this.sourceLoadError && !this.sourceSnapshots.length ? "暂时无法读取项目共享代码包,请检查 PageOps 服务连接。" : this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
573
+ return this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "";
553
574
  }
554
575
  scheduleSourceRefresh() {
555
576
  this.stopSourceRefresh(), !(!this.sourceLoadError && !this.isProjectMemoryUpdating()) && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
@@ -560,7 +581,7 @@ class V {
560
581
  renderPanel(e = this.asking, t = !1) {
561
582
  var g;
562
583
  if (!this.panel) return;
563
- const s = (g = this.panel.querySelector(".po-messages")) == null ? void 0 : g.scrollTop, r = this.questionUnavailableReason(), n = r || (this.asking ? "回答生成中,请稍候" : "请输入页面分析问题,Enter 发送,Shift + Enter 换行"), c = !!(r || this.asking), p = r ? '<button type="submit" disabled>暂不可提问</button>' : this.asking ? '<button class="po-stop" type="button" data-action="stop-answer" aria-label="停止输出" title="停止输出"><span aria-hidden="true"></span></button>' : '<button type="submit">发送</button>', m = C.map((o) => `
584
+ const s = (g = this.panel.querySelector(".po-messages")) == null ? void 0 : g.scrollTop, r = this.questionUnavailableReason(), n = r || (this.asking ? "回答生成中,请稍候" : this.sourceSnapshots.length ? "请输入页面分析问题,Enter 发送,Shift + Enter 换行" : "可直接闲聊;业务问题需先上传代码包"), c = !!(r || this.asking), p = r ? '<button type="submit" disabled>暂不可提问</button>' : this.asking ? '<button class="po-stop" type="button" data-action="stop-answer" aria-label="停止输出" title="停止输出"><span aria-hidden="true"></span></button>' : '<button type="submit">发送</button>', m = C.map((o) => `
564
585
  <button type="button" data-audience="${o.value}" aria-pressed="${o.value === this.answerAudience}" ${this.asking ? "disabled" : ""}>${o.label}</button>
565
586
  `).join("");
566
587
  if (this.panel.innerHTML = `
@@ -581,7 +602,7 @@ class V {
581
602
  }).join("")}</div>
582
603
  </aside>
583
604
  <main class="po-chat">
584
- <header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread ? l(this.currentThread.title) : "未选择问答"}</h2></div><div class="po-audience"><span>回答角色</span><div class="po-audience-options" role="group" aria-label="回答角色">${m}</div></div></header>
605
+ <header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread ? l(this.currentThread.title) : "输入问题即可开始"}</h2></div><div class="po-audience"><span>回答角色</span><div class="po-audience-options" role="group" aria-label="回答角色">${m}</div></div></header>
585
606
  <section class="po-messages">
586
607
  ${this.messages.map((o) => this.renderMessage(o)).join("")}
587
608
  ${this.renderAnswerState()}
@@ -602,7 +623,7 @@ class V {
602
623
  }
603
624
  }
604
625
  renderAnswerState() {
605
- const e = this.asking && this.waitingForFirstContent ? '<article class="po-message assistant waiting" role="status" aria-live="polite"><b>PageOps 分析</b><div class="po-ai-waiting"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在理解问题并检索证据</span></div></article>' : "", t = this.streaming ? `<article class="po-message assistant streaming"><b>PageOps 分析</b><div><span data-streaming-content>${R(this.streaming)}</span>${this.asking ? '<span class="po-typing-cursor" aria-hidden="true"></span>' : ""}</div></article>` : "", s = this.answerError ? `<article class="po-message assistant answer-error" role="alert"><b>PageOps 分析</b><strong>本次回答失败</strong><div>${l(this.answerError)}</div></article>` : "", r = this.answerStopped ? '<div class="po-stream-stopped" role="status">已停止输出</div>' : "";
626
+ const n = messageTime(this.activeQuestionStartedAt), c = this.renderThinkingProcess(), e = this.asking && this.waitingForFirstContent ? `<article class="po-message assistant waiting" role="status" aria-live="polite">${n}<b>PageOps 分析</b><div class="po-ai-waiting"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在理解问题并检索证据</span></div>${c}</article>` : "", t = this.streaming ? `<article class="po-message assistant streaming">${n}<b>PageOps 分析</b><div><span data-streaming-content>${R(this.streaming)}</span>${this.asking ? '<span class="po-typing-cursor" aria-hidden="true"></span>' : ""}</div>${c}</article>` : "", s = this.answerError ? `<article class="po-message assistant answer-error" role="alert">${n}<b>PageOps 分析</b><strong>本次回答失败</strong><div>${l(this.answerError)}</div></article>` : "", r = this.answerStopped ? '<div class="po-stream-stopped" role="status">已停止输出</div>' : "";
606
627
  return `${e}${t}${r}${s}`;
607
628
  }
608
629
  renderMessage(e) {
@@ -610,14 +631,15 @@ class V {
610
631
  <span class="po-run-id" title="${l(t)}">问答流水号 <code>${l(t)}</code></span>
611
632
  <button type="button" data-copy-run="${l(t)}">${r ? "已复制" : n ? "复制失败" : "复制流水号"}</button>
612
633
  <button type="button" data-view-run="${l(t)}" aria-pressed="${s}">${s ? "正在查看" : "查看执行过程"}</button>
613
- </footer>` : "";
634
+ </footer>` : "", p = messageTime(e.created_at), m = e.role === "user" ? "" : "<b>PageOps 分析</b>", g = e.role === "assistant" && s ? this.renderThinkingProcess() : "";
614
635
  return `<article class="po-message ${e.role} ${s ? "run-selected" : ""}" data-message="${l(e.id)}">
615
- <b>${e.role === "user" ? "你" : "PageOps 分析"}</b>
636
+ ${p}${m}
616
637
  <div>${e.role === "assistant" ? R(e.content) : l(e.content)}</div>
617
- ${c}
638
+ ${g}${c}
618
639
  </article>`;
619
640
  }
620
641
  renderSourceUploader() {
642
+ if (!this.developerAccess) return "";
621
643
  const e = this.sourceLoadError ? "暂时无法读取项目共享代码包,连接恢复后将自动重试。" : "当前项目暂无代码包,请先上传后再提问。";
622
644
  const t = typeof this.sourceUploadProgress == "number" ? Math.max(0, Math.min(100, Math.round(this.sourceUploadProgress))) : 0;
623
645
  return `
@@ -666,10 +688,25 @@ class V {
666
688
  </details>`;
667
689
  }).join("");
668
690
  }
691
+ renderThinkingProcess() {
692
+ if (!this.asking && !this.steps.length && !this.runLoading && !this.runLoadError) return "";
693
+ const e = this.asking && !this.streaming, t = this.asking && !this.streaming ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成", s = thinkingDuration(this.steps, this.activeQuestionStartedAt);
694
+ return `<details class="po-thinking-process" ${e ? "open" : ""}><summary><strong>${s ? `用时 ${l(s)}` : "思考过程"}</strong><span>${t}</span></summary><div class="po-thinking-content">${this.renderThinkingSteps()}</div></details>`;
695
+ }
696
+ renderThinkingSteps() {
697
+ if (this.runLoading) return '<div class="po-thinking-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复思考过程</span></div>';
698
+ if (this.runLoadError) return `<div class="po-thinking-state failed">${l(this.runLoadError)}</div>`;
699
+ const e = this.steps.length ? this.steps : [{ id: "idle", kind: "thinking", title: "理解问题", status: "running", summary: "正在判断问题并规划需要核对的信息。" }];
700
+ return e.map((t) => {
701
+ const s = String(t.kind || (String(t.id || "").startsWith("model-turn-") ? "thinking" : "status")), r = thinkingIcon(s), n = (t.metrics || []).length ? `<span class="po-thinking-metrics">${t.metrics.map((c) => l(c)).join(" · ")}</span>` : "", p = (t.details || []).map((c) => `<div class="po-thinking-detail"><span>${l(c.label)}</span>${String(c.value || "").split("\n").filter(Boolean).map((m) => `<code>${l(m)}</code>`).join("")}</div>`).join("");
702
+ if (s === "thinking") return `<div class="po-thinking-note ${t.status}">${r}<div><strong>${l(t.title)}</strong><p>${l(t.summary || "")}</p>${n}</div></div>`;
703
+ return `<div class="po-thinking-activity ${t.status}">${r}<div class="po-thinking-activity-copy"><strong>${l(t.title)}</strong><span>${l(t.summary || "")}</span>${n}${p}</div></div>`;
704
+ }).join("");
705
+ }
669
706
  renderExecutionSteps(e = !1) {
670
707
  var s, r;
671
708
  const t = (s = this.panel) == null ? void 0 : s.querySelector(".po-steps");
672
- if (t && (t.innerHTML = this.renderSteps(), e)) {
709
+ if (t && (t.innerHTML = this.renderSteps(), this.panel == null || this.panel.querySelectorAll(".po-thinking-content").forEach((n) => n.innerHTML = this.renderThinkingSteps()), e)) {
673
710
  const n = (r = this.panel) == null ? void 0 : r.querySelector(".po-trace > section");
674
711
  n && (n.scrollTop = n.scrollHeight);
675
712
  }
@@ -740,6 +777,40 @@ function M(a) {
740
777
  const e = (t = a.metadata_json) == null ? void 0 : t.agent_run_id;
741
778
  return typeof e == "number" ? String(e) : typeof e == "string" ? e : "";
742
779
  }
780
+ function conversationTitle(a, e) {
781
+ var s;
782
+ const t = (s = a.menu_path) != null && s.length ? String(a.menu_path[a.menu_path.length - 1]) : String(a.title || a.route || document.title || "新的问答").split(" - ")[0], r = String(e || "").replace(/\s+/g, " ").replace(/[??!!。]+$/, "").trim(), n = r.length > 28 ? `${r.slice(0, 28)}...` : r;
783
+ return [t.trim(), n].filter(Boolean).join(" · ");
784
+ }
785
+ function formatFullTimestamp(a) {
786
+ const e = new Date(a);
787
+ if (Number.isNaN(e.getTime())) return "";
788
+ const t = new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Shanghai", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" }).formatToParts(e).reduce((s, r) => (s[r.type] = r.value, s), {});
789
+ return `${t.year}-${t.month}-${t.day} ${t.hour}:${t.minute}:${t.second}`;
790
+ }
791
+ function messageTime(a) {
792
+ const e = formatFullTimestamp(a);
793
+ return e ? `<time class="po-message-time" datetime="${l(a)}">${e}</time>` : "";
794
+ }
795
+ function thinkingDuration(a, e) {
796
+ const t = [...a].reverse().flatMap((s) => s.metrics || []).find((s) => /^耗时\s/.test(s));
797
+ if (t) return t.replace(/^耗时\s*/, "");
798
+ if (!e) return "";
799
+ const s = Date.now() - new Date(e).getTime();
800
+ if (!Number.isFinite(s) || s < 0) return "";
801
+ const r = Math.floor(s / 1e3), n = Math.floor(r / 60), c = r % 60;
802
+ return n ? `${n}m ${c}s` : `${c}s`;
803
+ }
804
+ function thinkingIcon(a) {
805
+ const e = {
806
+ read: '<path d="M4 5.5A2.5 2.5 0 0 1 6.5 3H11v14H6.5A2.5 2.5 0 0 0 4 19.5z"/><path d="M20 5.5A2.5 2.5 0 0 0 17.5 3H13v14h4.5a2.5 2.5 0 0 1 2.5 2.5z"/>',
807
+ search: '<circle cx="11" cy="11" r="6"/><path d="m16 16 4 4"/>',
808
+ data: '<ellipse cx="12" cy="5" rx="7" ry="3"/><path d="M5 5v6c0 1.7 3.1 3 7 3s7-1.3 7-3V5"/><path d="M5 11v6c0 1.7 3.1 3 7 3s7-1.3 7-3v-6"/>',
809
+ tool: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/>',
810
+ thinking: '<path d="M9 18h6M10 22h4"/><path d="M8.5 14.5A6 6 0 1 1 15.5 14.5c-.9.7-1.5 1.5-1.5 2.5h-4c0-1-.6-1.8-1.5-2.5Z"/>'
811
+ }[a] || '<circle cx="12" cy="12" r="8"/><path d="m9 12 2 2 4-4"/>';
812
+ return `<svg class="po-thinking-icon" viewBox="0 0 24 24" aria-hidden="true">${e}</svg>`;
813
+ }
743
814
  function O(a) {
744
815
  return new Intl.DateTimeFormat("zh-CN", {
745
816
  timeZone: "Asia/Shanghai",
@@ -1,5 +1,5 @@
1
1
  (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.PageOpsSDK={}));})(this,(function(exports){'use strict';var W = Object.defineProperty;
2
- var H = (a, e, t) => e in a ? W(a, e, { enumerable: true, configurable: true, writable: true, value: t }) : a[e] = t;
2
+ var H = (a, e, t) => e in a ? W(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
3
  var i = (a, e, t) => H(a, typeof e != "symbol" ? e + "" : e, t);
4
4
  const UPLOAD_MAX_BYTES = 500 * 1024 * 1024;
5
5
  class K {
@@ -136,7 +136,7 @@ async function J(a, e) {
136
136
  r += s.decode();
137
137
  break;
138
138
  }
139
- r += s.decode(p, { stream: true });
139
+ r += s.decode(p, { stream: !0 });
140
140
  const m = r.split(/\r?\n\r?\n/);
141
141
  r = (n = m.pop()) != null ? n : "";
142
142
  for (const g of m) j(g, e);
@@ -193,7 +193,7 @@ class V {
193
193
  i(this, "messages", []);
194
194
  i(this, "steps", []);
195
195
  i(this, "selectedAgentRunId", "");
196
- i(this, "runLoading", false);
196
+ i(this, "runLoading", !1);
197
197
  i(this, "runLoadError", "");
198
198
  i(this, "copiedAgentRunId", "");
199
199
  i(this, "copyFeedbackTimer", null);
@@ -203,20 +203,22 @@ class V {
203
203
  i(this, "sourceUploadProgress", null);
204
204
  i(this, "sourceUploadError", "");
205
205
  i(this, "sourceLoadError", "");
206
- i(this, "sourceUploading", false);
206
+ i(this, "sourceUploading", !1);
207
207
  i(this, "sourceRefreshTimer", null);
208
+ i(this, "developerAccess", !1);
208
209
  i(this, "streaming", "");
209
- i(this, "asking", false);
210
- i(this, "waitingForFirstContent", false);
210
+ i(this, "asking", !1);
211
+ i(this, "waitingForFirstContent", !1);
211
212
  i(this, "abortController", null);
212
213
  i(this, "activeRunId", 0);
213
214
  i(this, "stoppedRunId", -1);
214
- i(this, "answerStopped", false);
215
+ i(this, "answerStopped", !1);
215
216
  i(this, "answerError", "");
216
217
  i(this, "conversationError", "");
217
218
  i(this, "deletingThreadId", "");
218
219
  i(this, "streamFailure", "");
219
220
  i(this, "streamDone", null);
221
+ i(this, "activeQuestionStartedAt", "");
220
222
  i(this, "answerAudience", "developer");
221
223
  i(this, "floatingRatio", 0.5);
222
224
  i(this, "floatingCleanup", null);
@@ -230,20 +232,20 @@ class V {
230
232
  }
231
233
  unmount() {
232
234
  var e;
233
- this.cleanupFloatingLauncher(), this.stopSourceRefresh(), this.cancelActiveAnswer(false), this.resetAnswerState(), (e = this.root) == null || e.remove(), this.root = null, this.panel = null, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoading = false, this.runLoadError = "", this.clearCopyFeedback(), this.sourceSnapshots = [], this.selectedSourceSnapshotId = null, this.sourceUploadStatus = "", this.sourceUploadProgress = null, this.sourceUploadError = "", this.sourceLoadError = "", this.sourceUploading = false, this.answerAudience = "developer";
235
+ this.cleanupFloatingLauncher(), this.stopSourceRefresh(), this.cancelActiveAnswer(!1), this.resetAnswerState(), (e = this.root) == null || e.remove(), this.root = null, this.panel = null, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.conversations = [], this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoading = !1, this.runLoadError = "", this.clearCopyFeedback(), this.sourceSnapshots = [], this.selectedSourceSnapshotId = null, this.sourceUploadStatus = "", this.sourceUploadProgress = null, this.sourceUploadError = "", this.sourceLoadError = "", this.sourceUploading = !1, this.developerAccess = !1, this.activeQuestionStartedAt = "", this.answerAudience = "developer";
234
236
  }
235
237
  open() {
236
- this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = "", this.panel = document.createElement("div"), this.panel.className = "po-panel", this.root.appendChild(this.panel), this.loadSources(), this.loadConversations(), this.renderPanel());
238
+ this.root && (this.cleanupFloatingLauncher(), this.root.innerHTML = "", this.panel = document.createElement("div"), this.panel.className = "po-panel", this.root.appendChild(this.panel), this.loadDeveloperAccess(), this.loadSources(), this.loadConversations(), this.renderPanel());
237
239
  }
238
240
  close() {
239
- this.stopSourceRefresh(), this.cancelActiveAnswer(false), this.renderClosed();
241
+ this.stopSourceRefresh(), this.cancelActiveAnswer(!1), this.renderClosed();
240
242
  }
241
243
  updateContext(e) {
242
244
  if (!this.options) return;
243
245
  const t = this.options.appId, s = String(this.options.ownerId || "").trim();
244
246
  this.options = { ...this.options, ...e }, this.client = new K(this.options);
245
247
  const r = String(this.options.ownerId || "").trim(), n = this.options.appId !== t;
246
- (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();
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 = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
247
249
  }
248
250
  renderClosed() {
249
251
  var e;
@@ -276,30 +278,43 @@ class V {
276
278
  }
277
279
  bindFloatingLauncher(e) {
278
280
  this.cleanupFloatingLauncher(), this.floatingRatio = this.loadFloatingRatio(), this.setFloatingPosition(e, window.innerHeight * this.floatingRatio);
279
- let t = null, s = false;
281
+ let t = null, s = !1;
280
282
  const r = (o) => {
281
283
  if (!t || o.pointerId !== t.pointerId) return;
282
284
  s = t.moved, e.classList.remove("po-fab-dragging"), e.hasPointerCapture && e.hasPointerCapture(o.pointerId) && e.releasePointerCapture(o.pointerId), t.moved && this.saveFloatingRatio(), t = null;
283
285
  }, n = (o) => {
284
286
  if (typeof o.button == "number" && o.button !== 0) return;
285
287
  const l = e.getBoundingClientRect();
286
- t = { pointerId: o.pointerId, startClientY: o.clientY, startCenterY: l.top + l.height / 2, moved: false }, e.setPointerCapture && e.setPointerCapture(o.pointerId), e.classList.add("po-fab-dragging");
288
+ t = { pointerId: o.pointerId, startClientY: o.clientY, startCenterY: l.top + l.height / 2, moved: !1 }, e.setPointerCapture && e.setPointerCapture(o.pointerId), e.classList.add("po-fab-dragging");
287
289
  }, c = (o) => {
288
290
  if (!t || o.pointerId !== t.pointerId) return;
289
291
  const l = o.clientY - t.startClientY;
290
- !t.moved && Math.abs(l) >= 4 && (t.moved = true), t.moved && (o.preventDefault(), this.setFloatingPosition(e, t.startCenterY + l));
292
+ !t.moved && Math.abs(l) >= 4 && (t.moved = !0), t.moved && (o.preventDefault(), this.setFloatingPosition(e, t.startCenterY + l));
291
293
  }, p = (o) => {
292
- s && (s = false, o.preventDefault(), o.stopImmediatePropagation());
294
+ s && (s = !1, o.preventDefault(), o.stopImmediatePropagation());
293
295
  }, m = () => {
294
296
  e.isConnected && this.setFloatingPosition(e, window.innerHeight * this.floatingRatio);
295
297
  };
296
- e.addEventListener("pointerdown", n), e.addEventListener("pointermove", c), e.addEventListener("pointerup", r), e.addEventListener("pointercancel", r), e.addEventListener("click", p, true), window.addEventListener("resize", m), this.floatingCleanup = () => {
297
- e.removeEventListener("pointerdown", n), e.removeEventListener("pointermove", c), e.removeEventListener("pointerup", r), e.removeEventListener("pointercancel", r), e.removeEventListener("click", p, true), window.removeEventListener("resize", m);
298
+ e.addEventListener("pointerdown", n), e.addEventListener("pointermove", c), e.addEventListener("pointerup", r), e.addEventListener("pointercancel", r), e.addEventListener("click", p, !0), window.addEventListener("resize", m), this.floatingCleanup = () => {
299
+ e.removeEventListener("pointerdown", n), e.removeEventListener("pointermove", c), e.removeEventListener("pointerup", r), e.removeEventListener("pointercancel", r), e.removeEventListener("click", p, !0), window.removeEventListener("resize", m);
298
300
  };
299
301
  }
300
302
  cleanupFloatingLauncher() {
301
303
  this.floatingCleanup && (this.floatingCleanup(), this.floatingCleanup = null), this.root && this.root.style.removeProperty("--pageops-fab-top");
302
304
  }
305
+ async loadDeveloperAccess() {
306
+ var e, t;
307
+ this.developerAccess = !1, this.renderPanel();
308
+ const s = String(((e = this.options) == null ? void 0 : e.developerAccessUrl) || "").trim();
309
+ if (!s) return;
310
+ try {
311
+ const r = await fetch(s, { credentials: "same-origin", headers: { Accept: "application/json" } }), n = await r.json().catch(() => null);
312
+ this.developerAccess = !!(r.ok && (n == null ? void 0 : n.code) === 1e4 && ((t = n == null ? void 0 : n.data) == null ? void 0 : t.developer) === !0);
313
+ } catch (r) {
314
+ this.developerAccess = !1;
315
+ }
316
+ this.renderPanel();
317
+ }
303
318
  async ensureContext() {
304
319
  if (!this.client || !this.options) throw new Error("PageOps SDK 未初始化");
305
320
  const e = this.getPageContext(), t = this.getPageContextKey(e);
@@ -352,7 +367,7 @@ class V {
352
367
  if (this.asking) return;
353
368
  const s = e === "" ? null : e;
354
369
  if ((this.selectedSourceSnapshotId == null ? "" : String(this.selectedSourceSnapshotId)) === (s == null ? "" : String(s))) return;
355
- this.selectedSourceSnapshotId = s, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = false, this.renderPanel();
370
+ this.selectedSourceSnapshotId = s, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
356
371
  }
357
372
  sourceSnapshotValue(e) {
358
373
  var t, s;
@@ -377,15 +392,15 @@ class V {
377
392
  async loadConversations() {
378
393
  this.client && (this.conversations = await this.client.listConversations(), this.renderPanel());
379
394
  }
380
- async newConversation() {
395
+ async newConversation(e = "") {
381
396
  var s;
382
397
  if (!this.client) return;
383
- const e = await this.ensureContext(), t = (s = e.menu_path) != null && s.length ? e.menu_path.join(" / ") : e.route || document.title || "新的问答";
384
- this.currentThread = await this.client.createConversation(e.id, t), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = false, this.renderPanel();
398
+ const t = await this.ensureContext(), r = e ? conversationTitle(t, e) : (s = t.menu_path) != null && s.length ? t.menu_path.join(" / ") : t.route || document.title || "新的问答";
399
+ this.currentThread = await this.client.createConversation(t.id, r), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
385
400
  }
386
401
  async selectThread(e) {
387
402
  if (!this.client) return;
388
- this.currentThread = e, this.selectedPageKey = this.getPageContextKey(this.getPageContext()), this.messages = await this.client.listMessages(e.id), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = false, this.renderPanel();
403
+ this.currentThread = e, this.selectedPageKey = this.getPageContextKey(this.getPageContext()), this.messages = await this.client.listMessages(e.id), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
389
404
  const t = [...this.messages].reverse().map(M).find(Boolean);
390
405
  t && await this.loadAgentRun(t);
391
406
  }
@@ -409,7 +424,7 @@ class V {
409
424
  async uploadSource(e, t) {
410
425
  var s;
411
426
  if (this.client) {
412
- this.sourceUploading = true, this.sourceUploadProgress = 0, this.sourceUploadStatus = "上传中 0%", this.sourceUploadError = "", this.renderPanel();
427
+ this.sourceUploading = !0, this.sourceUploadProgress = 0, this.sourceUploadStatus = "上传中 0%", this.sourceUploadError = "", this.renderPanel();
413
428
  try {
414
429
  await this.client.uploadSource(e, { ...t, uploader: (s = this.options) == null ? void 0 : s.uploader, onProgress: (r) => {
415
430
  this.sourceUploadProgress = Math.max(0, Math.min(100, Math.round(r.percent))), this.sourceUploadStatus = `上传中 ${this.sourceUploadProgress}%`, this.renderPanel();
@@ -417,7 +432,7 @@ class V {
417
432
  } catch (r) {
418
433
  this.sourceUploadError = r instanceof Error ? r.message : "源码包上传失败", this.sourceUploadStatus = "";
419
434
  } finally {
420
- this.sourceUploading = false, this.sourceUploadProgress = null, this.renderPanel();
435
+ this.sourceUploading = !1, this.sourceUploadProgress = null, this.renderPanel();
421
436
  }
422
437
  }
423
438
  }
@@ -428,13 +443,13 @@ class V {
428
443
  this.sourceUploadError = t, this.renderPanel();
429
444
  return;
430
445
  }
431
- this.resetAnswerState();
446
+ this.resetAnswerState(), this.activeQuestionStartedAt = (/* @__PURE__ */ new Date()).toISOString();
432
447
  const s = ++this.activeRunId, r = new AbortController();
433
- this.abortController = r, this.stoppedRunId = -1, this.asking = true, this.waitingForFirstContent = true, this.renderPanel();
448
+ this.abortController = r, this.stoppedRunId = -1, this.asking = !0, this.waitingForFirstContent = !0, this.renderPanel();
434
449
  try {
435
450
  const n = this.getPageContextKey(this.getPageContext());
436
- if (this.currentThread && this.selectedPageKey && this.selectedPageKey !== n && (this.currentThread = null), this.currentThread || await this.newConversation(), !this.currentThread) throw new Error("无法创建问答会话,请稍后重试。");
437
- this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {} }), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
451
+ if (this.currentThread && this.selectedPageKey && this.selectedPageKey !== n && (this.currentThread = null), this.currentThread || await this.newConversation(e), !this.currentThread) throw new Error("无法创建问答会话,请稍后重试。");
452
+ this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {}, created_at: this.activeQuestionStartedAt }), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
438
453
  const c = await this.client.streamQuestion(this.currentThread.id, e, this.answerAudience, r.signal);
439
454
  if (!c.ok) throw new Error(await z(c, "服务暂时无法回答,请稍后重试。"));
440
455
  if (!c.body) throw new Error("服务未返回有效的流式响应,请稍后重试。");
@@ -445,34 +460,34 @@ class V {
445
460
  await this.selectThread(this.currentThread);
446
461
  } catch (n) {
447
462
  if (s !== this.activeRunId) return;
448
- this.typewriter.clear(), this.waitingForFirstContent = false, s === this.stoppedRunId ? this.answerStopped = true : (this.answerError = n instanceof Error ? n.message : "服务异常,请稍后重试。", this.upsertStep({ id: "error", title: "执行失败", status: "failed", summary: this.answerError }));
463
+ this.typewriter.clear(), this.waitingForFirstContent = !1, s === this.stoppedRunId ? this.answerStopped = !0 : (this.answerError = n instanceof Error ? n.message : "服务异常,请稍后重试。", this.upsertStep({ id: "error", title: "执行失败", status: "failed", summary: this.answerError }));
449
464
  } finally {
450
465
  if (s !== this.activeRunId) return;
451
- this.asking = false, this.waitingForFirstContent = false, this.abortController === r && (this.abortController = null), this.renderPanel(true);
466
+ this.asking = !1, this.waitingForFirstContent = !1, this.abortController === r && (this.abortController = null), this.renderPanel(!0);
452
467
  }
453
468
  }
454
469
  cancelActiveAnswer(e) {
455
470
  var t;
456
471
  if (!(!this.asking && !this.abortController)) {
457
472
  if (e) {
458
- this.stoppedRunId = this.activeRunId, this.answerStopped = true;
473
+ this.stoppedRunId = this.activeRunId, this.answerStopped = !0;
459
474
  const s = this.steps.map((r) => r.status === "running" ? { ...r, status: "cancelled" } : r);
460
475
  this.steps = s.some((r) => r.status === "cancelled") ? s : [...s, { id: "stopped", title: "已停止", status: "cancelled" }];
461
476
  } else
462
- this.activeRunId += 1, this.asking = false;
463
- this.typewriter.clear(), this.waitingForFirstContent = false, (t = this.abortController) == null || t.abort(), this.abortController = null, e && this.renderPanel();
477
+ this.activeRunId += 1, this.asking = !1;
478
+ this.typewriter.clear(), this.waitingForFirstContent = !1, (t = this.abortController) == null || t.abort(), this.abortController = null, e && this.renderPanel();
464
479
  }
465
480
  }
466
481
  handleStreamEvent(e, t) {
467
482
  var s, r;
468
483
  if (e === "step") {
469
- this.upsertStep(t), this.renderExecutionSteps(true);
484
+ this.upsertStep(t), this.renderExecutionSteps(!0);
470
485
  return;
471
486
  }
472
487
  if (e === "delta") {
473
488
  const n = String((s = t.content) != null ? s : "");
474
489
  if (!n) return;
475
- this.waitingForFirstContent = false, this.typewriter.enqueue(n);
490
+ this.waitingForFirstContent = !1, this.typewriter.enqueue(n);
476
491
  return;
477
492
  }
478
493
  e === "done" && (this.streamDone = t), e === "error" && (this.streamFailure = String((r = t.message) != null ? r : "服务异常,请稍后重试。"));
@@ -485,11 +500,17 @@ class V {
485
500
  return;
486
501
  }
487
502
  e.innerHTML = R(this.streaming);
503
+ const thinking = e.closest(".po-message") == null ? void 0 : e.closest(".po-message").querySelector(".po-thinking-process");
504
+ if (thinking) {
505
+ thinking.open = !1;
506
+ const status = thinking.querySelector("summary span");
507
+ status && (status.textContent = "已思考完成");
508
+ }
488
509
  const t = (r = this.panel) == null ? void 0 : r.querySelector(".po-messages");
489
510
  t && (t.scrollTop = t.scrollHeight);
490
511
  }
491
512
  resetAnswerState() {
492
- this.typewriter.clear(), this.asking = false, this.waitingForFirstContent = false, this.answerError = "", this.answerStopped = false, this.streamFailure = "", this.streamDone = null, this.streaming = "";
513
+ this.typewriter.clear(), this.asking = !1, this.waitingForFirstContent = !1, this.answerError = "", this.answerStopped = !1, this.streamFailure = "", this.streamDone = null, this.streaming = "";
493
514
  }
494
515
  upsertStep(e) {
495
516
  const t = this.steps.findIndex((s) => s.id === e.id);
@@ -497,7 +518,7 @@ class V {
497
518
  }
498
519
  async loadAgentRun(e) {
499
520
  if (!(!this.client || !e)) {
500
- this.selectedAgentRunId = e, this.runLoading = true, this.runLoadError = "", this.renderPanel();
521
+ this.selectedAgentRunId = e, this.runLoading = !0, this.runLoadError = "", this.renderPanel();
501
522
  try {
502
523
  const t = await this.client.getAgentRun(e);
503
524
  if (this.selectedAgentRunId !== e) return;
@@ -506,7 +527,7 @@ class V {
506
527
  if (this.selectedAgentRunId !== e) return;
507
528
  this.steps = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
508
529
  } finally {
509
- this.selectedAgentRunId === e && (this.runLoading = false, this.renderPanel());
530
+ this.selectedAgentRunId === e && (this.runLoading = !1, this.renderPanel());
510
531
  }
511
532
  }
512
533
  }
@@ -525,7 +546,7 @@ class V {
525
546
  } catch (s) {
526
547
  this.copiedAgentRunId = `error:${e}`;
527
548
  }
528
- this.clearCopyFeedback(false), this.copyFeedbackTimer = setTimeout(() => {
549
+ this.clearCopyFeedback(!1), this.copyFeedbackTimer = setTimeout(() => {
529
550
  this.copiedAgentRunId = "", this.copyFeedbackTimer = null, this.updateCopyFeedback();
530
551
  }, 1800), this.updateCopyFeedback();
531
552
  }
@@ -538,7 +559,7 @@ class V {
538
559
  t.textContent = this.copiedAgentRunId === s ? "已复制" : this.copiedAgentRunId === `error:${s}` ? "复制失败" : "复制流水号";
539
560
  });
540
561
  }
541
- clearCopyFeedback(e = true) {
562
+ clearCopyFeedback(e = !0) {
542
563
  this.copyFeedbackTimer && clearTimeout(this.copyFeedbackTimer), this.copyFeedbackTimer = null, e && (this.copiedAgentRunId = "");
543
564
  }
544
565
  latestAnalysisStatus() {
@@ -549,7 +570,7 @@ class V {
549
570
  return ["pending", "running"].includes(this.latestAnalysisStatus());
550
571
  }
551
572
  questionUnavailableReason() {
552
- return this.sourceLoadError && !this.sourceSnapshots.length ? "暂时无法读取项目共享代码包,请检查 PageOps 服务连接。" : this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
573
+ return this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "";
553
574
  }
554
575
  scheduleSourceRefresh() {
555
576
  this.stopSourceRefresh(), !(!this.sourceLoadError && !this.isProjectMemoryUpdating()) && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
@@ -557,10 +578,10 @@ class V {
557
578
  stopSourceRefresh() {
558
579
  this.sourceRefreshTimer && clearTimeout(this.sourceRefreshTimer), this.sourceRefreshTimer = null;
559
580
  }
560
- renderPanel(e = this.asking, t = false) {
581
+ renderPanel(e = this.asking, t = !1) {
561
582
  var g;
562
583
  if (!this.panel) return;
563
- const s = (g = this.panel.querySelector(".po-messages")) == null ? void 0 : g.scrollTop, r = this.questionUnavailableReason(), n = r || (this.asking ? "回答生成中,请稍候" : "请输入页面分析问题,Enter 发送,Shift + Enter 换行"), c = !!(r || this.asking), p = r ? '<button type="submit" disabled>暂不可提问</button>' : this.asking ? '<button class="po-stop" type="button" data-action="stop-answer" aria-label="停止输出" title="停止输出"><span aria-hidden="true"></span></button>' : '<button type="submit">发送</button>', m = C.map((o) => `
584
+ const s = (g = this.panel.querySelector(".po-messages")) == null ? void 0 : g.scrollTop, r = this.questionUnavailableReason(), n = r || (this.asking ? "回答生成中,请稍候" : this.sourceSnapshots.length ? "请输入页面分析问题,Enter 发送,Shift + Enter 换行" : "可直接闲聊;业务问题需先上传代码包"), c = !!(r || this.asking), p = r ? '<button type="submit" disabled>暂不可提问</button>' : this.asking ? '<button class="po-stop" type="button" data-action="stop-answer" aria-label="停止输出" title="停止输出"><span aria-hidden="true"></span></button>' : '<button type="submit">发送</button>', m = C.map((o) => `
564
585
  <button type="button" data-audience="${o.value}" aria-pressed="${o.value === this.answerAudience}" ${this.asking ? "disabled" : ""}>${o.label}</button>
565
586
  `).join("");
566
587
  if (this.panel.innerHTML = `
@@ -581,7 +602,7 @@ class V {
581
602
  }).join("")}</div>
582
603
  </aside>
583
604
  <main class="po-chat">
584
- <header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread ? l(this.currentThread.title) : "未选择问答"}</h2></div><div class="po-audience"><span>回答角色</span><div class="po-audience-options" role="group" aria-label="回答角色">${m}</div></div></header>
605
+ <header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread ? l(this.currentThread.title) : "输入问题即可开始"}</h2></div><div class="po-audience"><span>回答角色</span><div class="po-audience-options" role="group" aria-label="回答角色">${m}</div></div></header>
585
606
  <section class="po-messages">
586
607
  ${this.messages.map((o) => this.renderMessage(o)).join("")}
587
608
  ${this.renderAnswerState()}
@@ -602,7 +623,7 @@ class V {
602
623
  }
603
624
  }
604
625
  renderAnswerState() {
605
- const e = this.asking && this.waitingForFirstContent ? '<article class="po-message assistant waiting" role="status" aria-live="polite"><b>PageOps 分析</b><div class="po-ai-waiting"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在理解问题并检索证据</span></div></article>' : "", t = this.streaming ? `<article class="po-message assistant streaming"><b>PageOps 分析</b><div><span data-streaming-content>${R(this.streaming)}</span>${this.asking ? '<span class="po-typing-cursor" aria-hidden="true"></span>' : ""}</div></article>` : "", s = this.answerError ? `<article class="po-message assistant answer-error" role="alert"><b>PageOps 分析</b><strong>本次回答失败</strong><div>${l(this.answerError)}</div></article>` : "", r = this.answerStopped ? '<div class="po-stream-stopped" role="status">已停止输出</div>' : "";
626
+ const n = messageTime(this.activeQuestionStartedAt), c = this.renderThinkingProcess(), e = this.asking && this.waitingForFirstContent ? `<article class="po-message assistant waiting" role="status" aria-live="polite">${n}<b>PageOps 分析</b><div class="po-ai-waiting"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在理解问题并检索证据</span></div>${c}</article>` : "", t = this.streaming ? `<article class="po-message assistant streaming">${n}<b>PageOps 分析</b><div><span data-streaming-content>${R(this.streaming)}</span>${this.asking ? '<span class="po-typing-cursor" aria-hidden="true"></span>' : ""}</div>${c}</article>` : "", s = this.answerError ? `<article class="po-message assistant answer-error" role="alert">${n}<b>PageOps 分析</b><strong>本次回答失败</strong><div>${l(this.answerError)}</div></article>` : "", r = this.answerStopped ? '<div class="po-stream-stopped" role="status">已停止输出</div>' : "";
606
627
  return `${e}${t}${r}${s}`;
607
628
  }
608
629
  renderMessage(e) {
@@ -610,14 +631,15 @@ class V {
610
631
  <span class="po-run-id" title="${l(t)}">问答流水号 <code>${l(t)}</code></span>
611
632
  <button type="button" data-copy-run="${l(t)}">${r ? "已复制" : n ? "复制失败" : "复制流水号"}</button>
612
633
  <button type="button" data-view-run="${l(t)}" aria-pressed="${s}">${s ? "正在查看" : "查看执行过程"}</button>
613
- </footer>` : "";
634
+ </footer>` : "", p = messageTime(e.created_at), m = e.role === "user" ? "" : "<b>PageOps 分析</b>", g = e.role === "assistant" && s ? this.renderThinkingProcess() : "";
614
635
  return `<article class="po-message ${e.role} ${s ? "run-selected" : ""}" data-message="${l(e.id)}">
615
- <b>${e.role === "user" ? "你" : "PageOps 分析"}</b>
636
+ ${p}${m}
616
637
  <div>${e.role === "assistant" ? R(e.content) : l(e.content)}</div>
617
- ${c}
638
+ ${g}${c}
618
639
  </article>`;
619
640
  }
620
641
  renderSourceUploader() {
642
+ if (!this.developerAccess) return "";
621
643
  const e = this.sourceLoadError ? "暂时无法读取项目共享代码包,连接恢复后将自动重试。" : "当前项目暂无代码包,请先上传后再提问。";
622
644
  const t = typeof this.sourceUploadProgress == "number" ? Math.max(0, Math.min(100, Math.round(this.sourceUploadProgress))) : 0;
623
645
  return `
@@ -666,17 +688,32 @@ class V {
666
688
  </details>`;
667
689
  }).join("");
668
690
  }
669
- renderExecutionSteps(e = false) {
691
+ renderThinkingProcess() {
692
+ if (!this.asking && !this.steps.length && !this.runLoading && !this.runLoadError) return "";
693
+ const e = this.asking && !this.streaming, t = this.asking && !this.streaming ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成", s = thinkingDuration(this.steps, this.activeQuestionStartedAt);
694
+ return `<details class="po-thinking-process" ${e ? "open" : ""}><summary><strong>${s ? `用时 ${l(s)}` : "思考过程"}</strong><span>${t}</span></summary><div class="po-thinking-content">${this.renderThinkingSteps()}</div></details>`;
695
+ }
696
+ renderThinkingSteps() {
697
+ if (this.runLoading) return '<div class="po-thinking-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复思考过程</span></div>';
698
+ if (this.runLoadError) return `<div class="po-thinking-state failed">${l(this.runLoadError)}</div>`;
699
+ const e = this.steps.length ? this.steps : [{ id: "idle", kind: "thinking", title: "理解问题", status: "running", summary: "正在判断问题并规划需要核对的信息。" }];
700
+ return e.map((t) => {
701
+ const s = String(t.kind || (String(t.id || "").startsWith("model-turn-") ? "thinking" : "status")), r = thinkingIcon(s), n = (t.metrics || []).length ? `<span class="po-thinking-metrics">${t.metrics.map((c) => l(c)).join(" · ")}</span>` : "", p = (t.details || []).map((c) => `<div class="po-thinking-detail"><span>${l(c.label)}</span>${String(c.value || "").split("\n").filter(Boolean).map((m) => `<code>${l(m)}</code>`).join("")}</div>`).join("");
702
+ if (s === "thinking") return `<div class="po-thinking-note ${t.status}">${r}<div><strong>${l(t.title)}</strong><p>${l(t.summary || "")}</p>${n}</div></div>`;
703
+ return `<div class="po-thinking-activity ${t.status}">${r}<div class="po-thinking-activity-copy"><strong>${l(t.title)}</strong><span>${l(t.summary || "")}</span>${n}${p}</div></div>`;
704
+ }).join("");
705
+ }
706
+ renderExecutionSteps(e = !1) {
670
707
  var s, r;
671
708
  const t = (s = this.panel) == null ? void 0 : s.querySelector(".po-steps");
672
- if (t && (t.innerHTML = this.renderSteps(), e)) {
709
+ if (t && (t.innerHTML = this.renderSteps(), this.panel == null || this.panel.querySelectorAll(".po-thinking-content").forEach((n) => n.innerHTML = this.renderThinkingSteps()), e)) {
673
710
  const n = (r = this.panel) == null ? void 0 : r.querySelector(".po-trace > section");
674
711
  n && (n.scrollTop = n.scrollHeight);
675
712
  }
676
713
  }
677
714
  bindPanelEvents() {
678
715
  var e, t, s, r, n, c, p, m, g, o, y, w, b, S, $, E, A, T, h, d;
679
- (t = (e = this.panel) == null ? void 0 : e.querySelector('[data-action="new"]')) == null || t.addEventListener("click", () => void this.newConversation()), (r = (s = this.panel) == null ? void 0 : s.querySelector('[data-action="close"]')) == null || r.addEventListener("click", () => this.close()), (c = (n = this.panel) == null ? void 0 : n.querySelector('[data-action="stop-answer"]')) == null || c.addEventListener("click", () => this.cancelActiveAnswer(true)), (p = this.panel) == null || p.querySelectorAll("[data-audience]").forEach((h) => {
716
+ (t = (e = this.panel) == null ? void 0 : e.querySelector('[data-action="new"]')) == null || t.addEventListener("click", () => void this.newConversation()), (r = (s = this.panel) == null ? void 0 : s.querySelector('[data-action="close"]')) == null || r.addEventListener("click", () => this.close()), (c = (n = this.panel) == null ? void 0 : n.querySelector('[data-action="stop-answer"]')) == null || c.addEventListener("click", () => this.cancelActiveAnswer(!0)), (p = this.panel) == null || p.querySelectorAll("[data-audience]").forEach((h) => {
680
717
  h.addEventListener("click", () => {
681
718
  var d;
682
719
  return this.changeAnswerAudience((d = h.dataset.audience) != null ? d : "");
@@ -740,6 +777,40 @@ function M(a) {
740
777
  const e = (t = a.metadata_json) == null ? void 0 : t.agent_run_id;
741
778
  return typeof e == "number" ? String(e) : typeof e == "string" ? e : "";
742
779
  }
780
+ function conversationTitle(a, e) {
781
+ var s;
782
+ const t = (s = a.menu_path) != null && s.length ? String(a.menu_path[a.menu_path.length - 1]) : String(a.title || a.route || document.title || "新的问答").split(" - ")[0], r = String(e || "").replace(/\s+/g, " ").replace(/[??!!。]+$/, "").trim(), n = r.length > 28 ? `${r.slice(0, 28)}...` : r;
783
+ return [t.trim(), n].filter(Boolean).join(" · ");
784
+ }
785
+ function formatFullTimestamp(a) {
786
+ const e = new Date(a);
787
+ if (Number.isNaN(e.getTime())) return "";
788
+ const t = new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Shanghai", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" }).formatToParts(e).reduce((s, r) => (s[r.type] = r.value, s), {});
789
+ return `${t.year}-${t.month}-${t.day} ${t.hour}:${t.minute}:${t.second}`;
790
+ }
791
+ function messageTime(a) {
792
+ const e = formatFullTimestamp(a);
793
+ return e ? `<time class="po-message-time" datetime="${l(a)}">${e}</time>` : "";
794
+ }
795
+ function thinkingDuration(a, e) {
796
+ const t = [...a].reverse().flatMap((s) => s.metrics || []).find((s) => /^耗时\s/.test(s));
797
+ if (t) return t.replace(/^耗时\s*/, "");
798
+ if (!e) return "";
799
+ const s = Date.now() - new Date(e).getTime();
800
+ if (!Number.isFinite(s) || s < 0) return "";
801
+ const r = Math.floor(s / 1e3), n = Math.floor(r / 60), c = r % 60;
802
+ return n ? `${n}m ${c}s` : `${c}s`;
803
+ }
804
+ function thinkingIcon(a) {
805
+ const e = {
806
+ read: '<path d="M4 5.5A2.5 2.5 0 0 1 6.5 3H11v14H6.5A2.5 2.5 0 0 0 4 19.5z"/><path d="M20 5.5A2.5 2.5 0 0 0 17.5 3H13v14h4.5a2.5 2.5 0 0 1 2.5 2.5z"/>',
807
+ search: '<circle cx="11" cy="11" r="6"/><path d="m16 16 4 4"/>',
808
+ data: '<ellipse cx="12" cy="5" rx="7" ry="3"/><path d="M5 5v6c0 1.7 3.1 3 7 3s7-1.3 7-3V5"/><path d="M5 11v6c0 1.7 3.1 3 7 3s7-1.3 7-3v-6"/>',
809
+ tool: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/>',
810
+ thinking: '<path d="M9 18h6M10 22h4"/><path d="M8.5 14.5A6 6 0 1 1 15.5 14.5c-.9.7-1.5 1.5-1.5 2.5h-4c0-1-.6-1.8-1.5-2.5Z"/>'
811
+ }[a] || '<circle cx="12" cy="12" r="8"/><path d="m9 12 2 2 4-4"/>';
812
+ return `<svg class="po-thinking-icon" viewBox="0 0 24 24" aria-hidden="true">${e}</svg>`;
813
+ }
743
814
  function O(a) {
744
815
  return new Intl.DateTimeFormat("zh-CN", {
745
816
  timeZone: "Asia/Shanghai",
@@ -761,4 +832,5 @@ function G(a) {
761
832
  function Z(a) {
762
833
  return { pending: "等待中", running: "执行中", completed: "已完成", failed: "失败", cancelled: "已停止" }[a];
763
834
  }
764
- const Y = new V();exports.PageOpsSDK=Y;}));
835
+ const Y = new V();
836
+ exports.PageOpsSDK=Y;}));
package/dist/types.d.ts CHANGED
@@ -12,6 +12,8 @@ export interface PageOpsMountOptions {
12
12
  apiBase: string;
13
13
  appId: string;
14
14
  env: string;
15
+ /** Host endpoint used to decide whether source-package controls are visible. */
16
+ developerAccessUrl?: string;
15
17
  ownerId?: string;
16
18
  uploader?: string;
17
19
  getPageContext?: () => PageOpsContext;
@@ -42,9 +44,11 @@ export interface ConversationMessage {
42
44
  content: string;
43
45
  evidence_bundle_id?: string | null;
44
46
  metadata_json: Record<string, unknown>;
47
+ created_at?: string;
45
48
  }
46
49
  export interface ExecutionStep {
47
50
  id: string;
51
+ kind?: 'thinking' | 'read' | 'search' | 'data' | 'tool' | 'status';
48
52
  title: string;
49
53
  status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
50
54
  summary?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageops/sdk",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "PageOps embeddable frontend SDK",
5
5
  "type": "module",
6
6
  "main": "dist/pageops-sdk.umd.cjs",
@@ -19,7 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "scripts": {
22
- "build": "vite build && tsc --emitDeclarationOnly",
22
+ "build": "node scripts/sync-artifacts.cjs",
23
+ "verify:static": "node --check dist/pageops-sdk.es.js && node --check dist/pageops-sdk.umd.cjs && node scripts/verify-static.cjs",
23
24
  "pack:check": "npm pack --dry-run",
24
25
  "test": "vitest run"
25
26
  },
@@ -31,6 +32,6 @@
31
32
  "vitest": "3.2.4"
32
33
  },
33
34
  "engines": {
34
- "node": ">=20"
35
+ "node": ">=14.21.3"
35
36
  }
36
37
  }