@pageops/sdk 0.1.35 → 0.1.37

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 CHANGED
@@ -1,9 +1,16 @@
1
1
  # PageOps SDK source baseline
2
2
 
3
3
  This directory restores the maintainable SDK boundary from the verified public
4
- `@pageops/sdk@0.1.34` artifacts. Version `0.1.35` adds developer-gated source
5
- controls and conversation presentation behavior directly to the SDK instead of
6
- patching host DOM from a business application.
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
+ Version `0.1.37` separates the answer-local `thoughts` stream/history contract
11
+ from the right-side `steps` contract. The middle timeline no longer re-renders
12
+ the execution cards; it receives only selected model decisions and evidence
13
+ activities shaped by the backend thought presenter.
7
14
 
8
15
  `src/index.js` is the readable ESM runtime baseline, `src/styles.css` preserves
9
16
  the 0.1.34 styles, and `src/extensions.css` contains the new non-minified style
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ declare class PageOpsSDKController {
12
12
  private conversations;
13
13
  private messages;
14
14
  private steps;
15
+ private thoughts;
15
16
  private selectedAgentRunId;
16
17
  private runLoading;
17
18
  private runLoadError;
@@ -73,6 +74,7 @@ declare class PageOpsSDKController {
73
74
  private updateStreamingMessage;
74
75
  private resetAnswerState;
75
76
  private upsertStep;
77
+ private upsertThought;
76
78
  private loadAgentRun;
77
79
  private copyAgentRunId;
78
80
  private updateCopyFeedback;
@@ -89,6 +91,8 @@ declare class PageOpsSDKController {
89
91
  private renderSourceItem;
90
92
  private renderSteps;
91
93
  private renderThinkingProcess;
94
+ private renderThinkingSteps;
95
+ private renderThinkingTimeline;
92
96
  private renderExecutionSteps;
93
97
  private bindPanelEvents;
94
98
  }
@@ -1,9 +1,8 @@
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
2
  .po-thinking-process {
3
- margin: 4px 0 2px;
4
- border: 1px solid #d8e0ec;
5
- border-radius: 6px;
6
- background: #f7f9fc;
3
+ margin: 14px 0 4px;
4
+ border-top: 1px solid #e2e8f0;
5
+ border-bottom: 1px solid #e2e8f0;
7
6
  color: #334155;
8
7
  }
9
8
 
@@ -12,14 +11,15 @@
12
11
  align-items: center;
13
12
  justify-content: space-between;
14
13
  gap: 12px;
15
- min-height: 34px;
16
- padding: 0 10px;
14
+ min-height: 40px;
15
+ padding: 0 2px;
17
16
  cursor: pointer;
18
17
  font-size: 12px;
19
18
  }
20
19
 
21
20
  .po-thinking-process > summary strong {
22
- font-size: 12px;
21
+ color: #64748b;
22
+ font-size: 13px;
23
23
  font-weight: 700;
24
24
  }
25
25
 
@@ -30,15 +30,103 @@
30
30
 
31
31
  .po-thinking-content {
32
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);
33
41
  gap: 8px;
34
- padding: 9px;
35
- border-top: 1px solid #e2e8f0;
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;
36
126
  }
37
127
 
