@pageops/sdk 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +2 -1
- package/dist/index.d.ts +10 -0
- package/dist/pageops-sdk.css +1 -1
- package/dist/pageops-sdk.es.js +235 -142
- package/dist/pageops-sdk.umd.cjs +35 -19
- package/dist/types.d.ts +17 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextSession, ConversationMessage, ConversationThread, PageOpsContext, PageOpsMountOptions, SourceSnapshot } from './types';
|
|
1
|
+
import type { AgentRunHistory, ContextSession, ConversationMessage, ConversationThread, PageOpsContext, PageOpsMountOptions, SourceSnapshot } from './types';
|
|
2
2
|
export declare class PageOpsClient {
|
|
3
3
|
private options;
|
|
4
4
|
constructor(options: PageOpsMountOptions);
|
|
@@ -7,6 +7,7 @@ export declare class PageOpsClient {
|
|
|
7
7
|
createConversation(contextSessionId: string, title?: string): Promise<ConversationThread>;
|
|
8
8
|
deleteConversation(threadId: string): Promise<void>;
|
|
9
9
|
listMessages(threadId: string): Promise<ConversationMessage[]>;
|
|
10
|
+
getAgentRun(runId: string): Promise<AgentRunHistory>;
|
|
10
11
|
listSources(): Promise<SourceSnapshot[]>;
|
|
11
12
|
uploadSource(file: File): Promise<SourceSnapshot>;
|
|
12
13
|
streamQuestion(threadId: string, question: string, signal?: AbortSignal): Promise<Response>;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,15 @@ declare class PageOpsSDKController {
|
|
|
12
12
|
private conversations;
|
|
13
13
|
private messages;
|
|
14
14
|
private steps;
|
|
15
|
+
private selectedAgentRunId;
|
|
16
|
+
private runLoading;
|
|
17
|
+
private runLoadError;
|
|
18
|
+
private copiedAgentRunId;
|
|
19
|
+
private copyFeedbackTimer;
|
|
15
20
|
private sourceSnapshots;
|
|
16
21
|
private sourceUploadStatus;
|
|
17
22
|
private sourceUploadError;
|
|
23
|
+
private sourceLoadError;
|
|
18
24
|
private sourceUploading;
|
|
19
25
|
private sourceRefreshTimer;
|
|
20
26
|
private streaming;
|
|
@@ -57,6 +63,9 @@ declare class PageOpsSDKController {
|
|
|
57
63
|
private updateStreamingMessage;
|
|
58
64
|
private resetAnswerState;
|
|
59
65
|
private upsertStep;
|
|
66
|
+
private loadAgentRun;
|
|
67
|
+
private copyAgentRunId;
|
|
68
|
+
private clearCopyFeedback;
|
|
60
69
|
private latestAnalysisStatus;
|
|
61
70
|
private isProjectMemoryUpdating;
|
|
62
71
|
private questionUnavailableReason;
|
|
@@ -64,6 +73,7 @@ declare class PageOpsSDKController {
|
|
|
64
73
|
private stopSourceRefresh;
|
|
65
74
|
private renderPanel;
|
|
66
75
|
private renderAnswerState;
|
|
76
|
+
private renderMessage;
|
|
67
77
|
private renderSourceUploader;
|
|
68
78
|
private renderSourceItem;
|
|
69
79
|
private renderSteps;
|
package/dist/pageops-sdk.css
CHANGED
|
@@ -1 +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{font:inherit}.pageops-sdk button{cursor:pointer}.po-fab{position:fixed;right:24px;bottom:24px;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}.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:flex;flex:0 0 auto;align-items:center;gap:8px}.po-audience>span{white-space:nowrap}.po-audience-options{display:grid;grid-template-columns:repeat(4,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.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-source-uploader{display:grid;gap:8px;border:1px solid var(--po-soft-border);border-radius:14px;background:#fff;padding:12px}.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:10px;background:#eff6ff;color:var(--po-primary-dark);padding:8px 10px;font-weight:750;cursor:pointer}.po-upload-button input{display:none}.po-upload-status{color:#166534!important}.po-upload-empty{color:#92400e!important}.po-source-list{display:grid;gap:6px}.po-source-item{display:grid;gap:3px;border:1px solid #dbeafe;border-radius:10px;background:#f8fbff;padding:8px}.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:14px;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:flex;justify-content:space-between;gap:8px;cursor:pointer}.po-step summary::marker{color:var(--po-muted)}.po-step pre{overflow:auto;margin:10px 0 0;border-radius:12px;background:#0f172a;color:#e2e8f0;padding:12px;font-size:12px;white-space:pre-wrap}@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(prefers-reduced-motion:reduce){.po-ai-spinner,.po-typing-cursor{animation:none}}
|
|
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{font:inherit}.pageops-sdk button{cursor:pointer}.po-fab{position:fixed;right:24px;bottom:24px;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}.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:flex;flex:0 0 auto;align-items:center;gap:8px}.po-audience>span{white-space:nowrap}.po-audience-options{display:grid;grid-template-columns:repeat(4,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-source-uploader{display:grid;gap:8px;border:1px solid var(--po-soft-border);border-radius:14px;background:#fff;padding:12px}.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:10px;background:#eff6ff;color:var(--po-primary-dark);padding:8px 10px;font-weight:750;cursor:pointer}.po-upload-button input{display:none}.po-upload-status{color:#166534!important}.po-upload-empty{color:#92400e!important}.po-source-list{display:grid;gap:6px}.po-source-item{display:grid;gap:3px;border:1px solid #dbeafe;border-radius:10px;background:#f8fbff;padding:8px}.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 18px}.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(prefers-reduced-motion:reduce){.po-ai-spinner,.po-step-dot,.po-typing-cursor{animation:none}}
|
package/dist/pageops-sdk.es.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var q = (a, e, t) => e in a ? L(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var r = (a, e, t) => q(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
class R {
|
|
5
5
|
constructor(e) {
|
|
6
6
|
this.options = e;
|
|
7
7
|
}
|
|
8
8
|
async createContext(e = ((i) => (i = ((t) => ((s) => (s = (t = this.options).getPageContext) == null ? void 0 : s.call(t))())()) != null ? i : {})()) {
|
|
9
|
-
var n,
|
|
9
|
+
var n, c, o;
|
|
10
10
|
return this.request("/context/session", {
|
|
11
11
|
method: "POST",
|
|
12
12
|
body: JSON.stringify({
|
|
@@ -14,8 +14,8 @@ class P {
|
|
|
14
14
|
env: this.options.env,
|
|
15
15
|
route: e.route,
|
|
16
16
|
url: (n = e.url) != null ? n : location.href,
|
|
17
|
-
title: (
|
|
18
|
-
menu_path: (
|
|
17
|
+
title: (c = e.title) != null ? c : document.title,
|
|
18
|
+
menu_path: (o = e.menuPath) != null ? o : [],
|
|
19
19
|
tenant_id: e.tenantId,
|
|
20
20
|
user_role: e.userRole,
|
|
21
21
|
build_version: e.buildVersion
|
|
@@ -39,6 +39,9 @@ class P {
|
|
|
39
39
|
async listMessages(e) {
|
|
40
40
|
return (await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}`)).messages;
|
|
41
41
|
}
|
|
42
|
+
async getAgentRun(e) {
|
|
43
|
+
return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`);
|
|
44
|
+
}
|
|
42
45
|
async listSources() {
|
|
43
46
|
return (await this.request(`/sources?project_id=${encodeURIComponent(this.options.appId)}`)).sources;
|
|
44
47
|
}
|
|
@@ -55,11 +58,11 @@ class P {
|
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
async request(e, t) {
|
|
58
|
-
var
|
|
59
|
-
const s = (t == null ? void 0 : t.body) instanceof FormData ? t.headers : { "content-type": "application/json", ...(
|
|
61
|
+
var c, o;
|
|
62
|
+
const s = (t == null ? void 0 : t.body) instanceof FormData ? t.headers : { "content-type": "application/json", ...(c = t == null ? void 0 : t.headers) != null ? c : {} }, i = await fetch(`${this.base()}${e}`, { ...t, headers: s });
|
|
60
63
|
if (i.status === 204) return;
|
|
61
64
|
const n = await i.json();
|
|
62
|
-
if (!i.ok) throw new Error((
|
|
65
|
+
if (!i.ok) throw new Error((o = n.message) != null ? o : "PageOps 请求失败");
|
|
63
66
|
return n;
|
|
64
67
|
}
|
|
65
68
|
base() {
|
|
@@ -67,40 +70,40 @@ class P {
|
|
|
67
70
|
return e.endsWith("/api") ? e : `${e}/api`;
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
|
-
async function
|
|
73
|
+
async function U(a, e) {
|
|
71
74
|
const t = await a.json().catch(() => null);
|
|
72
75
|
return typeof (t == null ? void 0 : t.message) == "string" && t.message.trim() ? t.message : e;
|
|
73
76
|
}
|
|
74
|
-
function
|
|
77
|
+
function x(a) {
|
|
75
78
|
return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
76
79
|
}
|
|
77
80
|
function v(a) {
|
|
78
|
-
return
|
|
81
|
+
return x(a).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
|
79
82
|
}
|
|
80
|
-
function
|
|
83
|
+
function F(a, e) {
|
|
81
84
|
const t = a[e], s = a[e + 1];
|
|
82
85
|
if (!(t != null && t.includes("|")) || !/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(s != null ? s : "")) return null;
|
|
83
86
|
const i = [];
|
|
84
87
|
let n = e;
|
|
85
88
|
for (; n < a.length && a[n].includes("|") && a[n].trim(); )
|
|
86
89
|
i.push(a[n]), n += 1;
|
|
87
|
-
const
|
|
88
|
-
return { html: `<table><thead><tr>${
|
|
90
|
+
const c = (g) => g.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((f) => v(f.trim())), o = c(i[0]).map((g) => `<th>${g}</th>`).join(""), p = i.slice(2).map((g) => `<tr>${c(g).map((f) => `<td>${f}</td>`).join("")}</tr>`).join("");
|
|
91
|
+
return { html: `<table><thead><tr>${o}</tr></thead><tbody>${p}</tbody></table>`, next: n };
|
|
89
92
|
}
|
|
90
|
-
function
|
|
93
|
+
function y(a) {
|
|
91
94
|
const e = a.split(`
|
|
92
95
|
`), t = [];
|
|
93
96
|
for (let s = 0; s < e.length; s += 1) {
|
|
94
97
|
const i = e[s];
|
|
95
98
|
if (i.trim().startsWith("```")) {
|
|
96
|
-
const
|
|
99
|
+
const c = [];
|
|
97
100
|
for (s += 1; s < e.length && !e[s].trim().startsWith("```"); )
|
|
98
|
-
|
|
99
|
-
t.push(`<pre><code>${
|
|
101
|
+
c.push(e[s]), s += 1;
|
|
102
|
+
t.push(`<pre><code>${x(c.join(`
|
|
100
103
|
`))}</code></pre>`);
|
|
101
104
|
continue;
|
|
102
105
|
}
|
|
103
|
-
const n =
|
|
106
|
+
const n = F(e, s);
|
|
104
107
|
if (n) {
|
|
105
108
|
t.push(n.html), s = n.next - 1;
|
|
106
109
|
continue;
|
|
@@ -109,33 +112,33 @@ function w(a) {
|
|
|
109
112
|
}
|
|
110
113
|
return t.join("");
|
|
111
114
|
}
|
|
112
|
-
async function
|
|
115
|
+
async function K(a, e) {
|
|
113
116
|
var n;
|
|
114
117
|
const t = a.getReader(), s = new TextDecoder();
|
|
115
118
|
let i = "";
|
|
116
119
|
for (; ; ) {
|
|
117
|
-
const { done:
|
|
118
|
-
if (
|
|
120
|
+
const { done: c, value: o } = await t.read();
|
|
121
|
+
if (c) {
|
|
119
122
|
i += s.decode();
|
|
120
123
|
break;
|
|
121
124
|
}
|
|
122
|
-
i += s.decode(
|
|
123
|
-
const
|
|
124
|
-
i = (n =
|
|
125
|
-
for (const
|
|
125
|
+
i += s.decode(o, { stream: !0 });
|
|
126
|
+
const p = i.split(/\r?\n\r?\n/);
|
|
127
|
+
i = (n = p.pop()) != null ? n : "";
|
|
128
|
+
for (const g of p) I(g, e);
|
|
126
129
|
}
|
|
127
|
-
i.trim() &&
|
|
130
|
+
i.trim() && I(i, e);
|
|
128
131
|
}
|
|
129
|
-
function
|
|
132
|
+
function I(a, e) {
|
|
130
133
|
var i, n;
|
|
131
134
|
const t = (i = a.match(/^event:\s*(.+)$/m)) == null ? void 0 : i[1], s = (n = a.match(/^data:\s*(.+)$/m)) == null ? void 0 : n[1];
|
|
132
135
|
t && s && e(t, JSON.parse(s));
|
|
133
136
|
}
|
|
134
|
-
class
|
|
137
|
+
class _ {
|
|
135
138
|
constructor(e, t = 16) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
r(this, "queue", []);
|
|
140
|
+
r(this, "timer", null);
|
|
141
|
+
r(this, "drainWaiters", []);
|
|
139
142
|
this.onChunk = e, this.interval = t;
|
|
140
143
|
}
|
|
141
144
|
enqueue(e) {
|
|
@@ -159,55 +162,61 @@ class K {
|
|
|
159
162
|
for (const e of this.drainWaiters.splice(0)) e();
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
|
-
const
|
|
165
|
+
const w = [
|
|
163
166
|
{ value: "product", label: "产品" },
|
|
164
167
|
{ value: "business", label: "业务" },
|
|
165
168
|
{ value: "developer", label: "研发" },
|
|
166
169
|
{ value: "tester", label: "测试" }
|
|
167
170
|
];
|
|
168
|
-
class
|
|
171
|
+
class j {
|
|
169
172
|
constructor() {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
173
|
+
r(this, "client", null);
|
|
174
|
+
r(this, "options", null);
|
|
175
|
+
r(this, "root", null);
|
|
176
|
+
r(this, "panel", null);
|
|
177
|
+
r(this, "context", null);
|
|
178
|
+
r(this, "contextKey", "");
|
|
179
|
+
r(this, "selectedPageKey", "");
|
|
180
|
+
r(this, "currentThread", null);
|
|
181
|
+
r(this, "conversations", []);
|
|
182
|
+
r(this, "messages", []);
|
|
183
|
+
r(this, "steps", []);
|
|
184
|
+
r(this, "selectedAgentRunId", "");
|
|
185
|
+
r(this, "runLoading", !1);
|
|
186
|
+
r(this, "runLoadError", "");
|
|
187
|
+
r(this, "copiedAgentRunId", "");
|
|
188
|
+
r(this, "copyFeedbackTimer", null);
|
|
189
|
+
r(this, "sourceSnapshots", []);
|
|
190
|
+
r(this, "sourceUploadStatus", "");
|
|
191
|
+
r(this, "sourceUploadError", "");
|
|
192
|
+
r(this, "sourceLoadError", "");
|
|
193
|
+
r(this, "sourceUploading", !1);
|
|
194
|
+
r(this, "sourceRefreshTimer", null);
|
|
195
|
+
r(this, "streaming", "");
|
|
196
|
+
r(this, "asking", !1);
|
|
197
|
+
r(this, "waitingForFirstContent", !1);
|
|
198
|
+
r(this, "abortController", null);
|
|
199
|
+
r(this, "activeRunId", 0);
|
|
200
|
+
r(this, "stoppedRunId", -1);
|
|
201
|
+
r(this, "answerStopped", !1);
|
|
202
|
+
r(this, "answerError", "");
|
|
203
|
+
r(this, "conversationError", "");
|
|
204
|
+
r(this, "deletingThreadId", "");
|
|
205
|
+
r(this, "streamFailure", "");
|
|
206
|
+
r(this, "streamDone", null);
|
|
207
|
+
r(this, "answerAudience", "business");
|
|
208
|
+
r(this, "audienceChanging", !1);
|
|
209
|
+
r(this, "typewriter", new _((e) => {
|
|
201
210
|
this.streaming += e, this.updateStreamingMessage();
|
|
202
211
|
}));
|
|
203
212
|
}
|
|
204
213
|
mount(e) {
|
|
205
214
|
var t;
|
|
206
|
-
this.unmount(), this.options = e, this.client = new
|
|
215
|
+
this.unmount(), this.options = e, this.client = new R(e), this.answerAudience = this.loadAnswerAudience(e.appId), this.root = document.createElement("div"), this.root.className = "pageops-sdk", ((t = e.container) != null ? t : document.body).appendChild(this.root), this.renderClosed();
|
|
207
216
|
}
|
|
208
217
|
unmount() {
|
|
209
218
|
var e;
|
|
210
|
-
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.sourceSnapshots = [], this.sourceUploadStatus = "", this.sourceUploadError = "", this.sourceUploading = !1, this.answerAudience = "business", this.audienceChanging = !1;
|
|
219
|
+
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.sourceUploadStatus = "", this.sourceUploadError = "", this.sourceLoadError = "", this.sourceUploading = !1, this.answerAudience = "business", this.audienceChanging = !1;
|
|
211
220
|
}
|
|
212
221
|
open() {
|
|
213
222
|
this.root && (this.root.innerHTML = "", this.panel = document.createElement("div"), this.panel.className = "po-panel", this.root.appendChild(this.panel), this.loadSources(), this.loadConversations(), this.renderPanel());
|
|
@@ -218,7 +227,7 @@ class F {
|
|
|
218
227
|
updateContext(e) {
|
|
219
228
|
if (!this.options) return;
|
|
220
229
|
const t = this.options.appId;
|
|
221
|
-
this.options = { ...this.options, ...e }, this.client = new
|
|
230
|
+
this.options = { ...this.options, ...e }, this.client = new R(this.options), this.options.appId !== t && (this.answerAudience = this.loadAnswerAudience(this.options.appId), this.currentThread = null, this.selectedPageKey = "", this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = ""), this.context = null, this.contextKey = "", this.renderPanel();
|
|
222
231
|
}
|
|
223
232
|
renderClosed() {
|
|
224
233
|
var e;
|
|
@@ -242,7 +251,7 @@ class F {
|
|
|
242
251
|
loadAnswerAudience(e) {
|
|
243
252
|
try {
|
|
244
253
|
const t = localStorage.getItem(this.answerAudienceStorageKey(e));
|
|
245
|
-
return
|
|
254
|
+
return w.some((s) => s.value === t) ? t : "business";
|
|
246
255
|
} catch (t) {
|
|
247
256
|
return "business";
|
|
248
257
|
}
|
|
@@ -257,9 +266,9 @@ class F {
|
|
|
257
266
|
async changeAnswerAudience(e) {
|
|
258
267
|
var s;
|
|
259
268
|
if (this.asking || this.audienceChanging) return;
|
|
260
|
-
const t = (s =
|
|
269
|
+
const t = (s = w.find((i) => i.value === e)) == null ? void 0 : s.value;
|
|
261
270
|
if (!(!t || t === this.answerAudience)) {
|
|
262
|
-
this.answerAudience = t, this.saveAnswerAudience(), this.audienceChanging = !0, this.context = null, this.contextKey = "", this.selectedPageKey = "", this.currentThread = null, this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = !1, this.conversationError = "", this.renderPanel();
|
|
271
|
+
this.answerAudience = t, this.saveAnswerAudience(), this.audienceChanging = !0, 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.conversationError = "", this.renderPanel();
|
|
263
272
|
try {
|
|
264
273
|
await this.newConversation();
|
|
265
274
|
} catch (i) {
|
|
@@ -270,21 +279,21 @@ class F {
|
|
|
270
279
|
}
|
|
271
280
|
}
|
|
272
281
|
getPageContextKey(e) {
|
|
273
|
-
var t, s, i, n,
|
|
282
|
+
var t, s, i, n, c;
|
|
274
283
|
return JSON.stringify([
|
|
275
284
|
(t = e.route) != null ? t : "",
|
|
276
285
|
(s = e.url) != null ? s : location.href,
|
|
277
286
|
(i = e.title) != null ? i : document.title,
|
|
278
287
|
(n = e.menuPath) != null ? n : [],
|
|
279
|
-
(
|
|
288
|
+
(c = e.userRole) != null ? c : ""
|
|
280
289
|
]);
|
|
281
290
|
}
|
|
282
291
|
async loadSources() {
|
|
283
292
|
if (this.client) {
|
|
284
293
|
try {
|
|
285
|
-
this.sourceSnapshots = await this.client.listSources(), this.
|
|
294
|
+
this.sourceSnapshots = await this.client.listSources(), this.sourceLoadError = "";
|
|
286
295
|
} catch (e) {
|
|
287
|
-
this.
|
|
296
|
+
this.sourceLoadError = "源码包状态加载失败,连接恢复后将自动重试。";
|
|
288
297
|
}
|
|
289
298
|
this.scheduleSourceRefresh(), this.renderPanel();
|
|
290
299
|
}
|
|
@@ -299,7 +308,10 @@ class F {
|
|
|
299
308
|
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();
|
|
300
309
|
}
|
|
301
310
|
async selectThread(e) {
|
|
302
|
-
|
|
311
|
+
if (!this.client) return;
|
|
312
|
+
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();
|
|
313
|
+
const t = [...this.messages].reverse().map(T).find(Boolean);
|
|
314
|
+
t && await this.loadAgentRun(t);
|
|
303
315
|
}
|
|
304
316
|
async deleteConversation(e) {
|
|
305
317
|
var t;
|
|
@@ -307,7 +319,7 @@ class F {
|
|
|
307
319
|
this.deletingThreadId = e.id, this.conversationError = "", this.renderPanel();
|
|
308
320
|
try {
|
|
309
321
|
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) {
|
|
310
|
-
this.currentThread = null, this.messages = [], this.steps = [], this.streaming = "", this.answerError = "", this.answerStopped = !1;
|
|
322
|
+
this.currentThread = null, this.messages = [], this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.streaming = "", this.answerError = "", this.answerStopped = !1;
|
|
311
323
|
const s = this.conversations[0];
|
|
312
324
|
s && await this.selectThread(s);
|
|
313
325
|
}
|
|
@@ -343,18 +355,18 @@ class F {
|
|
|
343
355
|
try {
|
|
344
356
|
const n = this.getPageContextKey(this.getPageContext());
|
|
345
357
|
if (this.currentThread && this.selectedPageKey && this.selectedPageKey !== n && (this.currentThread = null), this.currentThread || await this.newConversation(), !this.currentThread) throw new Error("无法创建问答会话,请稍后重试。");
|
|
346
|
-
this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {} }), this.steps = [], this.renderPanel();
|
|
347
|
-
const
|
|
348
|
-
if (!
|
|
349
|
-
if (!
|
|
350
|
-
if (await
|
|
358
|
+
this.messages.push({ id: `local-${Date.now()}`, role: "user", content: e, metadata_json: {} }), this.steps = [], this.selectedAgentRunId = "", this.runLoadError = "", this.renderPanel();
|
|
359
|
+
const c = await this.client.streamQuestion(this.currentThread.id, e, i.signal);
|
|
360
|
+
if (!c.ok) throw new Error(await U(c, "服务暂时无法回答,请稍后重试。"));
|
|
361
|
+
if (!c.body) throw new Error("服务未返回有效的流式响应,请稍后重试。");
|
|
362
|
+
if (await K(c.body, (o, p) => this.handleStreamEvent(o, p)), s === this.stoppedRunId) throw new DOMException("输出已停止", "AbortError");
|
|
351
363
|
if (this.streamFailure) throw new Error(this.streamFailure);
|
|
352
364
|
if (!this.streamDone) throw new Error("服务响应意外中断,请稍后重试。");
|
|
353
365
|
if (await this.typewriter.drain(), s === this.stoppedRunId) throw new DOMException("输出已停止", "AbortError");
|
|
354
366
|
await this.selectThread(this.currentThread);
|
|
355
367
|
} catch (n) {
|
|
356
368
|
if (s !== this.activeRunId) return;
|
|
357
|
-
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",
|
|
369
|
+
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 }));
|
|
358
370
|
} finally {
|
|
359
371
|
if (s !== this.activeRunId) return;
|
|
360
372
|
this.asking = !1, this.waitingForFirstContent = !1, this.abortController === i && (this.abortController = null), this.renderPanel(!0);
|
|
@@ -393,7 +405,7 @@ class F {
|
|
|
393
405
|
this.renderPanel();
|
|
394
406
|
return;
|
|
395
407
|
}
|
|
396
|
-
e.innerHTML =
|
|
408
|
+
e.innerHTML = y(this.streaming);
|
|
397
409
|
const t = (i = this.panel) == null ? void 0 : i.querySelector(".po-messages");
|
|
398
410
|
t && (t.scrollTop = t.scrollHeight);
|
|
399
411
|
}
|
|
@@ -404,6 +416,43 @@ class F {
|
|
|
404
416
|
const t = this.steps.findIndex((s) => s.id === e.id);
|
|
405
417
|
this.steps = t === -1 ? [...this.steps, e] : this.steps.map((s) => s.id === e.id ? { ...s, ...e } : s);
|
|
406
418
|
}
|
|
419
|
+
async loadAgentRun(e) {
|
|
420
|
+
if (!(!this.client || !e)) {
|
|
421
|
+
this.selectedAgentRunId = e, this.runLoading = !0, this.runLoadError = "", this.renderPanel();
|
|
422
|
+
try {
|
|
423
|
+
const t = await this.client.getAgentRun(e);
|
|
424
|
+
if (this.selectedAgentRunId !== e) return;
|
|
425
|
+
this.steps = t.steps;
|
|
426
|
+
} catch (t) {
|
|
427
|
+
if (this.selectedAgentRunId !== e) return;
|
|
428
|
+
this.steps = [], this.runLoadError = t instanceof Error ? t.message : "执行过程加载失败";
|
|
429
|
+
} finally {
|
|
430
|
+
this.selectedAgentRunId === e && (this.runLoading = !1, this.renderPanel());
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async copyAgentRunId(e) {
|
|
435
|
+
var t;
|
|
436
|
+
if (e) {
|
|
437
|
+
try {
|
|
438
|
+
if ((t = navigator.clipboard) != null && t.writeText)
|
|
439
|
+
await navigator.clipboard.writeText(e);
|
|
440
|
+
else {
|
|
441
|
+
const s = document.createElement("textarea");
|
|
442
|
+
s.value = e, s.style.position = "fixed", s.style.opacity = "0", document.body.appendChild(s), s.select(), document.execCommand("copy"), s.remove();
|
|
443
|
+
}
|
|
444
|
+
this.copiedAgentRunId = e;
|
|
445
|
+
} catch (s) {
|
|
446
|
+
this.copiedAgentRunId = `error:${e}`;
|
|
447
|
+
}
|
|
448
|
+
this.clearCopyFeedback(!1), this.copyFeedbackTimer = setTimeout(() => {
|
|
449
|
+
this.copiedAgentRunId = "", this.copyFeedbackTimer = null, this.renderPanel();
|
|
450
|
+
}, 1800), this.renderPanel();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
clearCopyFeedback(e = !0) {
|
|
454
|
+
this.copyFeedbackTimer && clearTimeout(this.copyFeedbackTimer), this.copyFeedbackTimer = null, e && (this.copiedAgentRunId = "");
|
|
455
|
+
}
|
|
407
456
|
latestAnalysisStatus() {
|
|
408
457
|
var e, t, s;
|
|
409
458
|
return String((s = (t = (e = this.sourceSnapshots[0]) == null ? void 0 : e.metadata) == null ? void 0 : t.analysis_status) != null ? s : "");
|
|
@@ -412,121 +461,165 @@ class F {
|
|
|
412
461
|
return ["pending", "running"].includes(this.latestAnalysisStatus());
|
|
413
462
|
}
|
|
414
463
|
questionUnavailableReason() {
|
|
415
|
-
return this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
|
|
464
|
+
return this.sourceLoadError && !this.sourceSnapshots.length ? "暂时无法读取项目共享代码包,请检查 PageOps 服务连接。" : this.sourceSnapshots.length ? this.isProjectMemoryUpdating() ? "项目记忆正在更新,完成前暂不能问答。" : this.latestAnalysisStatus() === "failed" ? "项目记忆更新失败,请重新上传或重新索引。" : "" : "请先上传代码包后再提问。";
|
|
416
465
|
}
|
|
417
466
|
scheduleSourceRefresh() {
|
|
418
|
-
this.stopSourceRefresh(), this.isProjectMemoryUpdating() && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
|
|
467
|
+
this.stopSourceRefresh(), !(!this.sourceLoadError && !this.isProjectMemoryUpdating()) && (this.sourceRefreshTimer = setTimeout(() => void this.loadSources(), 1500));
|
|
419
468
|
}
|
|
420
469
|
stopSourceRefresh() {
|
|
421
470
|
this.sourceRefreshTimer && clearTimeout(this.sourceRefreshTimer), this.sourceRefreshTimer = null;
|
|
422
471
|
}
|
|
423
472
|
renderPanel(e = this.asking) {
|
|
424
473
|
if (!this.panel) return;
|
|
425
|
-
const t = this.questionUnavailableReason(), s = t || (this.asking ? "回答生成中,请稍候" : "请输入页面分析问题,Enter 发送,Shift + Enter 换行"), i = !!(t || this.asking), n = t ? '<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>',
|
|
426
|
-
<button type="button" data-audience="${
|
|
474
|
+
const t = this.questionUnavailableReason(), s = t || (this.asking ? "回答生成中,请稍候" : "请输入页面分析问题,Enter 发送,Shift + Enter 换行"), i = !!(t || this.asking), n = t ? '<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>', c = w.map((o) => `
|
|
475
|
+
<button type="button" data-audience="${o.value}" aria-pressed="${o.value === this.answerAudience}" ${this.asking || this.audienceChanging ? "disabled" : ""}>${o.label}</button>
|
|
427
476
|
`).join("");
|
|
428
477
|
if (this.panel.innerHTML = `
|
|
429
478
|
<aside class="po-sidebar">
|
|
430
479
|
<div class="po-brand"><div class="po-logo"></div><div><strong>PageOps 问答</strong><span>页面工程专家</span></div></div>
|
|
431
480
|
<button class="po-new" data-action="new" ${this.asking ? "disabled" : ""}>+ 新建问答</button>
|
|
432
481
|
<input class="po-search" placeholder="搜索问答" />
|
|
433
|
-
${this.conversationError ? `<p class="po-conversation-error" role="alert">${
|
|
434
|
-
<div class="po-thread-list">${this.conversations.map((
|
|
435
|
-
var
|
|
482
|
+
${this.conversationError ? `<p class="po-conversation-error" role="alert">${l(this.conversationError)}</p>` : ""}
|
|
483
|
+
<div class="po-thread-list">${this.conversations.map((o) => {
|
|
484
|
+
var p;
|
|
436
485
|
return `
|
|
437
|
-
<div class="po-thread-row ${
|
|
438
|
-
<button class="po-thread" data-thread="${
|
|
439
|
-
<strong>${
|
|
486
|
+
<div class="po-thread-row ${o.id === ((p = this.currentThread) == null ? void 0 : p.id) ? "active" : ""}">
|
|
487
|
+
<button class="po-thread" data-thread="${l(o.id)}" ${this.asking ? "disabled" : ""}>
|
|
488
|
+
<strong>${l(o.title)}</strong><span>${k(o.created_at)}</span>
|
|
440
489
|
</button>
|
|
441
|
-
<button class="po-thread-delete" type="button" data-delete-thread="${
|
|
490
|
+
<button class="po-thread-delete" type="button" data-delete-thread="${l(o.id)}" aria-label="删除会话:${l(o.title)}" title="删除会话" ${this.asking || this.deletingThreadId === o.id ? "disabled" : ""}><span class="po-trash-icon" aria-hidden="true"></span></button>
|
|
442
491
|
</div>`;
|
|
443
492
|
}).join("")}</div>
|
|
444
493
|
</aside>
|
|
445
494
|
<main class="po-chat">
|
|
446
|
-
<header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread ?
|
|
495
|
+
<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="回答角色">${c}</div></div></header>
|
|
447
496
|
<section class="po-messages">
|
|
448
|
-
${this.messages.map((
|
|
497
|
+
${this.messages.map((o) => this.renderMessage(o)).join("")}
|
|
449
498
|
${this.renderAnswerState()}
|
|
450
499
|
</section>
|
|
451
|
-
<form class="po-composer"><textarea ${i ? "disabled" : ""} placeholder="${
|
|
500
|
+
<form class="po-composer"><textarea ${i ? "disabled" : ""} placeholder="${l(s)}"></textarea>${n}</form>
|
|
452
501
|
</main>
|
|
453
502
|
<aside class="po-trace"><header><h2>执行过程</h2><button data-action="close">×</button></header><section>${this.renderSourceUploader()}${this.renderSteps()}</section></aside>
|
|
454
503
|
`, this.bindPanelEvents(), e) {
|
|
455
|
-
const
|
|
456
|
-
|
|
504
|
+
const o = this.panel.querySelector(".po-messages");
|
|
505
|
+
o && (o.scrollTop = o.scrollHeight);
|
|
457
506
|
}
|
|
458
507
|
}
|
|
459
508
|
renderAnswerState() {
|
|
460
|
-
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>${
|
|
509
|
+
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>${y(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>` : "", i = this.answerStopped ? '<div class="po-stream-stopped" role="status">已停止输出</div>' : "";
|
|
461
510
|
return `${e}${t}${i}${s}`;
|
|
462
511
|
}
|
|
512
|
+
renderMessage(e) {
|
|
513
|
+
const t = T(e), s = t && t === this.selectedAgentRunId, i = this.copiedAgentRunId === t, n = this.copiedAgentRunId === `error:${t}`, c = e.role === "assistant" && t ? `<footer class="po-answer-meta ${s ? "selected" : ""}">
|
|
514
|
+
<span class="po-run-id" title="${l(t)}">问答流水号 <code>${l(t)}</code></span>
|
|
515
|
+
<button type="button" data-copy-run="${l(t)}">${i ? "已复制" : n ? "复制失败" : "复制流水号"}</button>
|
|
516
|
+
<button type="button" data-view-run="${l(t)}" aria-pressed="${s}">${s ? "正在查看" : "查看执行过程"}</button>
|
|
517
|
+
</footer>` : "";
|
|
518
|
+
return `<article class="po-message ${e.role} ${s ? "run-selected" : ""}" data-message="${l(e.id)}">
|
|
519
|
+
<b>${e.role === "user" ? "你" : "PageOps 分析"}</b>
|
|
520
|
+
<div>${e.role === "assistant" ? y(e.content) : l(e.content)}</div>
|
|
521
|
+
${c}
|
|
522
|
+
</article>`;
|
|
523
|
+
}
|
|
463
524
|
renderSourceUploader() {
|
|
525
|
+
const e = this.sourceLoadError ? "暂时无法读取项目共享代码包,连接恢复后将自动重试。" : "当前项目暂无代码包,请先上传后再提问。";
|
|
464
526
|
return `
|
|
465
527
|
<div class="po-source-uploader">
|
|
466
528
|
<strong>源码包</strong>
|
|
467
|
-
<p
|
|
529
|
+
<p>同一项目的所有回答角色共享代码包。上传 zip、tar、tar.gz 或 tgz 后,PageOps 将基于代码证据回答问题。</p>
|
|
468
530
|
<label class="po-upload-button">
|
|
469
531
|
<span>${this.sourceUploading ? "上传中..." : "选择代码包"}</span>
|
|
470
532
|
<input type="file" accept=".zip,.tar,.gz,.tgz" data-action="upload-source" ${this.sourceUploading ? "disabled" : ""} />
|
|
471
533
|
</label>
|
|
472
|
-
${this.sourceUploadStatus ? `<p class="po-upload-status">${
|
|
473
|
-
${this.sourceSnapshots.length ? `<div class="po-source-list">${this.sourceSnapshots.map((
|
|
474
|
-
${this.
|
|
534
|
+
${this.sourceUploadStatus ? `<p class="po-upload-status">${l(this.sourceUploadStatus)}</p>` : ""}
|
|
535
|
+
${this.sourceSnapshots.length ? `<div class="po-source-list">${this.sourceSnapshots.map((t) => this.renderSourceItem(t)).join("")}</div>` : `<p class="po-upload-empty">${e}</p>`}
|
|
536
|
+
${this.sourceLoadError ? `<p class="po-upload-error">${l(this.sourceLoadError)}</p>` : ""}
|
|
537
|
+
${this.sourceUploadError ? `<p class="po-upload-error">${l(this.sourceUploadError)}</p>` : ""}
|
|
475
538
|
</div>
|
|
476
539
|
`;
|
|
477
540
|
}
|
|
478
541
|
renderSourceItem(e) {
|
|
479
|
-
var
|
|
480
|
-
const t = e.filename || "未命名代码包", s = e.created_at ?
|
|
481
|
-
return `<article class="po-source-item"><strong>${
|
|
542
|
+
var o, p, g;
|
|
543
|
+
const t = e.filename || "未命名代码包", s = e.created_at ? k(e.created_at) : "刚刚上传", i = O(e.archive_bytes || e.total_bytes || 0), n = String((p = (o = e.metadata) == null ? void 0 : o.analysis_status) != null ? p : "unknown"), c = (g = { pending: "项目记忆等待更新", running: "项目记忆更新中", ready: "项目记忆已就绪", failed: "项目记忆更新失败" }[n]) != null ? g : "项目记忆状态未知";
|
|
544
|
+
return `<article class="po-source-item"><strong>${l(t)}</strong><span>${l(s)} · ${l(i)}</span><span>${l(c)}</span></article>`;
|
|
482
545
|
}
|
|
483
546
|
renderSteps() {
|
|
484
|
-
return (this.steps.length ? this.steps : [{ id: "idle", title: "等待任务", status: "pending",
|
|
485
|
-
var
|
|
486
|
-
|
|
547
|
+
return this.runLoading ? '<div class="po-trace-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复本次执行过程</span></div>' : this.runLoadError ? `<div class="po-trace-state failed" role="alert">${l(this.runLoadError)}</div>` : (this.steps.length ? this.steps : [{ id: "idle", title: "等待任务", status: "pending", summary: "发送问题后,这里会展示完整分析过程。" }]).map((t) => {
|
|
548
|
+
var c, o, p;
|
|
549
|
+
const s = (c = t.metrics) != null && c.length ? `<div class="po-step-metrics">${t.metrics.map((g) => `<span>${l(g)}</span>`).join("")}</div>` : "", i = (o = t.details) != null && o.length ? `<div class="po-step-details">${t.details.map((g) => `<div><span>${l(g.label)}</span><p>${l(g.value)}</p></div>`).join("")}</div>` : "", n = !!(s || i);
|
|
550
|
+
return `<details class="po-step ${t.status}" ${t.status === "running" || t.status === "failed" ? "open" : ""} ${n ? "" : "data-static"}>
|
|
551
|
+
<summary>
|
|
552
|
+
<span class="po-step-dot" aria-hidden="true"></span>
|
|
553
|
+
<span class="po-step-copy"><strong>${l(t.title)}</strong><small>${l((p = t.summary) != null ? p : "")}</small></span>
|
|
554
|
+
<span class="po-step-status">${D(t.status)}</span>
|
|
555
|
+
</summary>
|
|
556
|
+
${s}${i}
|
|
557
|
+
</details>`;
|
|
487
558
|
}).join("");
|
|
488
559
|
}
|
|
489
560
|
bindPanelEvents() {
|
|
490
|
-
var e, t, s, i, n,
|
|
491
|
-
(t = (e = this.panel) == null ? void 0 : e.querySelector('[data-action="new"]')) == null || t.addEventListener("click", () => void this.newConversation()), (i = (s = this.panel) == null ? void 0 : s.querySelector('[data-action="close"]')) == null || i.addEventListener("click", () => this.close()), (
|
|
492
|
-
|
|
561
|
+
var e, t, s, i, n, c, o, p, g, f, b, $, S, E, A, C, P;
|
|
562
|
+
(t = (e = this.panel) == null ? void 0 : e.querySelector('[data-action="new"]')) == null || t.addEventListener("click", () => void this.newConversation()), (i = (s = this.panel) == null ? void 0 : s.querySelector('[data-action="close"]')) == null || i.addEventListener("click", () => this.close()), (c = (n = this.panel) == null ? void 0 : n.querySelector('[data-action="stop-answer"]')) == null || c.addEventListener("click", () => this.cancelActiveAnswer(!0)), (o = this.panel) == null || o.querySelectorAll("[data-audience]").forEach((d) => {
|
|
563
|
+
d.addEventListener("click", () => {
|
|
493
564
|
var h;
|
|
494
|
-
return void this.changeAnswerAudience((h =
|
|
565
|
+
return void this.changeAnswerAudience((h = d.dataset.audience) != null ? h : "");
|
|
495
566
|
});
|
|
496
|
-
}), (
|
|
497
|
-
var
|
|
498
|
-
const h = (
|
|
567
|
+
}), (g = (p = this.panel) == null ? void 0 : p.querySelector('[data-action="upload-source"]')) == null || g.addEventListener("change", (d) => {
|
|
568
|
+
var u;
|
|
569
|
+
const h = (u = d.target.files) == null ? void 0 : u[0];
|
|
499
570
|
h && this.uploadSource(h);
|
|
500
|
-
}), (f = this.panel) == null || f.querySelectorAll("[data-thread]").forEach((
|
|
501
|
-
|
|
502
|
-
const h = this.conversations.find((
|
|
571
|
+
}), (f = this.panel) == null || f.querySelectorAll("[data-thread]").forEach((d) => {
|
|
572
|
+
d.addEventListener("click", () => {
|
|
573
|
+
const h = this.conversations.find((u) => u.id === d.dataset.thread);
|
|
503
574
|
h && this.selectThread(h);
|
|
504
575
|
});
|
|
505
|
-
}), (b = this.panel) == null || b.querySelectorAll("[data-delete-thread]").forEach((
|
|
506
|
-
|
|
576
|
+
}), (b = this.panel) == null || b.querySelectorAll("[data-delete-thread]").forEach((d) => {
|
|
577
|
+
d.addEventListener("click", (h) => {
|
|
507
578
|
h.stopPropagation();
|
|
508
|
-
const
|
|
509
|
-
|
|
579
|
+
const u = this.conversations.find((m) => m.id === d.dataset.deleteThread);
|
|
580
|
+
u && this.deleteConversation(u);
|
|
510
581
|
});
|
|
511
|
-
}), ($ =
|
|
582
|
+
}), ($ = this.panel) == null || $.querySelectorAll("[data-view-run]").forEach((d) => {
|
|
583
|
+
d.addEventListener("click", (h) => {
|
|
584
|
+
var u;
|
|
585
|
+
h.stopPropagation(), this.loadAgentRun((u = d.dataset.viewRun) != null ? u : "");
|
|
586
|
+
});
|
|
587
|
+
}), (S = this.panel) == null || S.querySelectorAll("[data-copy-run]").forEach((d) => {
|
|
588
|
+
d.addEventListener("click", (h) => {
|
|
589
|
+
var u;
|
|
590
|
+
h.stopPropagation(), this.copyAgentRunId((u = d.dataset.copyRun) != null ? u : "");
|
|
591
|
+
});
|
|
592
|
+
}), (A = (E = this.panel) == null ? void 0 : E.querySelector("form")) == null || A.addEventListener("submit", (d) => {
|
|
512
593
|
var m;
|
|
513
|
-
|
|
514
|
-
const h = (m = this.panel) == null ? void 0 : m.querySelector("textarea"),
|
|
515
|
-
|
|
516
|
-
}), (
|
|
517
|
-
var
|
|
518
|
-
const h =
|
|
519
|
-
h.key === "Enter" && !h.shiftKey && (h.preventDefault(), (m = (
|
|
594
|
+
d.preventDefault();
|
|
595
|
+
const h = (m = this.panel) == null ? void 0 : m.querySelector("textarea"), u = h == null ? void 0 : h.value.trim();
|
|
596
|
+
u && (h.value = "", this.ask(u));
|
|
597
|
+
}), (P = (C = this.panel) == null ? void 0 : C.querySelector("textarea")) == null || P.addEventListener("keydown", (d) => {
|
|
598
|
+
var u, m;
|
|
599
|
+
const h = d;
|
|
600
|
+
h.key === "Enter" && !h.shiftKey && (h.preventDefault(), (m = (u = this.panel) == null ? void 0 : u.querySelector("form")) == null || m.requestSubmit());
|
|
520
601
|
});
|
|
521
602
|
}
|
|
522
603
|
}
|
|
523
|
-
function
|
|
604
|
+
function l(a) {
|
|
524
605
|
return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
525
606
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
607
|
+
function T(a) {
|
|
608
|
+
var t;
|
|
609
|
+
const e = (t = a.metadata_json) == null ? void 0 : t.agent_run_id;
|
|
610
|
+
return typeof e == "string" ? e : "";
|
|
611
|
+
}
|
|
612
|
+
function k(a) {
|
|
613
|
+
return new Intl.DateTimeFormat("zh-CN", {
|
|
614
|
+
timeZone: "Asia/Shanghai",
|
|
615
|
+
month: "2-digit",
|
|
616
|
+
day: "2-digit",
|
|
617
|
+
hour: "2-digit",
|
|
618
|
+
minute: "2-digit",
|
|
619
|
+
hourCycle: "h23"
|
|
620
|
+
}).format(new Date(a));
|
|
528
621
|
}
|
|
529
|
-
function
|
|
622
|
+
function O(a) {
|
|
530
623
|
if (!a) return "0 B";
|
|
531
624
|
const e = ["B", "KB", "MB", "GB"];
|
|
532
625
|
let t = a, s = 0;
|
|
@@ -534,10 +627,10 @@ function _(a) {
|
|
|
534
627
|
t /= 1024, s += 1;
|
|
535
628
|
return `${t >= 10 || s === 0 ? t.toFixed(0) : t.toFixed(1)} ${e[s]}`;
|
|
536
629
|
}
|
|
537
|
-
function
|
|
630
|
+
function D(a) {
|
|
538
631
|
return { pending: "等待中", running: "执行中", completed: "已完成", failed: "失败", cancelled: "已停止" }[a];
|
|
539
632
|
}
|
|
540
|
-
const
|
|
633
|
+
const W = new j();
|
|
541
634
|
export {
|
|
542
|
-
|
|
635
|
+
W as PageOpsSDK
|
|
543
636
|
};
|
package/dist/pageops-sdk.umd.cjs
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
(function(m
|
|
2
|
-
`),t=[];for(let s=0;s<e.length;s+=1){const i=e[s];if(i.trim().startsWith("```")){const
|
|
3
|
-
`))}</code></pre>`);continue}const n=R(e,s);if(n){t.push(n.html),s=n.next-1;continue}i.startsWith("### ")?t.push(`<h4>${y(i.slice(4))}</h4>`):i.startsWith("## ")?t.push(`<h3>${y(i.slice(3))}</h3>`):i.startsWith("# ")?t.push(`<h2>${y(i.slice(2))}</h2>`):i.startsWith("- ")?t.push(`<li>${y(i.slice(2))}</li>`):i.trim()?t.push(`<p>${y(i)}</p>`):t.push("<br>")}return t.join("")}async function U(o,e){var n;const t=o.getReader(),s=new TextDecoder;let i="";for(;;){const{done:l,value:r}=await t.read();if(l){i+=s.decode();break}i+=s.decode(r,{stream:!0});const d=i.split(/\r?\n\r?\n/);i=(n=d.pop())!=null?n:"";for(const g of d)P(g,e)}i.trim()&&P(i,e)}function P(o,e){var i,n;const t=(i=o.match(/^event:\s*(.+)$/m))==null?void 0:i[1],s=(n=o.match(/^data:\s*(.+)$/m))==null?void 0:n[1];t&&s&&e(t,JSON.parse(s))}class q{constructor(e,t=16){a(this,"queue",[]);a(this,"timer",null);a(this,"drainWaiters",[]);this.onChunk=e,this.interval=t}enqueue(e){this.queue.push(...Array.from(e)),this.timer||this.tick()}async drain(){!this.timer&&!this.queue.length||await new Promise(e=>this.drainWaiters.push(e))}clear(){this.timer&&clearTimeout(this.timer),this.timer=null,this.queue=[],this.resolveDrainWaiters()}tick(){const e=Math.max(1,Math.ceil(this.queue.length/90)),t=this.queue.splice(0,e).join("");if(t&&this.onChunk(t),!this.queue.length){this.timer=null,this.resolveDrainWaiters();return}this.timer=setTimeout(()=>this.tick(),this.interval)}resolveDrainWaiters(){for(const e of this.drainWaiters.splice(0))e()}}const $=[{value:"product",label:"产品"},{value:"business",label:"业务"},{value:"developer",label:"研发"},{value:"tester",label:"测试"}];class K{constructor(){a(this,"client",null);a(this,"options",null);a(this,"root",null);a(this,"panel",null);a(this,"context",null);a(this,"contextKey","");a(this,"selectedPageKey","");a(this,"currentThread",null);a(this,"conversations",[]);a(this,"messages",[]);a(this,"steps",[]);a(this,"sourceSnapshots",[]);a(this,"sourceUploadStatus","");a(this,"sourceUploadError","");a(this,"sourceUploading",!1);a(this,"sourceRefreshTimer",null);a(this,"streaming","");a(this,"asking",!1);a(this,"waitingForFirstContent",!1);a(this,"abortController",null);a(this,"activeRunId",0);a(this,"stoppedRunId",-1);a(this,"answerStopped",!1);a(this,"answerError","");a(this,"conversationError","");a(this,"deletingThreadId","");a(this,"streamFailure","");a(this,"streamDone",null);a(this,"answerAudience","business");a(this,"audienceChanging",!1);a(this,"typewriter",new q(e=>{this.streaming+=e,this.updateStreamingMessage()}))}mount(e){var t;this.unmount(),this.options=e,this.client=new u(e),this.answerAudience=this.loadAnswerAudience(e.appId),this.root=document.createElement("div"),this.root.className="pageops-sdk",((t=e.container)!=null?t:document.body).appendChild(this.root),this.renderClosed()}unmount(){var e;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.sourceSnapshots=[],this.sourceUploadStatus="",this.sourceUploadError="",this.sourceUploading=!1,this.answerAudience="business",this.audienceChanging=!1}open(){this.root&&(this.root.innerHTML="",this.panel=document.createElement("div"),this.panel.className="po-panel",this.root.appendChild(this.panel),this.loadSources(),this.loadConversations(),this.renderPanel())}close(){this.stopSourceRefresh(),this.cancelActiveAnswer(!1),this.renderClosed()}updateContext(e){if(!this.options)return;const t=this.options.appId;this.options={...this.options,...e},this.client=new u(this.options),this.options.appId!==t&&(this.answerAudience=this.loadAnswerAudience(this.options.appId),this.currentThread=null,this.selectedPageKey="",this.messages=[],this.steps=[]),this.context=null,this.contextKey="",this.renderPanel()}renderClosed(){var e;this.root&&(this.root.innerHTML='<button class="po-fab" type="button">多轮问答</button>',(e=this.root.querySelector("button"))==null||e.addEventListener("click",()=>this.open()))}async ensureContext(){if(!this.client||!this.options)throw new Error("PageOps SDK 未初始化");const e=this.getPageContext(),t=this.getPageContextKey(e);return this.context&&this.contextKey===t?this.context:(this.context=await this.client.createContext(e),this.contextKey=t,this.context)}getPageContext(){var e,t,s;return{...(s=(t=(e=this.options)==null?void 0:e.getPageContext)==null?void 0:t.call(e))!=null?s:{},userRole:this.answerAudience}}answerAudienceStorageKey(e){return`pageops:answer-audience:${e}`}loadAnswerAudience(e){try{const t=localStorage.getItem(this.answerAudienceStorageKey(e));return $.some(s=>s.value===t)?t:"business"}catch(t){return"business"}}saveAnswerAudience(){if(this.options)try{localStorage.setItem(this.answerAudienceStorageKey(this.options.appId),this.answerAudience)}catch(e){}}async changeAnswerAudience(e){var s;if(this.asking||this.audienceChanging)return;const t=(s=$.find(i=>i.value===e))==null?void 0:s.value;if(!(!t||t===this.answerAudience)){this.answerAudience=t,this.saveAnswerAudience(),this.audienceChanging=!0,this.context=null,this.contextKey="",this.selectedPageKey="",this.currentThread=null,this.messages=[],this.steps=[],this.streaming="",this.answerError="",this.answerStopped=!1,this.conversationError="",this.renderPanel();try{await this.newConversation()}catch(i){this.conversationError=i instanceof Error?i.message:"切换回答角色失败,请稍后重试。"}finally{this.audienceChanging=!1,this.renderPanel()}}}getPageContextKey(e){var t,s,i,n,l;return JSON.stringify([(t=e.route)!=null?t:"",(s=e.url)!=null?s:location.href,(i=e.title)!=null?i:document.title,(n=e.menuPath)!=null?n:[],(l=e.userRole)!=null?l:""])}async loadSources(){if(this.client){try{this.sourceSnapshots=await this.client.listSources(),this.sourceUploadError=""}catch(e){this.sourceUploadError=e instanceof Error?e.message:"源码包状态加载失败"}this.scheduleSourceRefresh(),this.renderPanel()}}async loadConversations(){this.client&&(this.conversations=await this.client.listConversations(),this.renderPanel())}async newConversation(){var s;if(!this.client)return;const e=await this.ensureContext(),t=(s=e.menu_path)!=null&&s.length?e.menu_path.join(" / "):e.route||document.title||"新的问答";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()}async selectThread(e){this.client&&(this.currentThread=e,this.selectedPageKey=this.getPageContextKey(this.getPageContext()),this.messages=await this.client.listMessages(e.id),this.steps=[],this.streaming="",this.answerError="",this.answerStopped=!1,this.renderPanel())}async deleteConversation(e){var t;if(!(!this.client||this.asking||this.deletingThreadId)&&window.confirm(`确定删除会话“${e.title}”吗?此操作无法撤销。`)){this.deletingThreadId=e.id,this.conversationError="",this.renderPanel();try{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){this.currentThread=null,this.messages=[],this.steps=[],this.streaming="",this.answerError="",this.answerStopped=!1;const s=this.conversations[0];s&&await this.selectThread(s)}}catch(s){this.conversationError=s instanceof Error?s.message:"删除问答会话失败"}finally{this.deletingThreadId="",this.renderPanel()}}}async uploadSource(e){if(this.client){this.sourceUploading=!0,this.sourceUploadStatus="上传中...",this.sourceUploadError="",this.renderPanel();try{await this.client.uploadSource(e),this.sourceSnapshots=await this.client.listSources(),this.sourceUploadStatus=this.isProjectMemoryUpdating()?"源码上传完成,项目记忆更新中...":"上传完成",this.scheduleSourceRefresh()}catch(t){this.sourceUploadError=t instanceof Error?t.message:"源码包上传失败",this.sourceUploadStatus=""}finally{this.sourceUploading=!1,this.renderPanel()}}}async ask(e){if(!this.client||this.asking)return;const t=this.questionUnavailableReason();if(t){this.sourceUploadError=t,this.renderPanel();return}this.resetAnswerState();const s=++this.activeRunId,i=new AbortController;this.abortController=i,this.stoppedRunId=-1,this.asking=!0,this.waitingForFirstContent=!0,this.renderPanel();try{const n=this.getPageContextKey(this.getPageContext());if(this.currentThread&&this.selectedPageKey&&this.selectedPageKey!==n&&(this.currentThread=null),this.currentThread||await this.newConversation(),!this.currentThread)throw new Error("无法创建问答会话,请稍后重试。");this.messages.push({id:`local-${Date.now()}`,role:"user",content:e,metadata_json:{}}),this.steps=[],this.renderPanel();const l=await this.client.streamQuestion(this.currentThread.id,e,i.signal);if(!l.ok)throw new Error(await w(l,"服务暂时无法回答,请稍后重试。"));if(!l.body)throw new Error("服务未返回有效的流式响应,请稍后重试。");if(await U(l.body,(r,d)=>this.handleStreamEvent(r,d)),s===this.stoppedRunId)throw new DOMException("输出已停止","AbortError");if(this.streamFailure)throw new Error(this.streamFailure);if(!this.streamDone)throw new Error("服务响应意外中断,请稍后重试。");if(await this.typewriter.drain(),s===this.stoppedRunId)throw new DOMException("输出已停止","AbortError");await this.selectThread(this.currentThread)}catch(n){if(s!==this.activeRunId)return;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",details:{message:this.answerError}}))}finally{if(s!==this.activeRunId)return;this.asking=!1,this.waitingForFirstContent=!1,this.abortController===i&&(this.abortController=null),this.renderPanel(!0)}}cancelActiveAnswer(e){var t;if(!(!this.asking&&!this.abortController)){if(e){this.stoppedRunId=this.activeRunId,this.answerStopped=!0;const s=this.steps.map(i=>i.status==="running"?{...i,status:"cancelled"}:i);this.steps=s.some(i=>i.status==="cancelled")?s:[...s,{id:"stopped",title:"已停止",status:"cancelled"}]}else this.activeRunId+=1,this.asking=!1;this.typewriter.clear(),this.waitingForFirstContent=!1,(t=this.abortController)==null||t.abort(),this.abortController=null,e&&this.renderPanel()}}handleStreamEvent(e,t){var s,i;if(e==="step"){this.upsertStep(t),this.renderPanel();return}if(e==="delta"){const n=String((s=t.content)!=null?s:"");if(!n)return;this.waitingForFirstContent=!1,this.typewriter.enqueue(n);return}e==="done"&&(this.streamDone=t),e==="error"&&(this.streamFailure=String((i=t.message)!=null?i:"服务异常,请稍后重试。"))}updateStreamingMessage(){var s,i;const e=(s=this.panel)==null?void 0:s.querySelector("[data-streaming-content]");if(!e){this.renderPanel();return}e.innerHTML=S(this.streaming);const t=(i=this.panel)==null?void 0:i.querySelector(".po-messages");t&&(t.scrollTop=t.scrollHeight)}resetAnswerState(){this.typewriter.clear(),this.asking=!1,this.waitingForFirstContent=!1,this.answerError="",this.answerStopped=!1,this.streamFailure="",this.streamDone=null,this.streaming=""}upsertStep(e){const t=this.steps.findIndex(s=>s.id===e.id);this.steps=t===-1?[...this.steps,e]:this.steps.map(s=>s.id===e.id?{...s,...e}:s)}latestAnalysisStatus(){var e,t,s;return String((s=(t=(e=this.sourceSnapshots[0])==null?void 0:e.metadata)==null?void 0:t.analysis_status)!=null?s:"")}isProjectMemoryUpdating(){return["pending","running"].includes(this.latestAnalysisStatus())}questionUnavailableReason(){return this.sourceSnapshots.length?this.isProjectMemoryUpdating()?"项目记忆正在更新,完成前暂不能问答。":this.latestAnalysisStatus()==="failed"?"项目记忆更新失败,请重新上传或重新索引。":"":"请先上传代码包后再提问。"}scheduleSourceRefresh(){this.stopSourceRefresh(),this.isProjectMemoryUpdating()&&(this.sourceRefreshTimer=setTimeout(()=>void this.loadSources(),1500))}stopSourceRefresh(){this.sourceRefreshTimer&&clearTimeout(this.sourceRefreshTimer),this.sourceRefreshTimer=null}renderPanel(e=this.asking){if(!this.panel)return;const t=this.questionUnavailableReason(),s=t||(this.asking?"回答生成中,请稍候":"请输入页面分析问题,Enter 发送,Shift + Enter 换行"),i=!!(t||this.asking),n=t?'<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>',l=$.map(r=>`
|
|
4
|
-
<button type="button" data-audience="${
|
|
1
|
+
(function(f,m){typeof exports=="object"&&typeof module!="undefined"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(f=typeof globalThis!="undefined"?globalThis:f||self,m(f.PageOpsSDK={}))})(this,(function(f){"use strict";var M=Object.defineProperty;var W=(f,m,y)=>m in f?M(f,m,{enumerable:!0,configurable:!0,writable:!0,value:y}):f[m]=y;var r=(f,m,y)=>W(f,typeof m!="symbol"?m+"":m,y);class m{constructor(e){this.options=e}async createContext(e=(i=>(i=(t=>(s=>(s=(t=this.options).getPageContext)==null?void 0:s.call(t))())())!=null?i:{})()){var n,c,a;return this.request("/context/session",{method:"POST",body:JSON.stringify({app_id:this.options.appId,env:this.options.env,route:e.route,url:(n=e.url)!=null?n:location.href,title:(c=e.title)!=null?c:document.title,menu_path:(a=e.menuPath)!=null?a:[],tenant_id:e.tenantId,user_role:e.userRole,build_version:e.buildVersion})})}async listConversations(){return(await this.request(`/conversations?app_id=${encodeURIComponent(this.options.appId)}`)).conversations}async createConversation(e,t){return this.request("/conversations",{method:"POST",body:JSON.stringify({app_id:this.options.appId,context_session_id:e,title:t})})}async deleteConversation(e){return this.request(`/conversations/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`,{method:"DELETE"})}async listMessages(e){return(await this.request(`/conversations/${encodeURIComponent(e)}/messages?app_id=${encodeURIComponent(this.options.appId)}`)).messages}async getAgentRun(e){return this.request(`/question/runs/${encodeURIComponent(e)}?app_id=${encodeURIComponent(this.options.appId)}`)}async listSources(){return(await this.request(`/sources?project_id=${encodeURIComponent(this.options.appId)}`)).sources}uploadSource(e){const t=new FormData;return t.append("file",e),this.request(`/sources/upload?project_id=${encodeURIComponent(this.options.appId)}`,{method:"POST",body:t,headers:{}})}streamQuestion(e,t,s){return fetch(`${this.base()}/question/stream`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({app_id:this.options.appId,thread_id:e,question:t}),signal:s})}async request(e,t){var c,a;const s=(t==null?void 0:t.body)instanceof FormData?t.headers:{"content-type":"application/json",...(c=t==null?void 0:t.headers)!=null?c:{}},i=await fetch(`${this.base()}${e}`,{...t,headers:s});if(i.status===204)return;const n=await i.json();if(!i.ok)throw new Error((a=n.message)!=null?a:"PageOps 请求失败");return n}base(){const e=this.options.apiBase.replace(/\/$/,"");return e.endsWith("/api")?e:`${e}/api`}}async function y(o,e){const t=await o.json().catch(()=>null);return typeof(t==null?void 0:t.message)=="string"&&t.message.trim()?t.message:e}function E(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function w(o){return E(o).replace(/`([^`]+)`/g,"<code>$1</code>").replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>")}function U(o,e){const t=o[e],s=o[e+1];if(!(t!=null&&t.includes("|"))||!/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(s!=null?s:""))return null;const i=[];let n=e;for(;n<o.length&&o[n].includes("|")&&o[n].trim();)i.push(o[n]),n+=1;const c=g=>g.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(b=>w(b.trim())),a=c(i[0]).map(g=>`<th>${g}</th>`).join(""),p=i.slice(2).map(g=>`<tr>${c(g).map(b=>`<td>${b}</td>`).join("")}</tr>`).join("");return{html:`<table><thead><tr>${a}</tr></thead><tbody>${p}</tbody></table>`,next:n}}function $(o){const e=o.split(`
|
|
2
|
+
`),t=[];for(let s=0;s<e.length;s+=1){const i=e[s];if(i.trim().startsWith("```")){const c=[];for(s+=1;s<e.length&&!e[s].trim().startsWith("```");)c.push(e[s]),s+=1;t.push(`<pre><code>${E(c.join(`
|
|
3
|
+
`))}</code></pre>`);continue}const n=U(e,s);if(n){t.push(n.html),s=n.next-1;continue}i.startsWith("### ")?t.push(`<h4>${w(i.slice(4))}</h4>`):i.startsWith("## ")?t.push(`<h3>${w(i.slice(3))}</h3>`):i.startsWith("# ")?t.push(`<h2>${w(i.slice(2))}</h2>`):i.startsWith("- ")?t.push(`<li>${w(i.slice(2))}</li>`):i.trim()?t.push(`<p>${w(i)}</p>`):t.push("<br>")}return t.join("")}async function F(o,e){var n;const t=o.getReader(),s=new TextDecoder;let i="";for(;;){const{done:c,value:a}=await t.read();if(c){i+=s.decode();break}i+=s.decode(a,{stream:!0});const p=i.split(/\r?\n\r?\n/);i=(n=p.pop())!=null?n:"";for(const g of p)A(g,e)}i.trim()&&A(i,e)}function A(o,e){var i,n;const t=(i=o.match(/^event:\s*(.+)$/m))==null?void 0:i[1],s=(n=o.match(/^data:\s*(.+)$/m))==null?void 0:n[1];t&&s&&e(t,JSON.parse(s))}class K{constructor(e,t=16){r(this,"queue",[]);r(this,"timer",null);r(this,"drainWaiters",[]);this.onChunk=e,this.interval=t}enqueue(e){this.queue.push(...Array.from(e)),this.timer||this.tick()}async drain(){!this.timer&&!this.queue.length||await new Promise(e=>this.drainWaiters.push(e))}clear(){this.timer&&clearTimeout(this.timer),this.timer=null,this.queue=[],this.resolveDrainWaiters()}tick(){const e=Math.max(1,Math.ceil(this.queue.length/90)),t=this.queue.splice(0,e).join("");if(t&&this.onChunk(t),!this.queue.length){this.timer=null,this.resolveDrainWaiters();return}this.timer=setTimeout(()=>this.tick(),this.interval)}resolveDrainWaiters(){for(const e of this.drainWaiters.splice(0))e()}}const S=[{value:"product",label:"产品"},{value:"business",label:"业务"},{value:"developer",label:"研发"},{value:"tester",label:"测试"}];class _{constructor(){r(this,"client",null);r(this,"options",null);r(this,"root",null);r(this,"panel",null);r(this,"context",null);r(this,"contextKey","");r(this,"selectedPageKey","");r(this,"currentThread",null);r(this,"conversations",[]);r(this,"messages",[]);r(this,"steps",[]);r(this,"selectedAgentRunId","");r(this,"runLoading",!1);r(this,"runLoadError","");r(this,"copiedAgentRunId","");r(this,"copyFeedbackTimer",null);r(this,"sourceSnapshots",[]);r(this,"sourceUploadStatus","");r(this,"sourceUploadError","");r(this,"sourceLoadError","");r(this,"sourceUploading",!1);r(this,"sourceRefreshTimer",null);r(this,"streaming","");r(this,"asking",!1);r(this,"waitingForFirstContent",!1);r(this,"abortController",null);r(this,"activeRunId",0);r(this,"stoppedRunId",-1);r(this,"answerStopped",!1);r(this,"answerError","");r(this,"conversationError","");r(this,"deletingThreadId","");r(this,"streamFailure","");r(this,"streamDone",null);r(this,"answerAudience","business");r(this,"audienceChanging",!1);r(this,"typewriter",new K(e=>{this.streaming+=e,this.updateStreamingMessage()}))}mount(e){var t;this.unmount(),this.options=e,this.client=new m(e),this.answerAudience=this.loadAnswerAudience(e.appId),this.root=document.createElement("div"),this.root.className="pageops-sdk",((t=e.container)!=null?t:document.body).appendChild(this.root),this.renderClosed()}unmount(){var e;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.sourceUploadStatus="",this.sourceUploadError="",this.sourceLoadError="",this.sourceUploading=!1,this.answerAudience="business",this.audienceChanging=!1}open(){this.root&&(this.root.innerHTML="",this.panel=document.createElement("div"),this.panel.className="po-panel",this.root.appendChild(this.panel),this.loadSources(),this.loadConversations(),this.renderPanel())}close(){this.stopSourceRefresh(),this.cancelActiveAnswer(!1),this.renderClosed()}updateContext(e){if(!this.options)return;const t=this.options.appId;this.options={...this.options,...e},this.client=new m(this.options),this.options.appId!==t&&(this.answerAudience=this.loadAnswerAudience(this.options.appId),this.currentThread=null,this.selectedPageKey="",this.messages=[],this.steps=[],this.selectedAgentRunId="",this.runLoadError=""),this.context=null,this.contextKey="",this.renderPanel()}renderClosed(){var e;this.root&&(this.root.innerHTML='<button class="po-fab" type="button">多轮问答</button>',(e=this.root.querySelector("button"))==null||e.addEventListener("click",()=>this.open()))}async ensureContext(){if(!this.client||!this.options)throw new Error("PageOps SDK 未初始化");const e=this.getPageContext(),t=this.getPageContextKey(e);return this.context&&this.contextKey===t?this.context:(this.context=await this.client.createContext(e),this.contextKey=t,this.context)}getPageContext(){var e,t,s;return{...(s=(t=(e=this.options)==null?void 0:e.getPageContext)==null?void 0:t.call(e))!=null?s:{},userRole:this.answerAudience}}answerAudienceStorageKey(e){return`pageops:answer-audience:${e}`}loadAnswerAudience(e){try{const t=localStorage.getItem(this.answerAudienceStorageKey(e));return S.some(s=>s.value===t)?t:"business"}catch(t){return"business"}}saveAnswerAudience(){if(this.options)try{localStorage.setItem(this.answerAudienceStorageKey(this.options.appId),this.answerAudience)}catch(e){}}async changeAnswerAudience(e){var s;if(this.asking||this.audienceChanging)return;const t=(s=S.find(i=>i.value===e))==null?void 0:s.value;if(!(!t||t===this.answerAudience)){this.answerAudience=t,this.saveAnswerAudience(),this.audienceChanging=!0,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.conversationError="",this.renderPanel();try{await this.newConversation()}catch(i){this.conversationError=i instanceof Error?i.message:"切换回答角色失败,请稍后重试。"}finally{this.audienceChanging=!1,this.renderPanel()}}}getPageContextKey(e){var t,s,i,n,c;return JSON.stringify([(t=e.route)!=null?t:"",(s=e.url)!=null?s:location.href,(i=e.title)!=null?i:document.title,(n=e.menuPath)!=null?n:[],(c=e.userRole)!=null?c:""])}async loadSources(){if(this.client){try{this.sourceSnapshots=await this.client.listSources(),this.sourceLoadError=""}catch(e){this.sourceLoadError="源码包状态加载失败,连接恢复后将自动重试。"}this.scheduleSourceRefresh(),this.renderPanel()}}async loadConversations(){this.client&&(this.conversations=await this.client.listConversations(),this.renderPanel())}async newConversation(){var s;if(!this.client)return;const e=await this.ensureContext(),t=(s=e.menu_path)!=null&&s.length?e.menu_path.join(" / "):e.route||document.title||"新的问答";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()}async selectThread(e){if(!this.client)return;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();const t=[...this.messages].reverse().map(P).find(Boolean);t&&await this.loadAgentRun(t)}async deleteConversation(e){var t;if(!(!this.client||this.asking||this.deletingThreadId)&&window.confirm(`确定删除会话“${e.title}”吗?此操作无法撤销。`)){this.deletingThreadId=e.id,this.conversationError="",this.renderPanel();try{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){this.currentThread=null,this.messages=[],this.steps=[],this.selectedAgentRunId="",this.runLoadError="",this.streaming="",this.answerError="",this.answerStopped=!1;const s=this.conversations[0];s&&await this.selectThread(s)}}catch(s){this.conversationError=s instanceof Error?s.message:"删除问答会话失败"}finally{this.deletingThreadId="",this.renderPanel()}}}async uploadSource(e){if(this.client){this.sourceUploading=!0,this.sourceUploadStatus="上传中...",this.sourceUploadError="",this.renderPanel();try{await this.client.uploadSource(e),this.sourceSnapshots=await this.client.listSources(),this.sourceUploadStatus=this.isProjectMemoryUpdating()?"源码上传完成,项目记忆更新中...":"上传完成",this.scheduleSourceRefresh()}catch(t){this.sourceUploadError=t instanceof Error?t.message:"源码包上传失败",this.sourceUploadStatus=""}finally{this.sourceUploading=!1,this.renderPanel()}}}async ask(e){if(!this.client||this.asking)return;const t=this.questionUnavailableReason();if(t){this.sourceUploadError=t,this.renderPanel();return}this.resetAnswerState();const s=++this.activeRunId,i=new AbortController;this.abortController=i,this.stoppedRunId=-1,this.asking=!0,this.waitingForFirstContent=!0,this.renderPanel();try{const n=this.getPageContextKey(this.getPageContext());if(this.currentThread&&this.selectedPageKey&&this.selectedPageKey!==n&&(this.currentThread=null),this.currentThread||await this.newConversation(),!this.currentThread)throw new Error("无法创建问答会话,请稍后重试。");this.messages.push({id:`local-${Date.now()}`,role:"user",content:e,metadata_json:{}}),this.steps=[],this.selectedAgentRunId="",this.runLoadError="",this.renderPanel();const c=await this.client.streamQuestion(this.currentThread.id,e,i.signal);if(!c.ok)throw new Error(await y(c,"服务暂时无法回答,请稍后重试。"));if(!c.body)throw new Error("服务未返回有效的流式响应,请稍后重试。");if(await F(c.body,(a,p)=>this.handleStreamEvent(a,p)),s===this.stoppedRunId)throw new DOMException("输出已停止","AbortError");if(this.streamFailure)throw new Error(this.streamFailure);if(!this.streamDone)throw new Error("服务响应意外中断,请稍后重试。");if(await this.typewriter.drain(),s===this.stoppedRunId)throw new DOMException("输出已停止","AbortError");await this.selectThread(this.currentThread)}catch(n){if(s!==this.activeRunId)return;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}))}finally{if(s!==this.activeRunId)return;this.asking=!1,this.waitingForFirstContent=!1,this.abortController===i&&(this.abortController=null),this.renderPanel(!0)}}cancelActiveAnswer(e){var t;if(!(!this.asking&&!this.abortController)){if(e){this.stoppedRunId=this.activeRunId,this.answerStopped=!0;const s=this.steps.map(i=>i.status==="running"?{...i,status:"cancelled"}:i);this.steps=s.some(i=>i.status==="cancelled")?s:[...s,{id:"stopped",title:"已停止",status:"cancelled"}]}else this.activeRunId+=1,this.asking=!1;this.typewriter.clear(),this.waitingForFirstContent=!1,(t=this.abortController)==null||t.abort(),this.abortController=null,e&&this.renderPanel()}}handleStreamEvent(e,t){var s,i;if(e==="step"){this.upsertStep(t),this.renderPanel();return}if(e==="delta"){const n=String((s=t.content)!=null?s:"");if(!n)return;this.waitingForFirstContent=!1,this.typewriter.enqueue(n);return}e==="done"&&(this.streamDone=t),e==="error"&&(this.streamFailure=String((i=t.message)!=null?i:"服务异常,请稍后重试。"))}updateStreamingMessage(){var s,i;const e=(s=this.panel)==null?void 0:s.querySelector("[data-streaming-content]");if(!e){this.renderPanel();return}e.innerHTML=$(this.streaming);const t=(i=this.panel)==null?void 0:i.querySelector(".po-messages");t&&(t.scrollTop=t.scrollHeight)}resetAnswerState(){this.typewriter.clear(),this.asking=!1,this.waitingForFirstContent=!1,this.answerError="",this.answerStopped=!1,this.streamFailure="",this.streamDone=null,this.streaming=""}upsertStep(e){const t=this.steps.findIndex(s=>s.id===e.id);this.steps=t===-1?[...this.steps,e]:this.steps.map(s=>s.id===e.id?{...s,...e}:s)}async loadAgentRun(e){if(!(!this.client||!e)){this.selectedAgentRunId=e,this.runLoading=!0,this.runLoadError="",this.renderPanel();try{const t=await this.client.getAgentRun(e);if(this.selectedAgentRunId!==e)return;this.steps=t.steps}catch(t){if(this.selectedAgentRunId!==e)return;this.steps=[],this.runLoadError=t instanceof Error?t.message:"执行过程加载失败"}finally{this.selectedAgentRunId===e&&(this.runLoading=!1,this.renderPanel())}}}async copyAgentRunId(e){var t;if(e){try{if((t=navigator.clipboard)!=null&&t.writeText)await navigator.clipboard.writeText(e);else{const s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.select(),document.execCommand("copy"),s.remove()}this.copiedAgentRunId=e}catch(s){this.copiedAgentRunId=`error:${e}`}this.clearCopyFeedback(!1),this.copyFeedbackTimer=setTimeout(()=>{this.copiedAgentRunId="",this.copyFeedbackTimer=null,this.renderPanel()},1800),this.renderPanel()}}clearCopyFeedback(e=!0){this.copyFeedbackTimer&&clearTimeout(this.copyFeedbackTimer),this.copyFeedbackTimer=null,e&&(this.copiedAgentRunId="")}latestAnalysisStatus(){var e,t,s;return String((s=(t=(e=this.sourceSnapshots[0])==null?void 0:e.metadata)==null?void 0:t.analysis_status)!=null?s:"")}isProjectMemoryUpdating(){return["pending","running"].includes(this.latestAnalysisStatus())}questionUnavailableReason(){return this.sourceLoadError&&!this.sourceSnapshots.length?"暂时无法读取项目共享代码包,请检查 PageOps 服务连接。":this.sourceSnapshots.length?this.isProjectMemoryUpdating()?"项目记忆正在更新,完成前暂不能问答。":this.latestAnalysisStatus()==="failed"?"项目记忆更新失败,请重新上传或重新索引。":"":"请先上传代码包后再提问。"}scheduleSourceRefresh(){this.stopSourceRefresh(),!(!this.sourceLoadError&&!this.isProjectMemoryUpdating())&&(this.sourceRefreshTimer=setTimeout(()=>void this.loadSources(),1500))}stopSourceRefresh(){this.sourceRefreshTimer&&clearTimeout(this.sourceRefreshTimer),this.sourceRefreshTimer=null}renderPanel(e=this.asking){if(!this.panel)return;const t=this.questionUnavailableReason(),s=t||(this.asking?"回答生成中,请稍候":"请输入页面分析问题,Enter 发送,Shift + Enter 换行"),i=!!(t||this.asking),n=t?'<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>',c=S.map(a=>`
|
|
4
|
+
<button type="button" data-audience="${a.value}" aria-pressed="${a.value===this.answerAudience}" ${this.asking||this.audienceChanging?"disabled":""}>${a.label}</button>
|
|
5
5
|
`).join("");if(this.panel.innerHTML=`
|
|
6
6
|
<aside class="po-sidebar">
|
|
7
7
|
<div class="po-brand"><div class="po-logo"></div><div><strong>PageOps 问答</strong><span>页面工程专家</span></div></div>
|
|
8
8
|
<button class="po-new" data-action="new" ${this.asking?"disabled":""}>+ 新建问答</button>
|
|
9
9
|
<input class="po-search" placeholder="搜索问答" />
|
|
10
|
-
${this.conversationError?`<p class="po-conversation-error" role="alert">${
|
|
11
|
-
<div class="po-thread-list">${this.conversations.map(
|
|
12
|
-
<div class="po-thread-row ${
|
|
13
|
-
<button class="po-thread" data-thread="${
|
|
14
|
-
<strong>${
|
|
10
|
+
${this.conversationError?`<p class="po-conversation-error" role="alert">${l(this.conversationError)}</p>`:""}
|
|
11
|
+
<div class="po-thread-list">${this.conversations.map(a=>{var p;return`
|
|
12
|
+
<div class="po-thread-row ${a.id===((p=this.currentThread)==null?void 0:p.id)?"active":""}">
|
|
13
|
+
<button class="po-thread" data-thread="${l(a.id)}" ${this.asking?"disabled":""}>
|
|
14
|
+
<strong>${l(a.title)}</strong><span>${C(a.created_at)}</span>
|
|
15
15
|
</button>
|
|
16
|
-
<button class="po-thread-delete" type="button" data-delete-thread="${
|
|
16
|
+
<button class="po-thread-delete" type="button" data-delete-thread="${l(a.id)}" aria-label="删除会话:${l(a.title)}" title="删除会话" ${this.asking||this.deletingThreadId===a.id?"disabled":""}><span class="po-trash-icon" aria-hidden="true"></span></button>
|
|
17
17
|
</div>`}).join("")}</div>
|
|
18
18
|
</aside>
|
|
19
19
|
<main class="po-chat">
|
|
20
|
-
<header><div class="po-chat-title"><p>问数回答</p><h2>${this.currentThread?
|
|
20
|
+
<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="回答角色">${c}</div></div></header>
|
|
21
21
|
<section class="po-messages">
|
|
22
|
-
${this.messages.map(
|
|
22
|
+
${this.messages.map(a=>this.renderMessage(a)).join("")}
|
|
23
23
|
${this.renderAnswerState()}
|
|
24
24
|
</section>
|
|
25
|
-
<form class="po-composer"><textarea ${i?"disabled":""} placeholder="${
|
|
25
|
+
<form class="po-composer"><textarea ${i?"disabled":""} placeholder="${l(s)}"></textarea>${n}</form>
|
|
26
26
|
</main>
|
|
27
27
|
<aside class="po-trace"><header><h2>执行过程</h2><button data-action="close">×</button></header><section>${this.renderSourceUploader()}${this.renderSteps()}</section></aside>
|
|
28
|
-
`,this.bindPanelEvents(),e){const
|
|
28
|
+
`,this.bindPanelEvents(),e){const a=this.panel.querySelector(".po-messages");a&&(a.scrollTop=a.scrollHeight)}}renderAnswerState(){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>${$(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>`:"",i=this.answerStopped?'<div class="po-stream-stopped" role="status">已停止输出</div>':"";return`${e}${t}${i}${s}`}renderMessage(e){const t=P(e),s=t&&t===this.selectedAgentRunId,i=this.copiedAgentRunId===t,n=this.copiedAgentRunId===`error:${t}`,c=e.role==="assistant"&&t?`<footer class="po-answer-meta ${s?"selected":""}">
|
|
29
|
+
<span class="po-run-id" title="${l(t)}">问答流水号 <code>${l(t)}</code></span>
|
|
30
|
+
<button type="button" data-copy-run="${l(t)}">${i?"已复制":n?"复制失败":"复制流水号"}</button>
|
|
31
|
+
<button type="button" data-view-run="${l(t)}" aria-pressed="${s}">${s?"正在查看":"查看执行过程"}</button>
|
|
32
|
+
</footer>`:"";return`<article class="po-message ${e.role} ${s?"run-selected":""}" data-message="${l(e.id)}">
|
|
33
|
+
<b>${e.role==="user"?"你":"PageOps 分析"}</b>
|
|
34
|
+
<div>${e.role==="assistant"?$(e.content):l(e.content)}</div>
|
|
35
|
+
${c}
|
|
36
|
+
</article>`}renderSourceUploader(){const e=this.sourceLoadError?"暂时无法读取项目共享代码包,连接恢复后将自动重试。":"当前项目暂无代码包,请先上传后再提问。";return`
|
|
29
37
|
<div class="po-source-uploader">
|
|
30
38
|
<strong>源码包</strong>
|
|
31
|
-
<p
|
|
39
|
+
<p>同一项目的所有回答角色共享代码包。上传 zip、tar、tar.gz 或 tgz 后,PageOps 将基于代码证据回答问题。</p>
|
|
32
40
|
<label class="po-upload-button">
|
|
33
41
|
<span>${this.sourceUploading?"上传中...":"选择代码包"}</span>
|
|
34
42
|
<input type="file" accept=".zip,.tar,.gz,.tgz" data-action="upload-source" ${this.sourceUploading?"disabled":""} />
|
|
35
43
|
</label>
|
|
36
|
-
${this.sourceUploadStatus?`<p class="po-upload-status">${
|
|
37
|
-
${this.sourceSnapshots.length?`<div class="po-source-list">${this.sourceSnapshots.map(
|
|
38
|
-
${this.
|
|
44
|
+
${this.sourceUploadStatus?`<p class="po-upload-status">${l(this.sourceUploadStatus)}</p>`:""}
|
|
45
|
+
${this.sourceSnapshots.length?`<div class="po-source-list">${this.sourceSnapshots.map(t=>this.renderSourceItem(t)).join("")}</div>`:`<p class="po-upload-empty">${e}</p>`}
|
|
46
|
+
${this.sourceLoadError?`<p class="po-upload-error">${l(this.sourceLoadError)}</p>`:""}
|
|
47
|
+
${this.sourceUploadError?`<p class="po-upload-error">${l(this.sourceUploadError)}</p>`:""}
|
|
39
48
|
</div>
|
|
40
|
-
`}renderSourceItem(e){var
|
|
49
|
+
`}renderSourceItem(e){var a,p,g;const t=e.filename||"未命名代码包",s=e.created_at?C(e.created_at):"刚刚上传",i=j(e.archive_bytes||e.total_bytes||0),n=String((p=(a=e.metadata)==null?void 0:a.analysis_status)!=null?p:"unknown"),c=(g={pending:"项目记忆等待更新",running:"项目记忆更新中",ready:"项目记忆已就绪",failed:"项目记忆更新失败"}[n])!=null?g:"项目记忆状态未知";return`<article class="po-source-item"><strong>${l(t)}</strong><span>${l(s)} · ${l(i)}</span><span>${l(c)}</span></article>`}renderSteps(){return this.runLoading?'<div class="po-trace-state"><span class="po-ai-spinner" aria-hidden="true"></span><span>正在恢复本次执行过程</span></div>':this.runLoadError?`<div class="po-trace-state failed" role="alert">${l(this.runLoadError)}</div>`:(this.steps.length?this.steps:[{id:"idle",title:"等待任务",status:"pending",summary:"发送问题后,这里会展示完整分析过程。"}]).map(t=>{var c,a,p;const s=(c=t.metrics)!=null&&c.length?`<div class="po-step-metrics">${t.metrics.map(g=>`<span>${l(g)}</span>`).join("")}</div>`:"",i=(a=t.details)!=null&&a.length?`<div class="po-step-details">${t.details.map(g=>`<div><span>${l(g.label)}</span><p>${l(g.value)}</p></div>`).join("")}</div>`:"",n=!!(s||i);return`<details class="po-step ${t.status}" ${t.status==="running"||t.status==="failed"?"open":""} ${n?"":"data-static"}>
|
|
50
|
+
<summary>
|
|
51
|
+
<span class="po-step-dot" aria-hidden="true"></span>
|
|
52
|
+
<span class="po-step-copy"><strong>${l(t.title)}</strong><small>${l((p=t.summary)!=null?p:"")}</small></span>
|
|
53
|
+
<span class="po-step-status">${O(t.status)}</span>
|
|
54
|
+
</summary>
|
|
55
|
+
${s}${i}
|
|
56
|
+
</details>`}).join("")}bindPanelEvents(){var e,t,s,i,n,c,a,p,g,b,R,T,I,k,x,L,q;(t=(e=this.panel)==null?void 0:e.querySelector('[data-action="new"]'))==null||t.addEventListener("click",()=>void this.newConversation()),(i=(s=this.panel)==null?void 0:s.querySelector('[data-action="close"]'))==null||i.addEventListener("click",()=>this.close()),(c=(n=this.panel)==null?void 0:n.querySelector('[data-action="stop-answer"]'))==null||c.addEventListener("click",()=>this.cancelActiveAnswer(!0)),(a=this.panel)==null||a.querySelectorAll("[data-audience]").forEach(d=>{d.addEventListener("click",()=>{var h;return void this.changeAnswerAudience((h=d.dataset.audience)!=null?h:"")})}),(g=(p=this.panel)==null?void 0:p.querySelector('[data-action="upload-source"]'))==null||g.addEventListener("change",d=>{var u;const h=(u=d.target.files)==null?void 0:u[0];h&&this.uploadSource(h)}),(b=this.panel)==null||b.querySelectorAll("[data-thread]").forEach(d=>{d.addEventListener("click",()=>{const h=this.conversations.find(u=>u.id===d.dataset.thread);h&&this.selectThread(h)})}),(R=this.panel)==null||R.querySelectorAll("[data-delete-thread]").forEach(d=>{d.addEventListener("click",h=>{h.stopPropagation();const u=this.conversations.find(v=>v.id===d.dataset.deleteThread);u&&this.deleteConversation(u)})}),(T=this.panel)==null||T.querySelectorAll("[data-view-run]").forEach(d=>{d.addEventListener("click",h=>{var u;h.stopPropagation(),this.loadAgentRun((u=d.dataset.viewRun)!=null?u:"")})}),(I=this.panel)==null||I.querySelectorAll("[data-copy-run]").forEach(d=>{d.addEventListener("click",h=>{var u;h.stopPropagation(),this.copyAgentRunId((u=d.dataset.copyRun)!=null?u:"")})}),(x=(k=this.panel)==null?void 0:k.querySelector("form"))==null||x.addEventListener("submit",d=>{var v;d.preventDefault();const h=(v=this.panel)==null?void 0:v.querySelector("textarea"),u=h==null?void 0:h.value.trim();u&&(h.value="",this.ask(u))}),(q=(L=this.panel)==null?void 0:L.querySelector("textarea"))==null||q.addEventListener("keydown",d=>{var u,v;const h=d;h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),(v=(u=this.panel)==null?void 0:u.querySelector("form"))==null||v.requestSubmit())})}}function l(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function P(o){var t;const e=(t=o.metadata_json)==null?void 0:t.agent_run_id;return typeof e=="string"?e:""}function C(o){return new Intl.DateTimeFormat("zh-CN",{timeZone:"Asia/Shanghai",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).format(new Date(o))}function j(o){if(!o)return"0 B";const e=["B","KB","MB","GB"];let t=o,s=0;for(;t>=1024&&s<e.length-1;)t/=1024,s+=1;return`${t>=10||s===0?t.toFixed(0):t.toFixed(1)} ${e[s]}`}function O(o){return{pending:"等待中",running:"执行中",completed:"已完成",failed:"失败",cancelled:"已停止"}[o]}const D=new _;f.PageOpsSDK=D,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types.d.ts
CHANGED
|
@@ -43,7 +43,23 @@ export interface ExecutionStep {
|
|
|
43
43
|
id: string;
|
|
44
44
|
title: string;
|
|
45
45
|
status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
46
|
-
|
|
46
|
+
summary?: string;
|
|
47
|
+
metrics?: string[];
|
|
48
|
+
details?: Array<{
|
|
49
|
+
label: string;
|
|
50
|
+
value: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export interface AgentRunHistory {
|
|
54
|
+
run_id: string;
|
|
55
|
+
status: string;
|
|
56
|
+
started_at: string;
|
|
57
|
+
updated_at: string;
|
|
58
|
+
duration_ms: number;
|
|
59
|
+
turn_count: number;
|
|
60
|
+
tool_call_count: number;
|
|
61
|
+
active_skill?: string | null;
|
|
62
|
+
steps: ExecutionStep[];
|
|
47
63
|
}
|
|
48
64
|
export interface SourceSnapshot {
|
|
49
65
|
id?: string;
|