chainlesschain 0.45.81 → 0.46.0

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.
@@ -0,0 +1,318 @@
1
+ /**
2
+ * Workflow expression sandbox — evaluate `when` conditions and resolve
3
+ * typed step-result references for `forEach` expansion.
4
+ *
5
+ * SAFETY: hand-written tokenizer + recursive-descent parser, no
6
+ * `Function` / `eval`. Only the operators below are supported.
7
+ *
8
+ * Grammar (informal):
9
+ *
10
+ * expr := or
11
+ * or := and ( "||" and )*
12
+ * and := not ( "&&" not )*
13
+ * not := "!" not | cmp
14
+ * cmp := primary ( OP primary )? OP ∈ { == != < <= > >= contains }
15
+ * primary := "(" expr ")" | ref | string | number | bool | null
16
+ * ref := "${" "step" "." ID "." ID "}" OR "${item}"
17
+ *
18
+ * String literals use single or double quotes; `\'` / `\"` / `\\` escapes.
19
+ *
20
+ * `evaluate(expr, ctx)` returns a boolean. `ctx` shape:
21
+ * {
22
+ * step: Map<stepId, { status, taskId, result: { summary, tokenCount, ... } }>,
23
+ * item: any, // for forEach expansion
24
+ * }
25
+ *
26
+ * `resolveReference(ref, ctx)` returns the raw value of a `${...}` token
27
+ * (used by forEach to materialize array sources).
28
+ *
29
+ * @module workflow-expr
30
+ */
31
+
32
+ const TOKEN_OP = new Set([
33
+ "==",
34
+ "!=",
35
+ "<",
36
+ "<=",
37
+ ">",
38
+ ">=",
39
+ "contains",
40
+ "&&",
41
+ "||",
42
+ "!",
43
+ "(",
44
+ ")",
45
+ ]);
46
+
47
+ /**
48
+ * Tokenize an expression string. Returns an array of `{ type, value }`.
49
+ * Types: `op`, `ref`, `string`, `number`, `bool`, `null`.
50
+ */
51
+ export function tokenize(src) {
52
+ if (typeof src !== "string") throw new Error("expr must be a string");
53
+ const tokens = [];
54
+ let i = 0;
55
+ const n = src.length;
56
+ while (i < n) {
57
+ const c = src[i];
58
+ if (c === " " || c === "\t" || c === "\n") {
59
+ i++;
60
+ continue;
61
+ }
62
+ if (c === "(" || c === ")") {
63
+ tokens.push({ type: "op", value: c });
64
+ i++;
65
+ continue;
66
+ }
67
+ if (c === "$" && src[i + 1] === "{") {
68
+ const end = src.indexOf("}", i + 2);
69
+ if (end === -1) throw new Error("unterminated reference");
70
+ tokens.push({ type: "ref", value: src.slice(i + 2, end).trim() });
71
+ i = end + 1;
72
+ continue;
73
+ }
74
+ if (c === "'" || c === '"') {
75
+ let j = i + 1;
76
+ let out = "";
77
+ while (j < n && src[j] !== c) {
78
+ if (src[j] === "\\" && j + 1 < n) {
79
+ out += src[j + 1];
80
+ j += 2;
81
+ } else {
82
+ out += src[j];
83
+ j++;
84
+ }
85
+ }
86
+ if (j >= n) throw new Error("unterminated string literal");
87
+ tokens.push({ type: "string", value: out });
88
+ i = j + 1;
89
+ continue;
90
+ }
91
+ if (/[0-9-]/.test(c)) {
92
+ let j = i;
93
+ if (src[j] === "-") j++;
94
+ while (j < n && /[0-9.]/.test(src[j])) j++;
95
+ const lit = src.slice(i, j);
96
+ const num = Number(lit);
97
+ if (!Number.isFinite(num)) throw new Error(`bad number: ${lit}`);
98
+ tokens.push({ type: "number", value: num });
99
+ i = j;
100
+ continue;
101
+ }
102
+ // Multi-char ops
103
+ const two = src.slice(i, i + 2);
104
+ if (
105
+ two === "==" ||
106
+ two === "!=" ||
107
+ two === "<=" ||
108
+ two === ">=" ||
109
+ two === "&&" ||
110
+ two === "||"
111
+ ) {
112
+ tokens.push({ type: "op", value: two });
113
+ i += 2;
114
+ continue;
115
+ }
116
+ if (c === "<" || c === ">" || c === "!") {
117
+ tokens.push({ type: "op", value: c });
118
+ i++;
119
+ continue;
120
+ }
121
+ // Identifiers: contains / true / false / null
122
+ if (/[a-zA-Z_]/.test(c)) {
123
+ let j = i;
124
+ while (j < n && /[a-zA-Z0-9_]/.test(src[j])) j++;
125
+ const id = src.slice(i, j);
126
+ if (id === "true" || id === "false") {
127
+ tokens.push({ type: "bool", value: id === "true" });
128
+ } else if (id === "null") {
129
+ tokens.push({ type: "null", value: null });
130
+ } else if (id === "contains") {
131
+ tokens.push({ type: "op", value: "contains" });
132
+ } else {
133
+ throw new Error(`unknown identifier: ${id}`);
134
+ }
135
+ i = j;
136
+ continue;
137
+ }
138
+ throw new Error(`unexpected char at ${i}: ${c}`);
139
+ }
140
+ return tokens;
141
+ }
142
+
143
+ /** Resolve a ref token like `step.fetch.summary` or `item` against ctx. */
144
+ export function resolveReference(ref, ctx) {
145
+ if (ref === "item") return ctx?.item;
146
+ const parts = ref.split(".");
147
+ if (parts[0] !== "step") {
148
+ throw new Error(`unknown reference root: ${parts[0]}`);
149
+ }
150
+ if (parts.length !== 3) {
151
+ throw new Error(`ref must be step.<id>.<field>: ${ref}`);
152
+ }
153
+ const [, stepId, field] = parts;
154
+ const entry = ctx?.step?.get?.(stepId);
155
+ if (!entry) return undefined;
156
+ if (field === "status") return entry.status;
157
+ if (field === "taskId") return entry.taskId;
158
+ if (field === "summary") return entry.result?.summary;
159
+ if (field === "tokenCount") return entry.result?.tokenCount;
160
+ if (field === "iterationCount") return entry.result?.iterationCount;
161
+ if (field === "toolsUsed") return entry.result?.toolsUsed;
162
+ if (field === "items") return entry.result?.items;
163
+ // Generic fallback: look up directly on result
164
+ return entry.result?.[field];
165
+ }
166
+
167
+ /** Recursive-descent parser returning an AST. */
168
+ function parse(tokens) {
169
+ let pos = 0;
170
+ function peek() {
171
+ return tokens[pos];
172
+ }
173
+ function consume(expected) {
174
+ const t = tokens[pos];
175
+ if (!t) throw new Error("unexpected end of expression");
176
+ if (expected && (t.type !== "op" || t.value !== expected)) {
177
+ throw new Error(`expected ${expected}, got ${t.value ?? t.type}`);
178
+ }
179
+ pos++;
180
+ return t;
181
+ }
182
+ function parseExpr() {
183
+ return parseOr();
184
+ }
185
+ function parseOr() {
186
+ let left = parseAnd();
187
+ while (peek() && peek().type === "op" && peek().value === "||") {
188
+ pos++;
189
+ const right = parseAnd();
190
+ left = { kind: "or", left, right };
191
+ }
192
+ return left;
193
+ }
194
+ function parseAnd() {
195
+ let left = parseNot();
196
+ while (peek() && peek().type === "op" && peek().value === "&&") {
197
+ pos++;
198
+ const right = parseNot();
199
+ left = { kind: "and", left, right };
200
+ }
201
+ return left;
202
+ }
203
+ function parseNot() {
204
+ if (peek() && peek().type === "op" && peek().value === "!") {
205
+ pos++;
206
+ return { kind: "not", expr: parseNot() };
207
+ }
208
+ return parseCmp();
209
+ }
210
+ function parseCmp() {
211
+ const left = parsePrimary();
212
+ const t = peek();
213
+ const cmpOps = new Set(["==", "!=", "<", "<=", ">", ">=", "contains"]);
214
+ if (t && t.type === "op" && cmpOps.has(t.value)) {
215
+ pos++;
216
+ const right = parsePrimary();
217
+ return { kind: "cmp", op: t.value, left, right };
218
+ }
219
+ // bare value → truthiness check
220
+ return { kind: "truthy", expr: left };
221
+ }
222
+ function parsePrimary() {
223
+ const t = peek();
224
+ if (!t) throw new Error("unexpected end of expression");
225
+ if (t.type === "op" && t.value === "(") {
226
+ pos++;
227
+ const e = parseExpr();
228
+ consume(")");
229
+ return e;
230
+ }
231
+ if (t.type === "ref") {
232
+ pos++;
233
+ return { kind: "ref", name: t.value };
234
+ }
235
+ if (
236
+ t.type === "string" ||
237
+ t.type === "number" ||
238
+ t.type === "bool" ||
239
+ t.type === "null"
240
+ ) {
241
+ pos++;
242
+ return { kind: "lit", value: t.value };
243
+ }
244
+ throw new Error(`unexpected token: ${t.value ?? t.type}`);
245
+ }
246
+
247
+ const ast = parseExpr();
248
+ if (pos !== tokens.length) {
249
+ throw new Error(`trailing tokens at ${pos}`);
250
+ }
251
+ return ast;
252
+ }
253
+
254
+ function evalAst(ast, ctx) {
255
+ switch (ast.kind) {
256
+ case "lit":
257
+ return ast.value;
258
+ case "ref":
259
+ return resolveReference(ast.name, ctx);
260
+ case "not":
261
+ return !evalAst(ast.expr, ctx);
262
+ case "and":
263
+ return evalAst(ast.left, ctx) && evalAst(ast.right, ctx);
264
+ case "or":
265
+ return evalAst(ast.left, ctx) || evalAst(ast.right, ctx);
266
+ case "truthy": {
267
+ const v = evalAst(ast.expr, ctx);
268
+ return !!v;
269
+ }
270
+ case "cmp": {
271
+ const l = evalAst(ast.left, ctx);
272
+ const r = evalAst(ast.right, ctx);
273
+ switch (ast.op) {
274
+ case "==":
275
+ // Loose equality across string/number for ergonomic use
276
+ // eslint-disable-next-line eqeqeq
277
+ return l == r;
278
+ case "!=":
279
+ // eslint-disable-next-line eqeqeq
280
+ return l != r;
281
+ case "<":
282
+ return l < r;
283
+ case "<=":
284
+ return l <= r;
285
+ case ">":
286
+ return l > r;
287
+ case ">=":
288
+ return l >= r;
289
+ case "contains": {
290
+ if (l == null) return false;
291
+ if (Array.isArray(l)) return l.includes(r);
292
+ return String(l).includes(String(r));
293
+ }
294
+ default:
295
+ throw new Error(`unknown op: ${ast.op}`);
296
+ }
297
+ }
298
+ default:
299
+ throw new Error(`unknown node: ${ast.kind}`);
300
+ }
301
+ }
302
+
303
+ /** Evaluate an expression string against a context. Returns a boolean. */
304
+ export function evaluate(src, ctx) {
305
+ const tokens = tokenize(src);
306
+ const ast = parse(tokens);
307
+ const v = evalAst(ast, ctx);
308
+ return !!v;
309
+ }
310
+
311
+ /** Evaluate an expression and return the raw (non-coerced) value. */
312
+ export function evaluateRaw(src, ctx) {
313
+ const tokens = tokenize(src);
314
+ let ast = parse(tokens);
315
+ // Strip the implicit truthy-wrapper so bare refs return raw values.
316
+ if (ast.kind === "truthy") ast = ast.expr;
317
+ return evalAst(ast, ctx);
318
+ }
@@ -1,7 +0,0 @@
1
- import{V as Tn,w as tn,f as I,c as He,o as En,a3 as T,a1 as f,k as N,u as r,F as ie,a7 as le,a2 as ke,A as lt,a5 as v,a4 as V,G as Q,W as te,a6 as rt,Z as W,a9 as An,X as _e,Y as p,n as Wt}from"./vendor-CN0Iv_qZ.js";import{m as Yt,H as ct}from"./markdown-BZsB-Dsv.js";/* empty css */import{u as ut}from"./ws-Dma34ig_.js";import{u as he}from"./chat-BYmuDvol.js";import{_ as yn}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{R as Me,T as vn,v as $t,H as Sn,o as On,G as Rn,r as bn,j as wn,w as Cn,x as Dn,m as Ln,y as kn,b as Mn,s as In,u as xn}from"./antd-D6h4fDFf.js";const{entries:nn,setPrototypeOf:Vt,isFrozen:Nn,getPrototypeOf:Pn,getOwnPropertyDescriptor:Fn}=Object;let{freeze:F,seal:Y,create:Ue}=Object,{apply:gt,construct:Tt}=typeof Reflect<"u"&&Reflect;F||(F=function(t){return t});Y||(Y=function(t){return t});gt||(gt=function(t,c){for(var l=arguments.length,_=new Array(l>2?l-2:0),E=2;E<l;E++)_[E-2]=arguments[E];return t.apply(c,_)});Tt||(Tt=function(t){for(var c=arguments.length,l=new Array(c>1?c-1:0),_=1;_<c;_++)l[_-1]=arguments[_];return new t(...l)});const Ie=U(Array.prototype.forEach),Un=U(Array.prototype.lastIndexOf),Xt=U(Array.prototype.pop),xe=U(Array.prototype.push),Hn=U(Array.prototype.splice),je=U(String.prototype.toLowerCase),ft=U(String.prototype.toString),dt=U(String.prototype.match),ye=U(String.prototype.replace),zn=U(String.prototype.indexOf),Gn=U(String.prototype.trim),X=U(Object.prototype.hasOwnProperty),P=U(RegExp.prototype.test),Ne=Bn(TypeError);function U(u){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var c=arguments.length,l=new Array(c>1?c-1:0),_=1;_<c;_++)l[_-1]=arguments[_];return gt(u,t,l)}}function Bn(u){return function(){for(var t=arguments.length,c=new Array(t),l=0;l<t;l++)c[l]=arguments[l];return Tt(u,c)}}function m(u,t){let c=arguments.length>2&&arguments[2]!==void 0?arguments[2]:je;Vt&&Vt(u,null);let l=t.length;for(;l--;){let _=t[l];if(typeof _=="string"){const E=c(_);E!==_&&(Nn(t)||(t[l]=E),_=E)}u[_]=!0}return u}function Wn(u){for(let t=0;t<u.length;t++)X(u,t)||(u[t]=null);return u}function Z(u){const t=Ue(null);for(const[c,l]of nn(u))X(u,c)&&(Array.isArray(l)?t[c]=Wn(l):l&&typeof l=="object"&&l.constructor===Object?t[c]=Z(l):t[c]=l);return t}function Pe(u,t){for(;u!==null;){const l=Fn(u,t);if(l){if(l.get)return U(l.get);if(typeof l.value=="function")return U(l.value)}u=Pn(u)}function c(){return null}return c}const jt=F(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),pt=F(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),mt=F(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Yn=F(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),_t=F(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),$n=F(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),qt=F(["#text"]),Kt=F(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),ht=F(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Qt=F(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Xe=F(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Vn=Y(/\{\{[\w\W]*|[\w\W]*\}\}/gm),Xn=Y(/<%[\w\W]*|[\w\W]*%>/gm),jn=Y(/\$\{[\w\W]*/gm),qn=Y(/^data-[\-\w.\u00B7-\uFFFF]+$/),Kn=Y(/^aria-[\-\w]+$/),sn=Y(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Qn=Y(/^(?:\w+script|data):/i),Zn=Y(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),an=Y(/^html$/i),Jn=Y(/^[a-z][.\w]*(-[.\w]+)+$/i);var Zt=Object.freeze({__proto__:null,ARIA_ATTR:Kn,ATTR_WHITESPACE:Zn,CUSTOM_ELEMENT:Jn,DATA_ATTR:qn,DOCTYPE_NAME:an,ERB_EXPR:Xn,IS_ALLOWED_URI:sn,IS_SCRIPT_OR_DATA:Qn,MUSTACHE_EXPR:Vn,TMPLIT_EXPR:jn});const Fe={element:1,text:3,progressingInstruction:7,comment:8,document:9},es=function(){return typeof window>"u"?null:window},ts=function(t,c){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let l=null;const _="data-tt-policy-suffix";c&&c.hasAttribute(_)&&(l=c.getAttribute(_));const E="dompurify"+(l?"#"+l:"");try{return t.createPolicy(E,{createHTML(x){return x},createScriptURL(x){return x}})}catch{return console.warn("TrustedTypes policy "+E+" could not be created."),null}},Jt=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function on(){let u=arguments.length>0&&arguments[0]!==void 0?arguments[0]:es();const t=i=>on(i);if(t.version="3.4.0",t.removed=[],!u||!u.document||u.document.nodeType!==Fe.document||!u.Element)return t.isSupported=!1,t;let{document:c}=u;const l=c,_=l.currentScript,{DocumentFragment:E,HTMLTemplateElement:x,Node:S,Element:z,NodeFilter:B,NamedNodeMap:re=u.NamedNodeMap||u.MozNamedAttrMap,HTMLFormElement:ve,DOMParser:ce,trustedTypes:J}=u,j=z.prototype,Se=Pe(j,"cloneNode"),Oe=Pe(j,"remove"),ne=Pe(j,"nextSibling"),ue=Pe(j,"childNodes"),A=Pe(j,"parentNode");if(typeof x=="function"){const i=c.createElement("template");i.content&&i.content.ownerDocument&&(c=i.content.ownerDocument)}let o,C="";const{implementation:fe,createNodeIterator:Re,createDocumentFragment:be,getElementsByTagName:d}=c,{importNode:h}=l;let g=Jt();t.isSupported=typeof nn=="function"&&typeof A=="function"&&fe&&fe.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:a,ERB_EXPR:k,TMPLIT_EXPR:se,DATA_ATTR:ln,ARIA_ATTR:rn,IS_SCRIPT_OR_DATA:cn,ATTR_WHITESPACE:Et,CUSTOM_ELEMENT:un}=Zt;let{IS_ALLOWED_URI:At}=Zt,w=null;const yt=m({},[...jt,...pt,...mt,..._t,...qt]);let D=null;const vt=m({},[...Kt,...ht,...Qt,...Xe]);let O=Object.seal(Ue(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),we=null,ze=null;const ae=Object.seal(Ue(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let St=!0,qe=!0,Ot=!1,Rt=!0,de=!1,Ce=!0,pe=!1,Ke=!1,Qe=!1,ge=!1,Ge=!1,Be=!1,bt=!0,wt=!1;const fn="user-content-";let Ze=!0,De=!1,Te={},q=null;const Je=m({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Ct=null;const Dt=m({},["audio","video","img","source","image","track"]);let et=null;const Lt=m({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),We="http://www.w3.org/1998/Math/MathML",Ye="http://www.w3.org/2000/svg",K="http://www.w3.org/1999/xhtml";let Ee=K,tt=!1,nt=null;const dn=m({},[We,Ye,K],ft);let $e=m({},["mi","mo","mn","ms","mtext"]),Ve=m({},["annotation-xml"]);const pn=m({},["title","style","font","a","script"]);let Le=null;const mn=["application/xhtml+xml","text/html"],_n="text/html";let b=null,Ae=null;const hn=c.createElement("form"),kt=function(e){return e instanceof RegExp||e instanceof Function},st=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Ae&&Ae===e)){if((!e||typeof e!="object")&&(e={}),e=Z(e),Le=mn.indexOf(e.PARSER_MEDIA_TYPE)===-1?_n:e.PARSER_MEDIA_TYPE,b=Le==="application/xhtml+xml"?ft:je,w=X(e,"ALLOWED_TAGS")?m({},e.ALLOWED_TAGS,b):yt,D=X(e,"ALLOWED_ATTR")?m({},e.ALLOWED_ATTR,b):vt,nt=X(e,"ALLOWED_NAMESPACES")?m({},e.ALLOWED_NAMESPACES,ft):dn,et=X(e,"ADD_URI_SAFE_ATTR")?m(Z(Lt),e.ADD_URI_SAFE_ATTR,b):Lt,Ct=X(e,"ADD_DATA_URI_TAGS")?m(Z(Dt),e.ADD_DATA_URI_TAGS,b):Dt,q=X(e,"FORBID_CONTENTS")?m({},e.FORBID_CONTENTS,b):Je,we=X(e,"FORBID_TAGS")?m({},e.FORBID_TAGS,b):Z({}),ze=X(e,"FORBID_ATTR")?m({},e.FORBID_ATTR,b):Z({}),Te=X(e,"USE_PROFILES")?e.USE_PROFILES:!1,St=e.ALLOW_ARIA_ATTR!==!1,qe=e.ALLOW_DATA_ATTR!==!1,Ot=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Rt=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,de=e.SAFE_FOR_TEMPLATES||!1,Ce=e.SAFE_FOR_XML!==!1,pe=e.WHOLE_DOCUMENT||!1,ge=e.RETURN_DOM||!1,Ge=e.RETURN_DOM_FRAGMENT||!1,Be=e.RETURN_TRUSTED_TYPE||!1,Qe=e.FORCE_BODY||!1,bt=e.SANITIZE_DOM!==!1,wt=e.SANITIZE_NAMED_PROPS||!1,Ze=e.KEEP_CONTENT!==!1,De=e.IN_PLACE||!1,At=e.ALLOWED_URI_REGEXP||sn,Ee=e.NAMESPACE||K,$e=e.MATHML_TEXT_INTEGRATION_POINTS||$e,Ve=e.HTML_INTEGRATION_POINTS||Ve,O=e.CUSTOM_ELEMENT_HANDLING||Ue(null),e.CUSTOM_ELEMENT_HANDLING&&kt(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(O.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&kt(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(O.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(O.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),de&&(qe=!1),Ge&&(ge=!0),Te&&(w=m({},qt),D=Ue(null),Te.html===!0&&(m(w,jt),m(D,Kt)),Te.svg===!0&&(m(w,pt),m(D,ht),m(D,Xe)),Te.svgFilters===!0&&(m(w,mt),m(D,ht),m(D,Xe)),Te.mathMl===!0&&(m(w,_t),m(D,Qt),m(D,Xe))),ae.tagCheck=null,ae.attributeCheck=null,e.ADD_TAGS&&(typeof e.ADD_TAGS=="function"?ae.tagCheck=e.ADD_TAGS:(w===yt&&(w=Z(w)),m(w,e.ADD_TAGS,b))),e.ADD_ATTR&&(typeof e.ADD_ATTR=="function"?ae.attributeCheck=e.ADD_ATTR:(D===vt&&(D=Z(D)),m(D,e.ADD_ATTR,b))),e.ADD_URI_SAFE_ATTR&&m(et,e.ADD_URI_SAFE_ATTR,b),e.FORBID_CONTENTS&&(q===Je&&(q=Z(q)),m(q,e.FORBID_CONTENTS,b)),e.ADD_FORBID_CONTENTS&&(q===Je&&(q=Z(q)),m(q,e.ADD_FORBID_CONTENTS,b)),Ze&&(w["#text"]=!0),pe&&m(w,["html","head","body"]),w.table&&(m(w,["tbody"]),delete we.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!="function")throw Ne('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Ne('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');o=e.TRUSTED_TYPES_POLICY,C=o.createHTML("")}else o===void 0&&(o=ts(J,_)),o!==null&&typeof C=="string"&&(C=o.createHTML(""));F&&F(e),Ae=e}},Mt=m({},[...pt,...mt,...Yn]),It=m({},[..._t,...$n]),gn=function(e){let n=A(e);(!n||!n.tagName)&&(n={namespaceURI:Ee,tagName:"template"});const s=je(e.tagName),y=je(n.tagName);return nt[e.namespaceURI]?e.namespaceURI===Ye?n.namespaceURI===K?s==="svg":n.namespaceURI===We?s==="svg"&&(y==="annotation-xml"||$e[y]):!!Mt[s]:e.namespaceURI===We?n.namespaceURI===K?s==="math":n.namespaceURI===Ye?s==="math"&&Ve[y]:!!It[s]:e.namespaceURI===K?n.namespaceURI===Ye&&!Ve[y]||n.namespaceURI===We&&!$e[y]?!1:!It[s]&&(pn[s]||!Mt[s]):!!(Le==="application/xhtml+xml"&&nt[e.namespaceURI]):!1},$=function(e){xe(t.removed,{element:e});try{A(e).removeChild(e)}catch{Oe(e)}},me=function(e,n){try{xe(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{xe(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e==="is")if(ge||Ge)try{$(n)}catch{}else try{n.setAttribute(e,"")}catch{}},xt=function(e){let n=null,s=null;if(Qe)e="<remove></remove>"+e;else{const R=dt(e,/^[\r\n\t ]+/);s=R&&R[0]}Le==="application/xhtml+xml"&&Ee===K&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const y=o?o.createHTML(e):e;if(Ee===K)try{n=new ce().parseFromString(y,Le)}catch{}if(!n||!n.documentElement){n=fe.createDocument(Ee,"template",null);try{n.documentElement.innerHTML=tt?C:y}catch{}}const M=n.body||n.documentElement;return e&&s&&M.insertBefore(c.createTextNode(s),M.childNodes[0]||null),Ee===K?d.call(n,pe?"html":"body")[0]:pe?n.documentElement:M},Nt=function(e){return Re.call(e.ownerDocument||e,e,B.SHOW_ELEMENT|B.SHOW_COMMENT|B.SHOW_TEXT|B.SHOW_PROCESSING_INSTRUCTION|B.SHOW_CDATA_SECTION,null)},at=function(e){return e instanceof ve&&(typeof e.nodeName!="string"||typeof e.textContent!="string"||typeof e.removeChild!="function"||!(e.attributes instanceof re)||typeof e.removeAttribute!="function"||typeof e.setAttribute!="function"||typeof e.namespaceURI!="string"||typeof e.insertBefore!="function"||typeof e.hasChildNodes!="function")},ot=function(e){return typeof S=="function"&&e instanceof S};function ee(i,e,n){Ie(i,s=>{s.call(t,e,n,Ae)})}const Pt=function(e){let n=null;if(ee(g.beforeSanitizeElements,e,null),at(e))return $(e),!0;const s=b(e.nodeName);if(ee(g.uponSanitizeElement,e,{tagName:s,allowedTags:w}),Ce&&e.hasChildNodes()&&!ot(e.firstElementChild)&&P(/<[/\w!]/g,e.innerHTML)&&P(/<[/\w!]/g,e.textContent)||Ce&&e.namespaceURI===K&&s==="style"&&ot(e.firstElementChild)||e.nodeType===Fe.progressingInstruction||Ce&&e.nodeType===Fe.comment&&P(/<[/\w]/g,e.data))return $(e),!0;if(we[s]||!(ae.tagCheck instanceof Function&&ae.tagCheck(s))&&!w[s]){if(!we[s]&&Ut(s)&&(O.tagNameCheck instanceof RegExp&&P(O.tagNameCheck,s)||O.tagNameCheck instanceof Function&&O.tagNameCheck(s)))return!1;if(Ze&&!q[s]){const y=A(e)||e.parentNode,M=ue(e)||e.childNodes;if(M&&y){const R=M.length;for(let H=R-1;H>=0;--H){const G=Se(M[H],!0);G.__removalCount=(e.__removalCount||0)+1,y.insertBefore(G,ne(e))}}}return $(e),!0}return e instanceof z&&!gn(e)||(s==="noscript"||s==="noembed"||s==="noframes")&&P(/<\/no(script|embed|frames)/i,e.innerHTML)?($(e),!0):(de&&e.nodeType===Fe.text&&(n=e.textContent,Ie([a,k,se],y=>{n=ye(n,y," ")}),e.textContent!==n&&(xe(t.removed,{element:e.cloneNode()}),e.textContent=n)),ee(g.afterSanitizeElements,e,null),!1)},Ft=function(e,n,s){if(ze[n]||bt&&(n==="id"||n==="name")&&(s in c||s in hn))return!1;if(!(qe&&!ze[n]&&P(ln,n))){if(!(St&&P(rn,n))){if(!(ae.attributeCheck instanceof Function&&ae.attributeCheck(n,e))){if(!D[n]||ze[n]){if(!(Ut(e)&&(O.tagNameCheck instanceof RegExp&&P(O.tagNameCheck,e)||O.tagNameCheck instanceof Function&&O.tagNameCheck(e))&&(O.attributeNameCheck instanceof RegExp&&P(O.attributeNameCheck,n)||O.attributeNameCheck instanceof Function&&O.attributeNameCheck(n,e))||n==="is"&&O.allowCustomizedBuiltInElements&&(O.tagNameCheck instanceof RegExp&&P(O.tagNameCheck,s)||O.tagNameCheck instanceof Function&&O.tagNameCheck(s))))return!1}else if(!et[n]){if(!P(At,ye(s,Et,""))){if(!((n==="src"||n==="xlink:href"||n==="href")&&e!=="script"&&zn(s,"data:")===0&&Ct[e])){if(!(Ot&&!P(cn,ye(s,Et,"")))){if(s)return!1}}}}}}}return!0},Ut=function(e){return e!=="annotation-xml"&&dt(e,un)},Ht=function(e){ee(g.beforeSanitizeAttributes,e,null);const{attributes:n}=e;if(!n||at(e))return;const s={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:D,forceKeepAttr:void 0};let y=n.length;for(;y--;){const M=n[y],{name:R,namespaceURI:H,value:G}=M,oe=b(R),it=G;let L=R==="value"?it:Gn(it);if(s.attrName=oe,s.attrValue=L,s.keepAttr=!0,s.forceKeepAttr=void 0,ee(g.uponSanitizeAttribute,e,s),L=s.attrValue,wt&&(oe==="id"||oe==="name")&&(me(R,e),L=fn+L),Ce&&P(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,L)){me(R,e);continue}if(oe==="attributename"&&dt(L,"href")){me(R,e);continue}if(s.forceKeepAttr)continue;if(!s.keepAttr){me(R,e);continue}if(!Rt&&P(/\/>/i,L)){me(R,e);continue}de&&Ie([a,k,se],Bt=>{L=ye(L,Bt," ")});const Gt=b(e.nodeName);if(!Ft(Gt,oe,L)){me(R,e);continue}if(o&&typeof J=="object"&&typeof J.getAttributeType=="function"&&!H)switch(J.getAttributeType(Gt,oe)){case"TrustedHTML":{L=o.createHTML(L);break}case"TrustedScriptURL":{L=o.createScriptURL(L);break}}if(L!==it)try{H?e.setAttributeNS(H,R,L):e.setAttribute(R,L),at(e)?$(e):Xt(t.removed)}catch{me(R,e)}}ee(g.afterSanitizeAttributes,e,null)},zt=function(e){let n=null;const s=Nt(e);for(ee(g.beforeSanitizeShadowDOM,e,null);n=s.nextNode();)ee(g.uponSanitizeShadowNode,n,null),Pt(n),Ht(n),n.content instanceof E&&zt(n.content);ee(g.afterSanitizeShadowDOM,e,null)};return t.sanitize=function(i){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=null,s=null,y=null,M=null;if(tt=!i,tt&&(i="<!-->"),typeof i!="string"&&!ot(i))if(typeof i.toString=="function"){if(i=i.toString(),typeof i!="string")throw Ne("dirty is not a string, aborting")}else throw Ne("toString is not a function");if(!t.isSupported)return i;if(Ke||st(e),t.removed=[],typeof i=="string"&&(De=!1),De){if(i.nodeName){const G=b(i.nodeName);if(!w[G]||we[G])throw Ne("root node is forbidden and cannot be sanitized in-place")}}else if(i instanceof S)n=xt("<!---->"),s=n.ownerDocument.importNode(i,!0),s.nodeType===Fe.element&&s.nodeName==="BODY"||s.nodeName==="HTML"?n=s:n.appendChild(s);else{if(!ge&&!de&&!pe&&i.indexOf("<")===-1)return o&&Be?o.createHTML(i):i;if(n=xt(i),!n)return ge?null:Be?C:""}n&&Qe&&$(n.firstChild);const R=Nt(De?i:n);for(;y=R.nextNode();)Pt(y),Ht(y),y.content instanceof E&&zt(y.content);if(De)return i;if(ge){if(de){n.normalize();let G=n.innerHTML;Ie([a,k,se],oe=>{G=ye(G,oe," ")}),n.innerHTML=G}if(Ge)for(M=be.call(n.ownerDocument);n.firstChild;)M.appendChild(n.firstChild);else M=n;return(D.shadowroot||D.shadowrootmode)&&(M=h.call(l,M,!0)),M}let H=pe?n.outerHTML:n.innerHTML;return pe&&w["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&P(an,n.ownerDocument.doctype.name)&&(H="<!DOCTYPE "+n.ownerDocument.doctype.name+`>
2
- `+H),de&&Ie([a,k,se],G=>{H=ye(H,G," ")}),o&&Be?o.createHTML(H):H},t.setConfig=function(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};st(i),Ke=!0},t.clearConfig=function(){Ae=null,Ke=!1},t.isValidAttribute=function(i,e,n){Ae||st({});const s=b(i),y=b(e);return Ft(s,y,n)},t.addHook=function(i,e){typeof e=="function"&&xe(g[i],e)},t.removeHook=function(i,e){if(e!==void 0){const n=Un(g[i],e);return n===-1?void 0:Hn(g[i],n,1)[0]}return Xt(g[i])},t.removeHooks=function(i){g[i]=[]},t.removeAllHooks=function(){g=Jt()},t}var en=on();const ns=[{id:"doc-convert",name:"文档格式转换",icon:"FileTextOutlined",category:"document",description:"Word、Markdown、HTML、PDF 之间的格式互转",examples:["把 report.docx 转成 PDF","合并多个 Markdown 为一个文档"],acceptsFiles:!0},{id:"media-process",name:"音视频处理",icon:"PlayCircleOutlined",category:"media",description:"视频压缩、音频提取、格式转换、剪辑",examples:["提取 MP4 的音频","压缩视频到 50MB 以内"],acceptsFiles:!0},{id:"data-analysis",name:"数据分析",icon:"BarChartOutlined",category:"data",description:"CSV/Excel 分析、统计、可视化图表",examples:["分析 sales.csv 的月度趋势"],acceptsFiles:!0},{id:"web-research",name:"信息检索与调研",icon:"SearchOutlined",category:"research",description:"网页抓取、API 调用、多源信息汇总",examples:["调研 AI Agent 框架对比"],acceptsFiles:!1},{id:"image-process",name:"图片处理",icon:"PictureOutlined",category:"media",description:"批量压缩、格式转换、加水印、OCR",examples:["批量压缩到 500KB"],acceptsFiles:!0},{id:"code-helper",name:"代码辅助",icon:"CodeOutlined",category:"development",description:"生成脚本、调试代码、自动化任务",examples:["写一个批量重命名脚本"],acceptsFiles:!0},{id:"system-admin",name:"系统运维",icon:"DesktopOutlined",category:"system",description:"磁盘分析、进程管理、日志分析",examples:["查看磁盘使用情况"],acceptsFiles:!1},{id:"file-organize",name:"文件整理",icon:"FolderOpenOutlined",category:"file",description:"批量重命名、分类整理、查找重复",examples:["按文件类型分类整理"],acceptsFiles:!1},{id:"network-tools",name:"网络工具",icon:"GlobalOutlined",category:"network",description:"API 调试、网页抓取、网络诊断",examples:["测试 API 接口"],acceptsFiles:!1},{id:"learning-assist",name:"学习辅助",icon:"ReadOutlined",category:"learning",description:"文档翻译、内容总结、论文分析",examples:["翻译 PDF 摘要"],acceptsFiles:!0}],ss=Tn("cowork",()=>{const u=I(ns),t=I(null),c=I([]),l=I(!1),_=I([]),E=I([]),x=I(null),S=I(null),z=I(null),B=I([]),re=he();tn(()=>re.isLoading,d=>{!d&&S.value&&(l.value=!1)});function ve(d){t.value=d,ce()}function ce(){_.value=[],E.value=[],x.value=null,l.value=!1,S.value=null,z.value=null}function J(d){c.value.includes(d)||c.value.push(d)}function j(d){c.value=c.value.filter(h=>h!==d)}async function Se(){const d=ut();try{await d.waitConnected(5e3);const h=await d.sendRaw({type:"cowork-templates"},1e4);h?.templates?.length&&(u.value=h.templates)}catch{}}async function Oe(){const d=ut();try{await d.waitConnected(5e3);const h=await d.sendRaw({type:"cowork-history",limit:50},1e4);h?.entries&&(B.value=h.entries)}catch{}}async function ne(d){z.value={mode:"session",message:d},l.value=!0;const h=t.value;let g="";h&&(g=`## 当前任务类型: ${h.name}
3
- ${h.description||""}`);let a=d;c.value.length&&(a+=`
4
-
5
- [用户提供的文件: ${c.value.join(", ")}]`),E.value.push({role:"user",content:d,timestamp:Date.now()});const k={systemPromptExtension:g};h?.shellPolicyOverrides&&(k.shellPolicyOverrides=h.shellPolicyOverrides);const se=await re.createSession("agent",k);S.value=se,await re.sendMessage(se,a)}async function ue(d){z.value={mode:"direct",message:d};const h=ut();l.value=!0,E.value.push({role:"user",content:d,timestamp:Date.now()});try{await h.waitConnected(8e3);const g=await h.sendRaw({type:"cowork-task",templateId:t.value?.id||null,userMessage:d,files:c.value},3e5);E.value.push({role:"assistant",content:g.summary||"(No output)",timestamp:Date.now(),toolsUsed:g.toolsUsed||[],iterationCount:g.iterationCount||0}),x.value=g}catch(g){E.value.push({role:"assistant",content:`Error: ${g.message}`,timestamp:Date.now()})}finally{l.value=!1}}const A=He(()=>S.value?he().getMessages(S.value):[]),o=He(()=>{if(!S.value)return null;const h=he().streaming[S.value];return h?.active?h.content:null}),C=He(()=>S.value&&he().pendingQuestion[S.value]||null);function fe(d){if(!S.value)return;he().answerQuestion(S.value,d)}async function Re(){if(!z.value)return;const{mode:d,message:h}=z.value;d==="direct"?await ue(h):await ne(h)}async function be(d){if(!S.value)return;const h=he();E.value.push({role:"user",content:d,timestamp:Date.now()});let g=d;c.value.length&&(g+=`
6
-
7
- [用户提供的文件: ${c.value.join(", ")}]`),await h.sendMessage(S.value,g)}return{selectedTemplate:t,files:c,isRunning:l,steps:_,messages:E,result:x,agentSessionId:S,currentAgentMessages:A,currentStreaming:o,currentQuestion:C,selectTemplate:ve,reset:ce,addFile:J,removeFile:j,execute:ne,executeDirectWs:ue,sendFollowUp:be,answerQuestion:fe,loadTemplates:Se,templates:u,lastRequest:z,retry:Re,history:B,loadHistory:Oe}}),as={class:"cowork-root"},os={class:"template-panel"},is={class:"template-header"},ls={class:"template-list"},rs=["onClick"],cs={class:"card-icon"},us={class:"card-body"},fs={class:"card-name"},ds={class:"card-desc"},ps={class:"card-icon"},ms={class:"drop-text"},_s={key:0,class:"file-list"},hs={key:1,class:"history-section"},gs={key:0,class:"history-list"},Ts={class:"history-summary"},Es={class:"history-meta"},As={class:"exec-panel"},ys={key:0,class:"empty-state"},vs={class:"empty-icon"},Ss={class:"example-grid"},Os=["onClick"],Rs={key:1,class:"ready-state"},bs={class:"ready-header"},ws={class:"ready-name"},Cs={class:"ready-examples"},Ds=["onClick"],Ls={key:0,class:"tool-msg"},ks={class:"tool-input"},Ms={key:0,class:"tool-result-box"},Is={class:"tool-result"},xs={key:1,class:"user-msg"},Ns={class:"bubble user"},Ps={key:2,class:"assistant-msg"},Fs=["innerHTML"],Us={key:0,class:"assistant-msg"},Hs=["innerHTML"],zs={key:1,class:"question-card"},Gs={class:"question-text"},Bs={key:0,class:"question-choices"},Ws={key:3,class:"task-stats"},Ys={class:"input-area"},$s={key:0,class:"input-context"},Vs={class:"input-row"},Xs={__name:"Cowork",setup(u){Yt.setOptions({highlight:(A,o)=>o&&ct.getLanguage(o)?ct.highlight(A,{language:o}).value:ct.highlightAuto(A).value,breaks:!0});const t=ss(),c=he(),l=I(""),_=I(null),E=I(!1),x=I(""),S=I(!1),z=I(!1),B={FileTextOutlined:Mn,PlayCircleOutlined:kn,BarChartOutlined:Ln,SearchOutlined:Dn,PictureOutlined:Cn,CodeOutlined:wn,DesktopOutlined:bn,FolderOpenOutlined:$t,GlobalOutlined:Rn,ReadOutlined:On},re=["把 report.docx 转成 PDF","压缩视频到 50MB","分析 CSV 生成图表","查询今天的汇率","批量压缩图片","写一个自动化脚本"],ve=He(()=>c.isLoading?"等待响应中...":t.selectedTemplate?t.selectedTemplate.examples?.[0]||"描述你的需求...":"描述你想完成的任务,Agent 会帮你搞定"),ce=He(()=>t.currentAgentMessages);function J(A){try{return en.sanitize(Yt(A||""))}catch{return en.sanitize(A||"")}}function j(A){return A.split(/[\\/]/).pop()||A}function Se(A){E.value=!1;const o=A.dataTransfer?.files;if(o)for(const C of o)t.addFile(C.path||C.name)}function Oe(){const A=x.value.trim();A&&(t.addFile(A),x.value="")}async function ne(){const A=l.value.trim();!A||c.isLoading||(l.value="",t.agentSessionId?await t.sendFollowUp(A):await t.execute(A))}function ue(A){l.value=A,Wt(()=>ne())}return tn([ce,()=>t.currentStreaming],()=>{Wt(()=>{_.value&&(_.value.scrollTop=_.value.scrollHeight)})},{deep:!0}),En(()=>{c.loadSessions(),t.loadTemplates(),t.loadHistory()}),(A,o)=>{const C=_e("a-tag"),fe=_e("a-input"),Re=_e("a-collapse-panel"),be=_e("a-collapse"),d=_e("a-button"),h=_e("a-input-search"),g=_e("a-textarea");return p(),T("div",as,[f("div",os,[f("div",is,[N(r(Me),{class:"header-icon"}),o[7]||(o[7]=f("span",{class:"header-title"},"日常协作",-1))]),o[9]||(o[9]=f("div",{class:"template-hint"},"选择任务类型,或直接输入需求",-1)),f("div",ls,[(p(!0),T(ie,null,le(r(t).templates,a=>(p(),T("div",{key:a.id,class:ke(["template-card",{active:r(t).selectedTemplate?.id===a.id}]),onClick:k=>r(t).selectTemplate(a)},[f("div",cs,[(p(),te(rt(B[a.icon]||r(Me))))]),f("div",us,[f("div",fs,v(a.name),1),f("div",ds,v(a.description),1)])],10,rs))),128)),f("div",{class:ke(["template-card free",{active:r(t).selectedTemplate===null&&S.value}]),onClick:o[0]||(o[0]=a=>{r(t).selectTemplate(null),S.value=!0})},[f("div",ps,[N(r(vn))]),o[8]||(o[8]=f("div",{class:"card-body"},[f("div",{class:"card-name"},"自由提问"),f("div",{class:"card-desc"},"任意任务,Agent 自主完成")],-1))],2)]),r(t).selectedTemplate?.acceptsFiles!==!1?(p(),T("div",{key:0,class:ke(["file-zone",{dragging:E.value}]),onDragover:o[2]||(o[2]=lt(a=>E.value=!0,["prevent"])),onDragleave:o[3]||(o[3]=a=>E.value=!1),onDrop:lt(Se,["prevent"])},[N(r($t),{class:"drop-icon"}),f("div",ms,v(E.value?"松开以添加文件":"拖拽文件到此处"),1),r(t).files.length?(p(),T("div",_s,[(p(!0),T(ie,null,le(r(t).files,a=>(p(),te(C,{key:a,closable:"",onClose:k=>r(t).removeFile(a),class:"file-tag"},{default:W(()=>[Q(v(j(a)),1)]),_:2},1032,["onClose"]))),128))])):V("",!0),N(fe,{value:x.value,"onUpdate:value":o[1]||(o[1]=a=>x.value=a),placeholder:"或输入文件路径,按 Enter 添加",size:"small",class:"path-input",onPressEnter:Oe},null,8,["value"])],34)):V("",!0),r(t).history.length?(p(),T("div",hs,[f("div",{class:"history-header",onClick:o[4]||(o[4]=a=>z.value=!z.value)},[N(r(Sn)),Q(" 历史记录 ("+v(r(t).history.length)+") ",1)]),z.value?(p(),T("div",gs,[(p(!0),T(ie,null,le(r(t).history.slice().reverse().slice(0,20),(a,k)=>(p(),T("div",{key:k,class:ke(["history-item",a.status])},[f("div",Ts,v(a.userMessage),1),f("div",Es,[f("span",null,v(a.templateName||"自由模式"),1),f("span",null,v(a.status),1)])],2))),128))])):V("",!0)])):V("",!0)]),f("div",As,[!r(t).agentSessionId&&!r(t).selectedTemplate?(p(),T("div",ys,[f("div",vs,[N(r(Me))]),o[10]||(o[10]=f("div",{class:"empty-title"},"选择一个任务模板开始",-1)),o[11]||(o[11]=f("div",{class:"empty-sub"},"或选择「自由提问」处理任何问题",-1)),f("div",Ss,[(p(),T(ie,null,le(re,a=>f("div",{key:a,class:"example-chip",onClick:k=>ue(a)},v(a),9,Os)),64))])])):r(t).selectedTemplate&&!r(t).agentSessionId?(p(),T("div",Rs,[f("div",bs,[(p(),te(rt(B[r(t).selectedTemplate.icon]||r(Me)),{class:"ready-icon"})),f("span",ws,v(r(t).selectedTemplate.name),1)]),f("div",Cs,[o[12]||(o[12]=f("div",{class:"example-label"},"试试这些:",-1)),(p(!0),T(ie,null,le(r(t).selectedTemplate.examples,a=>(p(),T("div",{key:a,class:"example-chip",onClick:k=>ue(a)},v(a),9,Ds))),128))])])):(p(),T("div",{key:2,class:"messages-area",ref_key:"messagesEl",ref:_},[(p(!0),T(ie,null,le(ce.value,(a,k)=>(p(),T("div",{key:k,class:ke(["message-row",a.role])},[a.role==="tool"?(p(),T("div",Ls,[N(be,{ghost:"",size:"small"},{default:W(()=>[N(Re,{class:"tool-collapse"},{header:W(()=>[N(r(In)),Q(" "+v(a.tool)+" "+v(a.status==="running"?"(执行中...)":"✓"),1)]),default:W(()=>[f("pre",ks,v(JSON.stringify(a.input,null,2)),1),a.result?(p(),T("div",Ms,[f("pre",Is,v(typeof a.result=="string"?a.result:JSON.stringify(a.result,null,2)),1)])):V("",!0)]),_:2},1024)]),_:2},1024)])):a.role==="user"?(p(),T("div",xs,[f("div",Ns,v(a.content),1)])):(p(),T("div",Ps,[o[14]||(o[14]=f("div",{class:"avatar"},"AI",-1)),f("div",{class:"bubble assistant",innerHTML:J(a.content)},null,8,Fs),a.content?.startsWith("Error:")&&!r(t).isRunning&&r(t).lastRequest?(p(),te(d,{key:0,size:"small",type:"link",onClick:o[5]||(o[5]=se=>r(t).retry())},{default:W(()=>[...o[13]||(o[13]=[Q(" 重试 ",-1)])]),_:1})):V("",!0)]))],2))),128)),r(t).currentStreaming?(p(),T("div",Us,[o[15]||(o[15]=f("div",{class:"avatar"},"AI",-1)),f("div",{class:"bubble assistant streaming",innerHTML:J(r(t).currentStreaming)},null,8,Hs)])):V("",!0),r(t).currentQuestion?(p(),T("div",zs,[f("div",Gs,v(r(t).currentQuestion.question),1),r(t).currentQuestion.choices?.length?(p(),T("div",Bs,[(p(!0),T(ie,null,le(r(t).currentQuestion.choices,a=>(p(),te(d,{key:a,size:"small",onClick:k=>r(t).answerQuestion(a)},{default:W(()=>[Q(v(a),1)]),_:2},1032,["onClick"]))),128))])):(p(),te(h,{key:1,placeholder:"输入回答...","enter-button":"发送",style:{"margin-top":"10px"},onSearch:r(t).answerQuestion},null,8,["onSearch"]))])):V("",!0)],512)),r(t).result&&!r(t).isRunning?(p(),T("div",Ws,[N(C,{color:"geekblue"},{default:W(()=>[Q(v(r(t).result.iterationCount||0)+" iterations",1)]),_:1}),N(C,{color:"cyan"},{default:W(()=>[Q("~"+v((r(t).result.tokenCount||0).toLocaleString())+" tokens",1)]),_:1}),r(t).result.toolsUsed?.length?(p(),te(C,{key:0,color:"green"},{default:W(()=>[Q(v(r(t).result.toolsUsed.length)+" tools",1)]),_:1})):V("",!0)])):V("",!0),f("div",Ys,[r(t).selectedTemplate?(p(),T("div",$s,[N(C,{color:"blue",class:"context-tag"},{default:W(()=>[(p(),te(rt(B[r(t).selectedTemplate.icon]||r(Me)))),Q(" "+v(r(t).selectedTemplate.name),1)]),_:1}),(p(!0),T(ie,null,le(r(t).files,a=>(p(),te(C,{key:a,class:"context-tag file"},{default:W(()=>[Q(v(j(a)),1)]),_:2},1024))),128))])):V("",!0),f("div",Vs,[N(g,{value:l.value,"onUpdate:value":o[6]||(o[6]=a=>l.value=a),placeholder:ve.value,"auto-size":{minRows:1,maxRows:6},disabled:r(c).isLoading,class:"msg-input",onKeydown:An(lt(ne,["exact","prevent"]),["enter"])},null,8,["value","placeholder","disabled","onKeydown"]),N(d,{type:"primary",loading:r(c).isLoading,class:"send-btn",onClick:ne},{icon:W(()=>[N(r(xn))]),_:1},8,["loading"])])])])])}}},ta=yn(Xs,[["__scopeId","data-v-4cf2adfc"]]);export{ta as default};
@@ -1 +0,0 @@
1
- .cowork-root[data-v-4cf2adfc]{display:flex;height:calc(100vh - 104px);gap:16px}.template-panel[data-v-4cf2adfc]{width:280px;flex-shrink:0;background:var(--bg-card);border-radius:8px;border:1px solid var(--border-color);display:flex;flex-direction:column;overflow:hidden}.template-header[data-v-4cf2adfc]{padding:16px 16px 8px;display:flex;align-items:center;gap:8px;font-size:16px;font-weight:600;color:var(--text-primary)}.header-icon[data-v-4cf2adfc]{font-size:18px;color:#1677ff}.template-hint[data-v-4cf2adfc]{padding:0 16px 12px;font-size:12px;color:var(--text-muted);border-bottom:1px solid var(--border-color)}.template-list[data-v-4cf2adfc]{flex:1;overflow-y:auto;padding:8px}.template-card[data-v-4cf2adfc]{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border-radius:8px;cursor:pointer;transition:all .15s;margin-bottom:4px;border:1px solid transparent}.template-card[data-v-4cf2adfc]:hover{background:var(--bg-card-hover)}.template-card.active[data-v-4cf2adfc]{background:#1677ff14;border-color:#1677ff4d}.template-card.free .card-icon[data-v-4cf2adfc]{color:#faad14}.card-icon[data-v-4cf2adfc]{width:32px;height:32px;display:flex;align-items:center;justify-content:center;font-size:16px;color:#1677ff;background:#1677ff14;border-radius:8px;flex-shrink:0;margin-top:2px}.card-name[data-v-4cf2adfc]{font-size:13px;font-weight:500;color:var(--text-primary)}.card-desc[data-v-4cf2adfc]{font-size:11px;color:var(--text-muted);margin-top:2px;line-height:1.4}.file-zone[data-v-4cf2adfc]{padding:12px;border-top:1px solid var(--border-color);text-align:center;transition:background .2s}.file-zone.dragging[data-v-4cf2adfc]{background:#1677ff14}.drop-icon[data-v-4cf2adfc]{font-size:20px;color:var(--text-muted)}.drop-text[data-v-4cf2adfc]{font-size:11px;color:var(--text-muted);margin:4px 0 8px}.file-list[data-v-4cf2adfc]{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px;justify-content:center}.file-tag[data-v-4cf2adfc]{max-width:140px;overflow:hidden;text-overflow:ellipsis;font-size:11px}.path-input[data-v-4cf2adfc]{font-size:11px}.exec-panel[data-v-4cf2adfc]{flex:1;background:var(--bg-card);border-radius:8px;border:1px solid var(--border-color);display:flex;flex-direction:column;overflow:hidden}.empty-state[data-v-4cf2adfc],.ready-state[data-v-4cf2adfc]{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:40px 24px}.empty-icon[data-v-4cf2adfc]{font-size:48px;color:#1677ff40;margin-bottom:16px}.empty-title[data-v-4cf2adfc]{font-size:16px;color:var(--text-primary);margin-bottom:6px}.empty-sub[data-v-4cf2adfc]{font-size:13px;color:var(--text-muted);margin-bottom:24px}.ready-header[data-v-4cf2adfc]{display:flex;align-items:center;gap:10px;margin-bottom:20px}.ready-icon[data-v-4cf2adfc]{font-size:28px;color:#1677ff}.ready-name[data-v-4cf2adfc]{font-size:18px;font-weight:600;color:var(--text-primary)}.ready-examples[data-v-4cf2adfc]{text-align:center}.example-label[data-v-4cf2adfc]{font-size:13px;color:var(--text-muted);margin-bottom:12px}.example-grid[data-v-4cf2adfc]{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;max-width:500px}.example-chip[data-v-4cf2adfc]{padding:6px 14px;border-radius:16px;font-size:12px;color:var(--text-primary);background:var(--bg-card-hover);border:1px solid var(--border-color);cursor:pointer;transition:all .15s}.example-chip[data-v-4cf2adfc]:hover{border-color:#1677ff;background:#1677ff14;color:#1677ff}.messages-area[data-v-4cf2adfc]{flex:1;overflow-y:auto;padding:20px}.message-row[data-v-4cf2adfc]{margin-bottom:16px}.user-msg[data-v-4cf2adfc]{display:flex;justify-content:flex-end}.assistant-msg[data-v-4cf2adfc]{display:flex;gap:10px;align-items:flex-start}.avatar[data-v-4cf2adfc]{width:32px;height:32px;border-radius:50%;background:#1677ff;display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;color:var(--text-primary);flex-shrink:0}.bubble[data-v-4cf2adfc]{padding:10px 14px;border-radius:12px;max-width:80%;line-height:1.6;font-size:14px}.bubble.user[data-v-4cf2adfc]{background:#1677ff;color:var(--text-primary);border-bottom-right-radius:4px}.bubble.assistant[data-v-4cf2adfc]{background:var(--bg-card-hover);color:var(--text-primary);border-bottom-left-radius:4px}.bubble.streaming[data-v-4cf2adfc]:after{content:"○";animation:blink-4cf2adfc .7s step-start infinite;color:#1677ff}@keyframes blink-4cf2adfc{50%{opacity:0}}.tool-msg[data-v-4cf2adfc]{margin:8px 0}.tool-collapse[data-v-4cf2adfc]{border:1px solid var(--border-color);border-radius:6px;background:var(--bg-card)}.tool-input[data-v-4cf2adfc]{margin:0;font-size:11px;color:#aaa;white-space:pre-wrap}.tool-result-box[data-v-4cf2adfc]{margin-top:8px;padding-top:8px;border-top:1px solid var(--border-color)}.tool-result[data-v-4cf2adfc]{margin:0;font-size:11px;color:#52c41a;white-space:pre-wrap}.question-card[data-v-4cf2adfc]{background:var(--bg-card-hover);border:1px solid #1677ff40;border-radius:10px;padding:14px 16px;margin-top:8px}.question-text[data-v-4cf2adfc]{color:#aaa;font-size:13px}.question-choices[data-v-4cf2adfc]{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}.task-stats[data-v-4cf2adfc]{display:flex;gap:6px;padding:6px 16px;border-top:1px solid var(--border-color);justify-content:flex-end}.input-area[data-v-4cf2adfc]{padding:12px 16px 16px;border-top:1px solid var(--border-color)}.input-context[data-v-4cf2adfc]{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px}.context-tag[data-v-4cf2adfc]{font-size:11px}.context-tag.file[data-v-4cf2adfc]{background:var(--bg-card-hover)}.input-row[data-v-4cf2adfc]{display:flex;gap:8px;align-items:flex-end}.msg-input[data-v-4cf2adfc]{flex:1;background:var(--bg-card-hover);border-color:var(--border-color);color:var(--text-primary);resize:none}.send-btn[data-v-4cf2adfc]{height:40px}[data-v-4cf2adfc] .bubble.assistant pre{background:var(--bg-base);border-radius:6px;padding:12px;overflow-x:auto;font-size:12px}[data-v-4cf2adfc] .bubble.assistant code:not(pre code){background:var(--bg-card-hover);padding:1px 5px;border-radius:3px;font-size:12px;color:#f0a500}[data-v-4cf2adfc] .bubble.assistant p{margin:0 0 8px}[data-v-4cf2adfc] .bubble.assistant p:last-child{margin:0}.history-section[data-v-4cf2adfc]{margin-top:12px;border-top:1px solid var(--border-color);padding-top:8px}.history-header[data-v-4cf2adfc]{display:flex;align-items:center;gap:6px;font-size:12px;color:#888;cursor:pointer;padding:4px 0}.history-header[data-v-4cf2adfc]:hover{color:#1677ff}.history-list[data-v-4cf2adfc]{max-height:200px;overflow-y:auto}.history-item[data-v-4cf2adfc]{padding:6px 8px;border-radius:6px;margin-bottom:4px;background:var(--bg-card-hover);cursor:default}.history-item.failed[data-v-4cf2adfc]{border-left:2px solid #ff4d4f}.history-item.completed[data-v-4cf2adfc]{border-left:2px solid #52c41a}.history-summary[data-v-4cf2adfc]{font-size:12px;color:var(--text-primary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.history-meta[data-v-4cf2adfc]{display:flex;justify-content:space-between;font-size:10px;color:#888;margin-top:2px}
@@ -1 +0,0 @@
1
- .stat-card[data-v-39c5aabc]{background:var(--bg-card)!important;border-color:var(--border-color)!important;transition:border-color .2s}.stat-card[data-v-39c5aabc]:hover{border-color:var(--text-muted)!important}.stat-header[data-v-39c5aabc]{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}.stat-label[data-v-39c5aabc]{color:var(--text-secondary);font-size:12px}.stat-value[data-v-39c5aabc]{font-size:22px;font-weight:600;line-height:1.2;margin-bottom:4px}.stat-sub[data-v-39c5aabc]{color:var(--text-muted);font-size:11px}.gateway-card[data-v-39c5aabc]{border-left:3px solid #1677ff!important}.status-log[data-v-39c5aabc]{background:var(--bg-base);border:1px solid var(--border-color);border-radius:6px;padding:10px 14px;color:var(--text-secondary);font-size:11px;font-family:Consolas,monospace;max-height:200px;overflow-y:auto;white-space:pre-wrap;margin:0;line-height:1.6}.telemetry-card[data-v-39c5aabc]{background:var(--bg-base);border:1px solid var(--border-color);border-radius:8px;padding:14px;height:100%}.telemetry-filter[data-v-39c5aabc]{display:flex;flex-direction:column;gap:6px}.telemetry-filter-label[data-v-39c5aabc]{color:var(--text-muted);font-size:12px}.telemetry-label[data-v-39c5aabc]{color:var(--text-muted);font-size:12px;margin-bottom:6px}.telemetry-value[data-v-39c5aabc]{color:#91caff;font-size:24px;font-weight:600;line-height:1.2}.telemetry-sub[data-v-39c5aabc]{color:var(--text-secondary);font-size:11px;margin-top:4px}.telemetry-section[data-v-39c5aabc]{background:var(--bg-base);border:1px solid var(--border-color);border-radius:8px;padding:14px;min-height:140px}.telemetry-section-title[data-v-39c5aabc]{color:var(--text-secondary);font-size:12px;margin-bottom:10px}.telemetry-list[data-v-39c5aabc]{display:flex;flex-direction:column;gap:8px}.telemetry-row[data-v-39c5aabc]{display:flex;justify-content:space-between;gap:12px;color:var(--text-secondary);font-size:12px}.telemetry-empty[data-v-39c5aabc]{color:var(--text-muted);font-size:12px}