38
- .po-thinking-content .po-step {
39
- margin: 0;
40
- border-radius: 6px;
41
- background: #fff;
128
+ .po-thinking-state.failed {
129
+ color: #b91c1c;
42
130
  }
43
131
 
44
132
  .po-message-time {
@@ -192,6 +192,7 @@ class V {
192
192
  i(this, "conversations", []);
193
193
  i(this, "messages", []);
194
194
  i(this, "steps", []);
195
+ i(this, "thoughts", []);
195
196
  i(this, "selectedAgentRunId", "");
196
197
  i(this, "runLoading", !1);
197
198
  i(this, "runLoadError", "");
@@ -232,7 +233,7 @@ class V {
232
233
  }
233
234
  unmount() {
234
235
  var e;
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";
236
+ 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.thoughts = [], 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";
236
237
  }
237
238
  open() {
238
239
  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());
@@ -245,7 +246,7 @@ class V {
245
246
  const t = this.options.appId, s = String(this.options.ownerId || "").trim();
246
247
  this.options = { ...this.options, ...e }, this.client = new K(this.options);
247
248
  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 = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
249
+ (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.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
249
250
  }
250
251
  renderClosed() {
251
252
  var e;
@@ -367,7 +368,7 @@ class V {
367
368
  if (this.asking) return;
368
369
  const s = e === "" ? null : e;
369
370
  if ((this.selectedSourceSnapshotId == null ? "" : String(this.selectedSourceSnapshotId)) === (s == null ? "" : String(s))) return;
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();
371
+ this.selectedSourceSnapshotId = s, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
371
372
  }
372
373
  sourceSnapshotValue(e) {
373
374
  var t, s;
@@ -382,7 +383,7 @@ class V {
382
383
  if (this.client) {
383
384
  try {
384
385
  const e = await this.client.listSources(), t = e[0], s = t ? this.sourceSnapshotValue(t) : null, r = this.context && this.context.source_snapshot_id != null ? String(this.context.source_snapshot_id) : null, n = this.selectedSourceSnapshotId == null && s != null && r !== s && (this.context != null || this.currentThread != null);
385
- this.sourceSnapshots = e, this.sourceLoadError = "", n && (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);
386
+ this.sourceSnapshots = e, this.sourceLoadError = "", n && (this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1);
386
387
  } catch (e) {
387
388
  this.sourceLoadError = "源码包状态加载失败,连接恢复后将自动重试。";
388
389
  }
@@ -396,11 +397,11 @@ class V {
396
397
  var s;
397
398
  if (!this.client) return;
398
399
  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();
400
+ this.currentThread = await this.client.createConversation(t.id, r), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.thoughts = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
400
401
  }
401
402
  async selectThread(e) {
402
403
  if (!this.client) return;
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();
404
+ this.currentThread = e, this.selectedPageKey = this.getPageContextKey(this.getPageContext()), this.messages = await this.client.listMessages(e.id), this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
404
405
  const t = [...this.messages].reverse().map(M).find(Boolean);
405
406
  t && await this.loadAgentRun(t);
406
407
  }
@@ -410,7 +411,7 @@ class V {
410
411
  this.deletingThreadId = e.id, this.conversationError = "", this.renderPanel();
411
412
  try {
412
413
  if (await this.client.deleteConversation(e.id), this.conversations = this.conversations.filter((s) => s.id !== e.id), ((t = this.currentThread) == null ? void 0 : t.id) === e.id) {
413
- this.currentThread = null, this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1;
414
+ this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1;
414
415
  const s = this.conversations[0];
415
416
  s && await this.selectThread(s);
416
417
  }
@@ -449,7 +450,7 @@ class V {
449
450
  try {
450
451
  const n = this.getPageContextKey(this.getPageContext());
451
452
  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();
453
+ this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {}, created_at: this.activeQuestionStartedAt }), this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
453
454
  const c = await this.client.streamQuestion(this.currentThread.id, e, this.answerAudience, r.signal);
454
455
  if (!c.ok) throw new Error(await z(c, "服务暂时无法回答,请稍后重试。"));
455
456
  if (!c.body) throw new Error("服务未返回有效的流式响应,请稍后重试。");
@@ -484,6 +485,10 @@ class V {
484
485
  this.upsertStep(t), this.renderExecutionSteps(!0);
485
486
  return;
486
487
  }
488
+ if (e === "thought") {
489
+ this.upsertThought(t), this.renderThinkingTimeline();
490
+ return;
491
+ }
487
492
  if (e === "delta") {
488
493
  const n = String((s = t.content) != null ? s : "");
489
494
  if (!n) return;
@@ -500,6 +505,12 @@ class V {
500
505
  return;
501
506
  }
502
507
  e.innerHTML = R(this.streaming);
508
+ const thinking = e.closest(".po-message") == null ? void 0 : e.closest(".po-message").querySelector(".po-thinking-process");
509
+ if (thinking) {
510
+ thinking.open = !1;
511
+ const status = thinking.querySelector("summary span");
512
+ status && (status.textContent = "已思考完成");
513
+ }
503
514
  const t = (r = this.panel) == null ? void 0 : r.querySelector(".po-messages");
504
515
  t && (t.scrollTop = t.scrollHeight);
505
516
  }
@@ -510,16 +521,20 @@ class V {
510
521
  const t = this.steps.findIndex((s) => s.id === e.id);
511
522
  this.steps = t === -1 ? [...this.steps, e] : this.steps.map((s) => s.id === e.id ? { ...s, ...e } : s);
512
523
  }
524
+ upsertThought(e) {
525
+ const t = this.thoughts.findIndex((s) => s.id === e.id);
526
+ this.thoughts = t === -1 ? [...this.thoughts, e] : this.thoughts.map((s) => s.id === e.id ? { ...s, ...e } : s);
527
+ }
513
528
  async loadAgentRun(e) {
514
529
  if (!(!this.client || !e)) {
515
530
  this.selectedAgentRunId = e, this.runLoading = !0, this.runLoadError = "", this.renderPanel();
516
531
  try {
517
532
  const t = await this.client.getAgentRun(e);
518
533
  if (this.selectedAgentRunId !== e) return;
519
- this.steps = t.steps;
534
+ this.steps = t.steps, this.thoughts = t.thoughts || [];
520
535
  } catch (t) {
521
536
  if (this.selectedAgentRunId !== e) return;
522
- this.steps = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
537
+ this.steps = [], this.thoughts = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
523
538
  } finally {
524
539
  this.selectedAgentRunId === e && (this.runLoading = !1, this.renderPanel());
525
540
  }
@@ -564,7 +579,7 @@ class V {
564
579
  return ["pending", "running"].includes(this.latestAnalysisStatus());
565
580
  }
566
581
  questionUnavailableReason() {
567
- return this.sourceLoadError && !this.sourceSnapshots.length ? "暂时无法读取项目共享代码包,请检查 PageOps 服务连接。" : this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
582
+ return this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "";
568
583
  }
569
584
  scheduleSourceRefresh() {
570
585
  this.stopSourceRefresh(), !(!this.sourceLoadError && !this.isProjectMemoryUpdating()) && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
@@ -575,7 +590,7 @@ class V {
575
590
  renderPanel(e = this.asking, t = !1) {
576
591
  var g;
577
592
  if (!this.panel) return;
578
- 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) => `
593
+ 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) => `
579
594
  <button type="button" data-audience="${o.value}" aria-pressed="${o.value === this.answerAudience}" ${this.asking ? "disabled" : ""}>${o.label}</button>
580
595
  `).join("");
581
596
  if (this.panel.innerHTML = `
@@ -683,14 +698,28 @@ class V {
683
698
  }).join("");
684
699
  }
685
700
  renderThinkingProcess() {
686
- if (!this.asking && !this.steps.length && !this.runLoading && !this.runLoadError) return "";
687
- const e = this.asking || this.steps.some((t) => t.status === "running"), t = this.asking ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成";
688
- return `<details class="po-thinking-process" ${e ? "open" : ""}><summary><strong>思考过程</strong><span>${t}</span></summary><div class="po-thinking-content">${this.renderSteps()}</div></details>`;
701
+ if (!this.asking && !this.thoughts.length && !this.runLoading && !this.runLoadError) return "";
702
+ const e = this.asking && !this.streaming, t = this.asking && !this.streaming ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成", s = thinkingDuration(this.thoughts, this.activeQuestionStartedAt);
703
+ 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>`;
704
+ }
705
+ renderThinkingSteps() {
706
+ if (this.runLoading) return '<div class="po-thinking-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复思考过程</span></div>';
707
+ if (this.runLoadError) return `<div class="po-thinking-state failed">${l(this.runLoadError)}</div>`;
708
+ const e = this.thoughts.length ? this.thoughts : [{ id: "idle", kind: "thinking", label: "理解问题", status: "running", text: "正在判断问题并规划需要核对的信息。" }];
709
+ return e.map((t) => {
710
+ const s = String(t.kind || "thinking"), 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("");
711
+ if (s === "thinking") return `<div class="po-thinking-note ${t.status}">${r}<div><strong>${l(t.label)}</strong><p>${l(t.text || "")}</p>${n}</div></div>`;
712
+ return `<div class="po-thinking-activity ${t.status}">${r}<div class="po-thinking-activity-copy"><strong>${l(t.label)}</strong><span>${l(t.text || "")}</span>${n}${p}</div></div>`;
713
+ }).join("");
714
+ }
715
+ renderThinkingTimeline() {
716
+ var e;
717
+ (e = this.panel) == null || e.querySelectorAll(".po-thinking-content").forEach((t) => t.innerHTML = this.renderThinkingSteps());
689
718
  }
690
719
  renderExecutionSteps(e = !1) {
691
720
  var s, r;
692
721
  const t = (s = this.panel) == null ? void 0 : s.querySelector(".po-steps");
693
- if (t && (t.innerHTML = this.renderSteps(), this.panel == null || this.panel.querySelectorAll(".po-thinking-content").forEach((n) => n.innerHTML = this.renderSteps()), e)) {
722
+ if (t && (t.innerHTML = this.renderSteps(), e)) {
694
723
  const n = (r = this.panel) == null ? void 0 : r.querySelector(".po-trace > section");
695
724
  n && (n.scrollTop = n.scrollHeight);
696
725
  }
@@ -776,6 +805,25 @@ function messageTime(a) {
776
805
  const e = formatFullTimestamp(a);
777
806
  return e ? `<time class="po-message-time" datetime="${l(a)}">${e}</time>` : "";
778
807
  }
808
+ function thinkingDuration(a, e) {
809
+ const t = [...a].reverse().flatMap((s) => s.metrics || []).find((s) => /^耗时\s/.test(s));
810
+ if (t) return t.replace(/^耗时\s*/, "");
811
+ if (!e) return "";
812
+ const s = Date.now() - new Date(e).getTime();
813
+ if (!Number.isFinite(s) || s < 0) return "";
814
+ const r = Math.floor(s / 1e3), n = Math.floor(r / 60), c = r % 60;
815
+ return n ? `${n}m ${c}s` : `${c}s`;
816
+ }
817
+ function thinkingIcon(a) {
818
+ const e = {
819
+ 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"/>',
820
+ search: '<circle cx="11" cy="11" r="6"/><path d="m16 16 4 4"/>',
821
+ 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"/>',
822
+ tool: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/>',
823
+ 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"/>'
824
+ }[a] || '<circle cx="12" cy="12" r="8"/><path d="m9 12 2 2 4-4"/>';
825
+ return `<svg class="po-thinking-icon" viewBox="0 0 24 24" aria-hidden="true">${e}</svg>`;
826
+ }
779
827
  function O(a) {
780
828
  return new Intl.DateTimeFormat("zh-CN", {
781
829
  timeZone: "Asia/Shanghai",
@@ -192,6 +192,7 @@ class V {
192
192
  i(this, "conversations", []);
193
193
  i(this, "messages", []);
194
194
  i(this, "steps", []);
195
+ i(this, "thoughts", []);
195
196
  i(this, "selectedAgentRunId", "");
196
197
  i(this, "runLoading", !1);
197
198
  i(this, "runLoadError", "");
@@ -232,7 +233,7 @@ class V {
232
233
  }
233
234
  unmount() {
234
235
  var e;
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";
236
+ 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.thoughts = [], 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";
236
237
  }
237
238
  open() {
238
239
  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());
@@ -245,7 +246,7 @@ class V {
245
246
  const t = this.options.appId, s = String(this.options.ownerId || "").trim();
246
247
  this.options = { ...this.options, ...e }, this.client = new K(this.options);
247
248
  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 = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
249
+ (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.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", r !== s && this.loadDeveloperAccess(), this.panel && this.loadConversations(), this.renderPanel();
249
250
  }
250
251
  renderClosed() {
251
252
  var e;
@@ -367,7 +368,7 @@ class V {
367
368
  if (this.asking) return;
368
369
  const s = e === "" ? null : e;
369
370
  if ((this.selectedSourceSnapshotId == null ? "" : String(this.selectedSourceSnapshotId)) === (s == null ? "" : String(s))) return;
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();
371
+ this.selectedSourceSnapshotId = s, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
371
372
  }
372
373
  sourceSnapshotValue(e) {
373
374
  var t, s;
@@ -382,7 +383,7 @@ class V {
382
383
  if (this.client) {
383
384
  try {
384
385
  const e = await this.client.listSources(), t = e[0], s = t ? this.sourceSnapshotValue(t) : null, r = this.context && this.context.source_snapshot_id != null ? String(this.context.source_snapshot_id) : null, n = this.selectedSourceSnapshotId == null && s != null && r !== s && (this.context != null || this.currentThread != null);
385
- this.sourceSnapshots = e, this.sourceLoadError = "", n && (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);
386
+ this.sourceSnapshots = e, this.sourceLoadError = "", n && (this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1);
386
387
  } catch (e) {
387
388
  this.sourceLoadError = "源码包状态加载失败,连接恢复后将自动重试。";
388
389
  }
@@ -396,11 +397,11 @@ class V {
396
397
  var s;
397
398
  if (!this.client) return;
398
399
  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();
400
+ this.currentThread = await this.client.createConversation(t.id, r), this.selectedPageKey = this.contextKey, this.conversations = [this.currentThread, ...this.conversations], this.messages = [], this.steps = [], this.thoughts = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
400
401
  }
401
402
  async selectThread(e) {
402
403
  if (!this.client) return;
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();
404
+ this.currentThread = e, this.selectedPageKey = this.getPageContextKey(this.getPageContext()), this.messages = await this.client.listMessages(e.id), this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1, this.renderPanel();
404
405
  const t = [...this.messages].reverse().map(M).find(Boolean);
405
406
  t && await this.loadAgentRun(t);
406
407
  }
@@ -410,7 +411,7 @@ class V {
410
411
  this.deletingThreadId = e.id, this.conversationError = "", this.renderPanel();
411
412
  try {
412
413
  if (await this.client.deleteConversation(e.id), this.conversations = this.conversations.filter((s) => s.id !== e.id), ((t = this.currentThread) == null ? void 0 : t.id) === e.id) {
413
- this.currentThread = null, this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1;
414
+ this.currentThread = null, this.messages = [], this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1;
414
415
  const s = this.conversations[0];
415
416
  s && await this.selectThread(s);
416
417
  }
@@ -449,7 +450,7 @@ class V {
449
450
  try {
450
451
  const n = this.getPageContextKey(this.getPageContext());
451
452
  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();
453
+ this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {}, created_at: this.activeQuestionStartedAt }), this.steps = [], this.thoughts = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
453
454
  const c = await this.client.streamQuestion(this.currentThread.id, e, this.answerAudience, r.signal);
454
455
  if (!c.ok) throw new Error(await z(c, "服务暂时无法回答,请稍后重试。"));
455
456
  if (!c.body) throw new Error("服务未返回有效的流式响应,请稍后重试。");
@@ -484,6 +485,10 @@ class V {
484
485
  this.upsertStep(t), this.renderExecutionSteps(!0);
485
486
  return;
486
487
  }
488
+ if (e === "thought") {
489
+ this.upsertThought(t), this.renderThinkingTimeline();
490
+ return;
491
+ }
487
492
  if (e === "delta") {
488
493
  const n = String((s = t.content) != null ? s : "");
489
494
  if (!n) return;
@@ -500,6 +505,12 @@ class V {
500
505
  return;
501
506
  }
502
507
  e.innerHTML = R(this.streaming);
508
+ const thinking = e.closest(".po-message") == null ? void 0 : e.closest(".po-message").querySelector(".po-thinking-process");
509
+ if (thinking) {
510
+ thinking.open = !1;
511
+ const status = thinking.querySelector("summary span");
512
+ status && (status.textContent = "已思考完成");
513
+ }
503
514
  const t = (r = this.panel) == null ? void 0 : r.querySelector(".po-messages");
504
515
  t && (t.scrollTop = t.scrollHeight);
505
516
  }
@@ -510,16 +521,20 @@ class V {
510
521
  const t = this.steps.findIndex((s) => s.id === e.id);
511
522
  this.steps = t === -1 ? [...this.steps, e] : this.steps.map((s) => s.id === e.id ? { ...s, ...e } : s);
512
523
  }
524
+ upsertThought(e) {
525
+ const t = this.thoughts.findIndex((s) => s.id === e.id);
526
+ this.thoughts = t === -1 ? [...this.thoughts, e] : this.thoughts.map((s) => s.id === e.id ? { ...s, ...e } : s);
527
+ }
513
528
  async loadAgentRun(e) {
514
529
  if (!(!this.client || !e)) {
515
530
  this.selectedAgentRunId = e, this.runLoading = !0, this.runLoadError = "", this.renderPanel();
516
531
  try {
517
532
  const t = await this.client.getAgentRun(e);
518
533
  if (this.selectedAgentRunId !== e) return;
519
- this.steps = t.steps;
534
+ this.steps = t.steps, this.thoughts = t.thoughts || [];
520
535
  } catch (t) {
521
536
  if (this.selectedAgentRunId !== e) return;
522
- this.steps = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
537
+ this.steps = [], this.thoughts = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
523
538
  } finally {
524
539
  this.selectedAgentRunId === e && (this.runLoading = !1, this.renderPanel());
525
540
  }
@@ -564,7 +579,7 @@ class V {
564
579
  return ["pending", "running"].includes(this.latestAnalysisStatus());
565
580
  }
566
581
  questionUnavailableReason() {
567
- return this.sourceLoadError && !this.sourceSnapshots.length ? "暂时无法读取项目共享代码包,请检查 PageOps 服务连接。" : this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
582
+ return this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "";
568
583
  }
569
584
  scheduleSourceRefresh() {
570
585
  this.stopSourceRefresh(), !(!this.sourceLoadError && !this.isProjectMemoryUpdating()) && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
@@ -575,7 +590,7 @@ class V {
575
590
  renderPanel(e = this.asking, t = !1) {
576
591
  var g;
577
592
  if (!this.panel) return;
578
- 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) => `
593
+ 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) => `
579
594
  <button type="button" data-audience="${o.value}" aria-pressed="${o.value === this.answerAudience}" ${this.asking ? "disabled" : ""}>${o.label}</button>
580
595
  `).join("");
581
596
  if (this.panel.innerHTML = `
@@ -683,14 +698,28 @@ class V {
683
698
  }).join("");
684
699
  }
685
700
  renderThinkingProcess() {
686
- if (!this.asking && !this.steps.length && !this.runLoading && !this.runLoadError) return "";
687
- const e = this.asking || this.steps.some((t) => t.status === "running"), t = this.asking ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成";
688
- return `<details class="po-thinking-process" ${e ? "open" : ""}><summary><strong>思考过程</strong><span>${t}</span></summary><div class="po-thinking-content">${this.renderSteps()}</div></details>`;
701
+ if (!this.asking && !this.thoughts.length && !this.runLoading && !this.runLoadError) return "";
702
+ const e = this.asking && !this.streaming, t = this.asking && !this.streaming ? "思考中" : this.runLoading ? "加载中" : this.runLoadError ? "加载失败" : "已思考完成", s = thinkingDuration(this.thoughts, this.activeQuestionStartedAt);
703
+ 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>`;
704
+ }
705
+ renderThinkingSteps() {
706
+ if (this.runLoading) return '<div class="po-thinking-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复思考过程</span></div>';
707
+ if (this.runLoadError) return `<div class="po-thinking-state failed">${l(this.runLoadError)}</div>`;
708
+ const e = this.thoughts.length ? this.thoughts : [{ id: "idle", kind: "thinking", label: "理解问题", status: "running", text: "正在判断问题并规划需要核对的信息。" }];
709
+ return e.map((t) => {
710
+ const s = String(t.kind || "thinking"), 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("");
711
+ if (s === "thinking") return `<div class="po-thinking-note ${t.status}">${r}<div><strong>${l(t.label)}</strong><p>${l(t.text || "")}</p>${n}</div></div>`;
712
+ return `<div class="po-thinking-activity ${t.status}">${r}<div class="po-thinking-activity-copy"><strong>${l(t.label)}</strong><span>${l(t.text || "")}</span>${n}${p}</div></div>`;
713
+ }).join("");
714
+ }
715
+ renderThinkingTimeline() {
716
+ var e;
717
+ (e = this.panel) == null || e.querySelectorAll(".po-thinking-content").forEach((t) => t.innerHTML = this.renderThinkingSteps());
689
718
  }
690
719
  renderExecutionSteps(e = !1) {
691
720
  var s, r;
692
721
  const t = (s = this.panel) == null ? void 0 : s.querySelector(".po-steps");
693
- if (t && (t.innerHTML = this.renderSteps(), this.panel == null || this.panel.querySelectorAll(".po-thinking-content").forEach((n) => n.innerHTML = this.renderSteps()), e)) {
722
+ if (t && (t.innerHTML = this.renderSteps(), e)) {
694
723
  const n = (r = this.panel) == null ? void 0 : r.querySelector(".po-trace > section");
695
724
  n && (n.scrollTop = n.scrollHeight);
696
725
  }
@@ -776,6 +805,25 @@ function messageTime(a) {
776
805
  const e = formatFullTimestamp(a);
777
806
  return e ? `<time class="po-message-time" datetime="${l(a)}">${e}</time>` : "";
778
807
  }
808
+ function thinkingDuration(a, e) {
809
+ const t = [...a].reverse().flatMap((s) => s.metrics || []).find((s) => /^耗时\s/.test(s));
810
+ if (t) return t.replace(/^耗时\s*/, "");
811
+ if (!e) return "";
812
+ const s = Date.now() - new Date(e).getTime();
813
+ if (!Number.isFinite(s) || s < 0) return "";
814
+ const r = Math.floor(s / 1e3), n = Math.floor(r / 60), c = r % 60;
815
+ return n ? `${n}m ${c}s` : `${c}s`;
816
+ }
817
+ function thinkingIcon(a) {
818
+ const e = {
819
+ 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"/>',
820
+ search: '<circle cx="11" cy="11" r="6"/><path d="m16 16 4 4"/>',
821
+ 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"/>',
822
+ tool: '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/>',
823
+ 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"/>'
824
+ }[a] || '<circle cx="12" cy="12" r="8"/><path d="m9 12 2 2 4-4"/>';
825
+ return `<svg class="po-thinking-icon" viewBox="0 0 24 24" aria-hidden="true">${e}</svg>`;
826
+ }
779
827
  function O(a) {
780
828
  return new Intl.DateTimeFormat("zh-CN", {
781
829
  timeZone: "Asia/Shanghai",
package/dist/types.d.ts CHANGED
@@ -48,6 +48,7 @@ export interface ConversationMessage {
48
48
  }
49
49
  export interface ExecutionStep {
50
50
  id: string;
51
+ kind?: 'thinking' | 'read' | 'search' | 'data' | 'tool' | 'status';
51
52
  title: string;
52
53
  status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
53
54
  summary?: string;
@@ -67,6 +68,20 @@ export interface AgentRunHistory {
67
68
  tool_call_count: number;
68
69
  active_skill?: string | null;
69
70
  steps: ExecutionStep[];
71
+ thoughts: AgentRunThought[];
72
+ }
73
+
74
+ export interface AgentRunThought {
75
+ id: string;
76
+ kind: 'thinking' | 'read' | 'search' | 'data' | 'tool' | 'status';
77
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
78
+ label: string;
79
+ text: string;
80
+ metrics?: string[];
81
+ details?: Array<{
82
+ label: string;
83
+ value: string;
84
+ }>;
70
85
  }
71
86
  export interface SourceSnapshot {
72
87
  id?: number | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageops/sdk",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "PageOps embeddable frontend SDK",
5
5
  "type": "module",
6
6
  "main": "dist/pageops-sdk.umd.cjs",