@storvia/sdk 0.2.2 → 0.3.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.
- package/dist/index.cjs.js +484 -227
- package/dist/index.d.mts +8 -5
- package/dist/index.esm.js +484 -227
- package/dist/index.umd.js +484 -227
- package/package.json +14 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1,431 +1,688 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);for(let
|
|
1
|
+
"use strict";var M=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var z=(l,e)=>{for(var t in e)M(l,t,{get:e[t],enumerable:!0})},j=(l,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of F(e))!G.call(l,i)&&i!==t&&M(l,i,{get:()=>e[i],enumerable:!(n=A(e,i))||n.enumerable});return l};var V=l=>j(M({},"__esModule",{value:!0}),l);var se={};z(se,{StorviaError:()=>p,StorviaSDK:()=>T,createStorviaSDK:()=>H,extractFieldValue:()=>U,isRichFieldValue:()=>$});module.exports=V(se);var p=class extends Error{constructor(e,t){super(t),this.name="StorviaError",this.code=e}};var P=class{constructor(e,t,n=!1,i=""){this.baseUrl=e,this.token=t,this.debug=n,this.devApiKey=i}setToken(e){this.token=e}setDebug(e){this.debug=e}buildHeaders(){let e={"Content-Type":"application/json"};return this.token&&(e.Authorization=`Bearer ${this.token}`),this.devApiKey&&(e["x-api-key"]=this.devApiKey),e}log(e,t,n,i,s){if(!this.debug)return;let r="%c[Storvia SDK]",o="color: #6366f1; font-weight: bold";s?(console.groupCollapsed(`${r} %c${e} ${t} %c\u2717`,o,"color: #e0e0e0","color: #ef4444"),n&&console.log("Request:",n),console.error("Error:",s),console.groupEnd()):(console.groupCollapsed(`${r} %c${e} ${t} %c\u2713`,o,"color: #e0e0e0","color: #22c55e"),n&&console.log("Request:",n),i!==void 0&&console.log("Response:",i),console.groupEnd())}async get(e,t){let n=new URL(`${this.baseUrl}${e}`);t&&Object.entries(t).forEach(([i,s])=>n.searchParams.set(i,s));try{let i=await fetch(n.toString(),{method:"GET",headers:this.buildHeaders()}),s=await this.handleResponse(i);return this.log("GET",e,t,s),s}catch(i){throw this.log("GET",e,t,void 0,i),i}}async post(e,t){try{let n=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0}),i=await this.handleResponse(n);return this.log("POST",e,t,i),i}catch(n){throw this.log("POST",e,t,void 0,n),n}}async patch(e,t){try{let n=await fetch(`${this.baseUrl}${e}`,{method:"PATCH",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0}),i=await this.handleResponse(n);return this.log("PATCH",e,t,i),i}catch(n){throw this.log("PATCH",e,t,void 0,n),n}}async delete(e){try{let t=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.buildHeaders()}),n=await this.handleResponse(t);return this.log("DELETE",e,void 0,n),n}catch(t){throw this.log("DELETE",e,void 0,void 0,t),t}}async stream(e,t,n,i){this.log("STREAM",e,t);let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!s.ok){let d=await s.json().catch(()=>({})),h=new p(d.code||"INTERNAL_ERROR",d.message||`HTTP ${s.status}`);throw this.log("STREAM",e,t,void 0,h),h}let r=s.body?.getReader();if(!r)throw new p("INTERNAL_ERROR","No response body for stream");let o=new TextDecoder,a="",c="";for(;;){let{done:d,value:h}=await r.read();if(d)break;let v=o.decode(h,{stream:!0}).split(`
|
|
2
|
+
`);for(let f of v){if(!f.startsWith("data: "))continue;let L=f.slice(6);if(L==="[DONE]"){this.debug&&this.log("STREAM",e+" [done]",void 0,{id:a,contentLength:c.length}),i(a);return}try{let b=JSON.parse(L);b.type==="done"&&b.id?a=b.id:b.content&&(c+=b.content,n(b.content))}catch{}}}a&&i(a)}async handleResponse(e){if(!e.ok){let n={};try{n=await e.json()}catch{}let i={401:"UNAUTHORIZED",402:"INSUFFICIENT_BALANCE",404:"GAME_NOT_FOUND",429:"RATE_LIMITED"},s=n.code||i[e.status]||"INTERNAL_ERROR";throw new p(s,n.message||`HTTP ${e.status}`)}let t=await e.json();return t&&typeof t=="object"&&"data"in t?t.data:t}};var R=[{value:"zh-CN",label:"\u7B80\u4F53\u4E2D\u6587"},{value:"zh-TW",label:"\u7E41\u9AD4\u4E2D\u6587"},{value:"en",label:"English"},{value:"ja",label:"\u65E5\u672C\u8A9E"},{value:"ko",label:"\uD55C\uAD6D\uC5B4"}],N=[{value:"low",label:"\u7B80\u77ED"},{value:"medium",label:"\u9002\u4E2D"},{value:"high",label:"\u8BE6\u7EC6"}],Y="https://cdn.storvia.ai/default/logo.png",X="https://api.storvia.ai/storage/v1/object/public/storvia/default/credits.png",W=`
|
|
3
3
|
:host {
|
|
4
4
|
position: fixed;
|
|
5
|
-
bottom: 20px;
|
|
6
|
-
right: 20px;
|
|
7
5
|
z-index: 2147483647;
|
|
8
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
6
|
+
font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* \u2500\u2500 FAB \u2500\u2500 */
|
|
10
|
+
.fab-wrap {
|
|
11
|
+
position: relative;
|
|
12
|
+
display: inline-block;
|
|
13
|
+
touch-action: none;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
.fab {
|
|
12
17
|
width: 48px;
|
|
13
18
|
height: 48px;
|
|
14
19
|
border-radius: 50%;
|
|
15
|
-
background:
|
|
16
|
-
|
|
20
|
+
background: rgba(255, 255, 255, 0.1);
|
|
21
|
+
backdrop-filter: blur(10px);
|
|
22
|
+
-webkit-backdrop-filter: blur(10px);
|
|
17
23
|
border: none;
|
|
18
|
-
cursor:
|
|
24
|
+
cursor: grab;
|
|
19
25
|
display: flex;
|
|
20
26
|
align-items: center;
|
|
21
27
|
justify-content: center;
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
user-select: none;
|
|
30
|
+
-webkit-user-select: none;
|
|
31
|
+
transition: transform 0.2s, background 0.15s;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
.fab:hover {
|
|
27
|
-
transform: scale(1.
|
|
28
|
-
|
|
35
|
+
transform: scale(1.06);
|
|
36
|
+
background: rgba(255, 255, 255, 0.15);
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
.fab
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
.fab.dragging {
|
|
40
|
+
cursor: grabbing;
|
|
41
|
+
transition: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.fab img {
|
|
45
|
+
width: 32px;
|
|
46
|
+
height: 32px;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
display: block;
|
|
34
49
|
}
|
|
35
50
|
|
|
51
|
+
.fab-dot {
|
|
52
|
+
position: absolute;
|
|
53
|
+
top: 2px;
|
|
54
|
+
right: 2px;
|
|
55
|
+
width: 10px;
|
|
56
|
+
height: 10px;
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
background: #f87171;
|
|
59
|
+
border: 2px solid #1e1e1e;
|
|
60
|
+
display: none;
|
|
61
|
+
pointer-events: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.fab-dot.visible {
|
|
65
|
+
display: block;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* \u2500\u2500 Panel \u2500\u2500 */
|
|
36
69
|
.panel {
|
|
37
70
|
position: absolute;
|
|
38
|
-
|
|
39
|
-
right: 0;
|
|
40
|
-
width: 320px;
|
|
71
|
+
width: 380px;
|
|
41
72
|
max-height: 80vh;
|
|
42
|
-
overflow-y: auto;
|
|
43
73
|
background: #1e1e1e;
|
|
44
|
-
border:
|
|
45
|
-
|
|
46
|
-
box-shadow: 0 8px 32px rgba(0,0,0,0.6);
|
|
74
|
+
border-radius: 12px;
|
|
75
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
|
47
76
|
display: none;
|
|
77
|
+
flex-direction: column;
|
|
78
|
+
overflow: hidden;
|
|
48
79
|
}
|
|
49
80
|
|
|
50
81
|
.panel.open {
|
|
51
|
-
display:
|
|
82
|
+
display: flex;
|
|
52
83
|
}
|
|
53
84
|
|
|
85
|
+
/* Header */
|
|
54
86
|
.panel-header {
|
|
87
|
+
flex-shrink: 0;
|
|
55
88
|
display: flex;
|
|
56
89
|
align-items: center;
|
|
57
90
|
justify-content: space-between;
|
|
58
|
-
padding: 16px
|
|
91
|
+
padding: 16px;
|
|
59
92
|
}
|
|
60
93
|
|
|
61
94
|
.panel-title {
|
|
62
95
|
font-size: 16px;
|
|
63
96
|
font-weight: 600;
|
|
64
97
|
color: #fff;
|
|
98
|
+
margin: 0;
|
|
65
99
|
}
|
|
66
100
|
|
|
67
101
|
.close-btn {
|
|
68
|
-
width:
|
|
69
|
-
height:
|
|
70
|
-
border-radius: 50%;
|
|
102
|
+
width: 32px;
|
|
103
|
+
height: 32px;
|
|
71
104
|
border: none;
|
|
72
105
|
background: transparent;
|
|
73
|
-
color:
|
|
106
|
+
color: rgba(255, 255, 255, 0.7);
|
|
74
107
|
cursor: pointer;
|
|
108
|
+
border-radius: 8px;
|
|
75
109
|
display: flex;
|
|
76
110
|
align-items: center;
|
|
77
111
|
justify-content: center;
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
transition: background 0.15s, color 0.15s;
|
|
113
|
+
padding: 0;
|
|
80
114
|
}
|
|
81
115
|
|
|
82
116
|
.close-btn:hover {
|
|
117
|
+
background: rgba(130, 70, 255, 0.1);
|
|
118
|
+
color: #fff;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.close-btn svg {
|
|
122
|
+
width: 20px;
|
|
123
|
+
height: 20px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Tabs (segment-control \u6837\u5F0F) */
|
|
127
|
+
.tabs {
|
|
128
|
+
flex-shrink: 0;
|
|
129
|
+
margin: 0 16px 12px;
|
|
130
|
+
display: flex;
|
|
83
131
|
background: #2a2a2a;
|
|
132
|
+
border-radius: 12px;
|
|
133
|
+
padding: 3px;
|
|
134
|
+
gap: 2px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.tab-btn {
|
|
138
|
+
flex: 1;
|
|
139
|
+
padding: 8px 16px;
|
|
140
|
+
background: transparent;
|
|
141
|
+
border: none;
|
|
142
|
+
border-radius: 8px;
|
|
143
|
+
font-size: 13px;
|
|
144
|
+
color: rgba(255, 255, 255, 0.7);
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
transition: all 0.15s;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.tab-btn:hover {
|
|
84
150
|
color: #fff;
|
|
85
151
|
}
|
|
86
152
|
|
|
153
|
+
.tab-btn.active {
|
|
154
|
+
background: #8246FF;
|
|
155
|
+
color: #fff;
|
|
156
|
+
font-weight: 500;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* Body */
|
|
87
160
|
.panel-body {
|
|
88
|
-
|
|
161
|
+
flex: 1;
|
|
162
|
+
overflow-y: auto;
|
|
163
|
+
overscroll-behavior: contain;
|
|
164
|
+
-webkit-overflow-scrolling: touch;
|
|
165
|
+
padding: 0 16px 16px;
|
|
89
166
|
}
|
|
90
167
|
|
|
91
|
-
.
|
|
92
|
-
|
|
168
|
+
.panel-body::-webkit-scrollbar {
|
|
169
|
+
width: 6px;
|
|
93
170
|
}
|
|
94
171
|
|
|
95
|
-
.
|
|
96
|
-
|
|
172
|
+
.panel-body::-webkit-scrollbar-thumb {
|
|
173
|
+
background: rgba(255, 255, 255, 0.12);
|
|
174
|
+
border-radius: 3px;
|
|
97
175
|
}
|
|
98
176
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
font-weight: 500;
|
|
102
|
-
color: #c0c0c0;
|
|
103
|
-
margin-bottom: 6px;
|
|
177
|
+
/* \u2500\u2500 Models \u2500\u2500 */
|
|
178
|
+
.category-tabs {
|
|
104
179
|
display: flex;
|
|
105
|
-
|
|
106
|
-
|
|
180
|
+
flex-wrap: wrap;
|
|
181
|
+
gap: 8px;
|
|
182
|
+
margin-bottom: 16px;
|
|
107
183
|
}
|
|
108
184
|
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
185
|
+
.category-tab {
|
|
186
|
+
display: inline-flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
padding: 6px 14px;
|
|
190
|
+
background: rgba(255, 255, 255, 0.1);
|
|
191
|
+
border: none;
|
|
192
|
+
border-radius: 16px;
|
|
193
|
+
color: rgba(255, 255, 255, 0.7);
|
|
194
|
+
font-size: 12px;
|
|
195
|
+
font-weight: 500;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
transition: all 0.15s;
|
|
198
|
+
white-space: nowrap;
|
|
112
199
|
}
|
|
113
200
|
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
color: #
|
|
117
|
-
margin-bottom: 8px;
|
|
118
|
-
line-height: 1.4;
|
|
201
|
+
.category-tab:hover {
|
|
202
|
+
background: rgba(255, 255, 255, 0.15);
|
|
203
|
+
color: #fff;
|
|
119
204
|
}
|
|
120
205
|
|
|
121
|
-
.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
margin: 12px 0;
|
|
206
|
+
.category-tab.active {
|
|
207
|
+
background: rgba(130, 70, 255, 0.3);
|
|
208
|
+
color: #fff;
|
|
125
209
|
}
|
|
126
210
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
gap: 2px;
|
|
211
|
+
.models-grid {
|
|
212
|
+
display: grid;
|
|
213
|
+
grid-template-columns: repeat(2, 1fr);
|
|
214
|
+
gap: 12px;
|
|
132
215
|
}
|
|
133
216
|
|
|
134
|
-
.model-
|
|
217
|
+
.model-card {
|
|
135
218
|
display: flex;
|
|
136
219
|
align-items: center;
|
|
137
220
|
gap: 8px;
|
|
138
|
-
padding:
|
|
221
|
+
padding: 10px 12px;
|
|
139
222
|
border-radius: 8px;
|
|
140
223
|
cursor: pointer;
|
|
224
|
+
background: #2a2a2a;
|
|
141
225
|
border: none;
|
|
142
|
-
|
|
143
|
-
color: #e0e0e0;
|
|
144
|
-
width: 100%;
|
|
145
|
-
font-size: 13px;
|
|
146
|
-
text-align: left;
|
|
226
|
+
color: #fff;
|
|
147
227
|
transition: background 0.15s;
|
|
228
|
+
overflow: hidden;
|
|
229
|
+
text-align: left;
|
|
148
230
|
}
|
|
149
231
|
|
|
150
|
-
.model-
|
|
151
|
-
background:
|
|
232
|
+
.model-card:hover {
|
|
233
|
+
background: rgba(130, 70, 255, 0.05);
|
|
152
234
|
}
|
|
153
235
|
|
|
154
|
-
.model-
|
|
155
|
-
background:
|
|
156
|
-
|
|
236
|
+
.model-card:active {
|
|
237
|
+
background: rgba(130, 70, 255, 0.2);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.model-card.selected {
|
|
241
|
+
background: rgba(130, 70, 255, 0.1);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.model-card.disabled {
|
|
245
|
+
opacity: 0.7;
|
|
246
|
+
cursor: not-allowed;
|
|
157
247
|
}
|
|
158
248
|
|
|
159
|
-
.
|
|
249
|
+
.status-dot {
|
|
160
250
|
width: 8px;
|
|
161
251
|
height: 8px;
|
|
162
252
|
border-radius: 50%;
|
|
163
|
-
background: #555;
|
|
164
253
|
flex-shrink: 0;
|
|
254
|
+
pointer-events: none;
|
|
165
255
|
}
|
|
166
256
|
|
|
167
|
-
.model-
|
|
168
|
-
|
|
257
|
+
.model-name {
|
|
258
|
+
flex: 1;
|
|
259
|
+
min-width: 0;
|
|
260
|
+
font-size: 13px;
|
|
261
|
+
font-weight: 500;
|
|
262
|
+
color: #fff;
|
|
263
|
+
white-space: nowrap;
|
|
264
|
+
overflow: hidden;
|
|
265
|
+
text-overflow: ellipsis;
|
|
266
|
+
pointer-events: none;
|
|
169
267
|
}
|
|
170
268
|
|
|
171
|
-
/*
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
padding:
|
|
269
|
+
/* Model detail */
|
|
270
|
+
.model-detail {
|
|
271
|
+
margin-top: 20px;
|
|
272
|
+
padding: 16px;
|
|
273
|
+
background: #2a2a2a;
|
|
274
|
+
border-radius: 8px;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.detail-header {
|
|
278
|
+
display: flex;
|
|
279
|
+
align-items: center;
|
|
280
|
+
justify-content: space-between;
|
|
281
|
+
margin-bottom: 12px;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.detail-title {
|
|
285
|
+
font-size: 14px;
|
|
286
|
+
font-weight: 600;
|
|
287
|
+
color: #fff;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.detail-status {
|
|
291
|
+
font-size: 12px;
|
|
292
|
+
font-weight: 500;
|
|
293
|
+
padding: 2px 8px;
|
|
294
|
+
border-radius: 6px;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.detail-status.excellent { background: rgba(16, 185, 129, 0.1); color: #10b981; }
|
|
298
|
+
.detail-status.good { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
|
|
299
|
+
.detail-status.normal { background: rgba(234, 179, 8, 0.1); color: #eab308; }
|
|
300
|
+
.detail-status.crowded { background: rgba(249, 115, 22, 0.1); color: #f97316; }
|
|
301
|
+
.detail-status.inactive { background: rgba(107, 114, 128, 0.1); color: #6b7280; }
|
|
302
|
+
|
|
303
|
+
.detail-credits {
|
|
304
|
+
display: flex;
|
|
305
|
+
align-items: center;
|
|
306
|
+
gap: 4px;
|
|
307
|
+
margin-bottom: 12px;
|
|
308
|
+
font-size: 13px;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.credits-label {
|
|
312
|
+
color: rgba(255, 255, 255, 0.7);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.credits-value {
|
|
316
|
+
font-weight: 600;
|
|
317
|
+
color: #fff;
|
|
318
|
+
margin-left: 4px;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.credits-icon {
|
|
322
|
+
width: 16px;
|
|
323
|
+
height: 16px;
|
|
324
|
+
margin-left: 2px;
|
|
325
|
+
display: inline-block;
|
|
326
|
+
vertical-align: middle;
|
|
175
327
|
}
|
|
176
328
|
|
|
329
|
+
.credits-unit {
|
|
330
|
+
font-size: 12px;
|
|
331
|
+
color: rgba(255, 255, 255, 0.7);
|
|
332
|
+
margin-left: 2px;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.detail-description {
|
|
336
|
+
font-size: 13px;
|
|
337
|
+
color: rgba(255, 255, 255, 0.7);
|
|
338
|
+
line-height: 1.5;
|
|
339
|
+
white-space: pre-wrap;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/* \u2500\u2500 Settings form \u2500\u2500 */
|
|
343
|
+
.form-stack {
|
|
344
|
+
display: flex;
|
|
345
|
+
flex-direction: column;
|
|
346
|
+
gap: 20px;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.form-group {
|
|
350
|
+
display: flex;
|
|
351
|
+
flex-direction: column;
|
|
352
|
+
gap: 12px;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.form-label {
|
|
356
|
+
font-size: 13px;
|
|
357
|
+
font-weight: 500;
|
|
358
|
+
color: #fff;
|
|
359
|
+
display: flex;
|
|
360
|
+
justify-content: space-between;
|
|
361
|
+
align-items: center;
|
|
362
|
+
margin: 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.temperature-value {
|
|
366
|
+
font-weight: 600;
|
|
367
|
+
color: #8246FF;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.form-hint {
|
|
371
|
+
font-size: 12px;
|
|
372
|
+
color: rgba(255, 255, 255, 0.7);
|
|
373
|
+
margin: -8px 0 0;
|
|
374
|
+
line-height: 1.5;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* Slider */
|
|
177
378
|
.slider {
|
|
178
379
|
-webkit-appearance: none;
|
|
179
380
|
appearance: none;
|
|
180
381
|
width: 100%;
|
|
181
|
-
height:
|
|
182
|
-
|
|
183
|
-
|
|
382
|
+
height: 8px;
|
|
383
|
+
background: rgba(255, 255, 255, 0.08);
|
|
384
|
+
border-radius: 8px;
|
|
184
385
|
outline: none;
|
|
386
|
+
cursor: pointer;
|
|
185
387
|
}
|
|
186
388
|
|
|
187
389
|
.slider::-webkit-slider-thumb {
|
|
188
390
|
-webkit-appearance: none;
|
|
189
391
|
appearance: none;
|
|
190
|
-
width:
|
|
191
|
-
height:
|
|
392
|
+
width: 24px;
|
|
393
|
+
height: 24px;
|
|
394
|
+
background: #8246FF;
|
|
192
395
|
border-radius: 50%;
|
|
193
|
-
background: #6366f1;
|
|
194
396
|
cursor: pointer;
|
|
195
|
-
border:
|
|
196
|
-
|
|
397
|
+
border: none;
|
|
398
|
+
transition: transform 0.15s, box-shadow 0.15s;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.slider::-webkit-slider-thumb:hover {
|
|
402
|
+
transform: scale(1.1);
|
|
403
|
+
box-shadow: 0 0 0 4px rgba(130, 70, 255, 0.2);
|
|
197
404
|
}
|
|
198
405
|
|
|
199
406
|
.slider::-moz-range-thumb {
|
|
200
|
-
width:
|
|
201
|
-
height:
|
|
407
|
+
width: 24px;
|
|
408
|
+
height: 24px;
|
|
409
|
+
background: #8246FF;
|
|
202
410
|
border-radius: 50%;
|
|
203
|
-
|
|
411
|
+
border: none;
|
|
204
412
|
cursor: pointer;
|
|
205
|
-
border: 2px solid #1e1e1e;
|
|
206
|
-
box-shadow: 0 2px 4px rgba(0,0,0,0.3);
|
|
207
413
|
}
|
|
208
414
|
|
|
209
415
|
.slider-labels {
|
|
210
416
|
display: flex;
|
|
211
417
|
justify-content: space-between;
|
|
212
|
-
font-size:
|
|
213
|
-
color:
|
|
418
|
+
font-size: 12px;
|
|
419
|
+
color: rgba(255, 255, 255, 0.6);
|
|
214
420
|
margin-top: 4px;
|
|
215
421
|
}
|
|
216
422
|
|
|
217
|
-
/* Segment
|
|
218
|
-
.segment {
|
|
423
|
+
/* Segment-control (\u56DE\u590D\u957F\u5EA6) */
|
|
424
|
+
.segment-control {
|
|
219
425
|
display: flex;
|
|
220
426
|
background: #2a2a2a;
|
|
221
|
-
border-radius:
|
|
427
|
+
border-radius: 12px;
|
|
222
428
|
padding: 3px;
|
|
223
429
|
gap: 2px;
|
|
224
430
|
}
|
|
225
431
|
|
|
226
|
-
.segment-
|
|
432
|
+
.segment-button {
|
|
227
433
|
flex: 1;
|
|
228
|
-
padding: 8px
|
|
434
|
+
padding: 8px 16px;
|
|
435
|
+
background: transparent;
|
|
229
436
|
border: none;
|
|
230
437
|
border-radius: 8px;
|
|
231
|
-
background: transparent;
|
|
232
|
-
color: #999;
|
|
233
438
|
font-size: 13px;
|
|
439
|
+
color: rgba(255, 255, 255, 0.7);
|
|
234
440
|
cursor: pointer;
|
|
235
|
-
transition: all 0.
|
|
441
|
+
transition: all 0.15s;
|
|
236
442
|
}
|
|
237
443
|
|
|
238
|
-
.segment-
|
|
239
|
-
background: #6366f1;
|
|
444
|
+
.segment-button:hover {
|
|
240
445
|
color: #fff;
|
|
241
|
-
font-weight: 500;
|
|
242
446
|
}
|
|
243
447
|
|
|
244
|
-
.segment-
|
|
245
|
-
|
|
448
|
+
.segment-button.active {
|
|
449
|
+
background: #8246FF;
|
|
450
|
+
color: #fff;
|
|
451
|
+
font-weight: 500;
|
|
246
452
|
}
|
|
247
453
|
|
|
248
|
-
/* Select */
|
|
249
|
-
.select
|
|
454
|
+
/* Custom Select */
|
|
455
|
+
.custom-select {
|
|
250
456
|
position: relative;
|
|
251
457
|
}
|
|
252
458
|
|
|
253
|
-
.select {
|
|
459
|
+
.select-trigger {
|
|
254
460
|
width: 100%;
|
|
255
|
-
padding:
|
|
256
|
-
border-radius: 10px;
|
|
257
|
-
border: 1px solid #333;
|
|
461
|
+
padding: 12px 16px;
|
|
258
462
|
background: #2a2a2a;
|
|
259
|
-
|
|
463
|
+
border: none;
|
|
464
|
+
border-radius: 8px;
|
|
260
465
|
font-size: 13px;
|
|
261
|
-
|
|
262
|
-
-webkit-appearance: none;
|
|
466
|
+
color: #fff;
|
|
263
467
|
cursor: pointer;
|
|
264
|
-
|
|
265
|
-
|
|
468
|
+
display: flex;
|
|
469
|
+
justify-content: space-between;
|
|
470
|
+
align-items: center;
|
|
471
|
+
text-align: left;
|
|
266
472
|
}
|
|
267
473
|
|
|
268
|
-
.select
|
|
269
|
-
|
|
474
|
+
.select-arrow {
|
|
475
|
+
color: rgba(255, 255, 255, 0.6);
|
|
476
|
+
font-size: 11px;
|
|
477
|
+
margin-left: 8px;
|
|
270
478
|
}
|
|
271
479
|
|
|
272
|
-
.select-
|
|
480
|
+
.select-dropdown {
|
|
273
481
|
position: absolute;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
482
|
+
top: calc(100% + 4px);
|
|
483
|
+
left: 0;
|
|
484
|
+
right: 0;
|
|
485
|
+
background: #2a2a2a;
|
|
486
|
+
border-radius: 8px;
|
|
487
|
+
overflow: hidden;
|
|
488
|
+
z-index: 10;
|
|
489
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
|
490
|
+
display: none;
|
|
280
491
|
}
|
|
281
492
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
position: relative;
|
|
493
|
+
.select-dropdown.open {
|
|
494
|
+
display: block;
|
|
285
495
|
}
|
|
286
496
|
|
|
287
|
-
.
|
|
497
|
+
.select-option {
|
|
288
498
|
width: 100%;
|
|
289
|
-
padding:
|
|
290
|
-
|
|
291
|
-
border:
|
|
292
|
-
background: #2a2a2a;
|
|
293
|
-
color: #e0e0e0;
|
|
499
|
+
padding: 12px 16px;
|
|
500
|
+
background: transparent;
|
|
501
|
+
border: none;
|
|
294
502
|
font-size: 13px;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
.note-input::placeholder {
|
|
304
|
-
color: #555;
|
|
503
|
+
color: #fff;
|
|
504
|
+
cursor: pointer;
|
|
505
|
+
display: flex;
|
|
506
|
+
justify-content: space-between;
|
|
507
|
+
align-items: center;
|
|
508
|
+
text-align: left;
|
|
509
|
+
transition: background 0.15s;
|
|
305
510
|
}
|
|
306
511
|
|
|
307
|
-
.
|
|
308
|
-
|
|
512
|
+
.select-option:hover {
|
|
513
|
+
background: rgba(255, 255, 255, 0.05);
|
|
309
514
|
}
|
|
310
515
|
|
|
311
|
-
.
|
|
312
|
-
|
|
313
|
-
font-size: 11px;
|
|
314
|
-
color: #555;
|
|
315
|
-
margin-top: 4px;
|
|
516
|
+
.select-option.active {
|
|
517
|
+
color: #8246FF;
|
|
316
518
|
}
|
|
317
519
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
color: #666;
|
|
322
|
-
margin-bottom: 8px;
|
|
323
|
-
line-height: 1.4;
|
|
520
|
+
.select-option .check {
|
|
521
|
+
width: 16px;
|
|
522
|
+
height: 16px;
|
|
324
523
|
}
|
|
325
524
|
|
|
326
|
-
|
|
525
|
+
/* Note input */
|
|
526
|
+
.player-note-input {
|
|
327
527
|
width: 100%;
|
|
328
|
-
padding:
|
|
329
|
-
|
|
330
|
-
border:
|
|
331
|
-
|
|
332
|
-
color: #
|
|
528
|
+
padding: 12px;
|
|
529
|
+
background: rgba(255, 255, 255, 0.08);
|
|
530
|
+
border: none;
|
|
531
|
+
border-radius: 8px;
|
|
532
|
+
color: #fff;
|
|
333
533
|
font-size: 13px;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
transition: background 0.15s;
|
|
534
|
+
line-height: 1.5;
|
|
535
|
+
resize: none;
|
|
536
|
+
box-sizing: border-box;
|
|
537
|
+
font-family: inherit;
|
|
538
|
+
outline: none;
|
|
340
539
|
}
|
|
341
540
|
|
|
342
|
-
.
|
|
343
|
-
|
|
541
|
+
.player-note-input::placeholder {
|
|
542
|
+
color: rgba(255, 255, 255, 0.4);
|
|
344
543
|
}
|
|
345
544
|
|
|
346
|
-
.
|
|
347
|
-
|
|
348
|
-
|
|
545
|
+
.char-count {
|
|
546
|
+
font-size: 12px;
|
|
547
|
+
font-weight: normal;
|
|
548
|
+
color: rgba(255, 255, 255, 0.6);
|
|
349
549
|
}
|
|
350
550
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
551
|
+
/* Sync hint */
|
|
552
|
+
.sync-hint {
|
|
553
|
+
font-size: 12px;
|
|
554
|
+
color: #f59e0b;
|
|
555
|
+
margin: -8px 0 0;
|
|
556
|
+
line-height: 1.4;
|
|
557
|
+
display: none;
|
|
354
558
|
}
|
|
355
559
|
|
|
356
|
-
.sync-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
/* Save button */
|
|
360
|
-
.save-row {
|
|
361
|
-
display: flex;
|
|
362
|
-
justify-content: flex-end;
|
|
363
|
-
margin-top: 16px;
|
|
560
|
+
.sync-hint.visible {
|
|
561
|
+
display: block;
|
|
364
562
|
}
|
|
365
563
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
564
|
+
/* Buttons */
|
|
565
|
+
.btn {
|
|
566
|
+
padding: 8px 16px;
|
|
567
|
+
border-radius: 8px;
|
|
369
568
|
border: none;
|
|
370
|
-
background: #6366f1;
|
|
371
|
-
color: #fff;
|
|
372
569
|
font-size: 13px;
|
|
373
570
|
font-weight: 500;
|
|
374
571
|
cursor: pointer;
|
|
375
|
-
transition:
|
|
572
|
+
transition: all 0.15s;
|
|
573
|
+
display: flex;
|
|
574
|
+
align-items: center;
|
|
575
|
+
gap: 8px;
|
|
576
|
+
justify-content: center;
|
|
376
577
|
}
|
|
377
578
|
|
|
378
|
-
.
|
|
379
|
-
|
|
579
|
+
.btn:disabled {
|
|
580
|
+
opacity: 0.5;
|
|
581
|
+
cursor: not-allowed;
|
|
380
582
|
}
|
|
381
583
|
|
|
382
|
-
.
|
|
383
|
-
|
|
384
|
-
|
|
584
|
+
.btn-sync {
|
|
585
|
+
width: 100%;
|
|
586
|
+
background: rgba(255, 255, 255, 0.08);
|
|
587
|
+
color: #fff;
|
|
385
588
|
}
|
|
386
589
|
|
|
387
|
-
.
|
|
388
|
-
background:
|
|
590
|
+
.btn-sync:hover:not(:disabled) {
|
|
591
|
+
background: rgba(255, 255, 255, 0.12);
|
|
389
592
|
}
|
|
390
593
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
top: 2px;
|
|
395
|
-
right: 2px;
|
|
396
|
-
width: 10px;
|
|
397
|
-
height: 10px;
|
|
398
|
-
border-radius: 50%;
|
|
399
|
-
background: #f87171;
|
|
400
|
-
border: 2px solid #1e1e1e;
|
|
401
|
-
display: none;
|
|
594
|
+
.btn-sync svg {
|
|
595
|
+
width: 16px;
|
|
596
|
+
height: 16px;
|
|
402
597
|
}
|
|
403
598
|
|
|
404
|
-
.
|
|
405
|
-
|
|
599
|
+
.btn-sync.success { color: #4ade80; }
|
|
600
|
+
.btn-sync.error { color: #f87171; }
|
|
601
|
+
|
|
602
|
+
/* Footer */
|
|
603
|
+
.panel-footer {
|
|
604
|
+
flex-shrink: 0;
|
|
605
|
+
padding: 16px;
|
|
606
|
+
display: flex;
|
|
607
|
+
justify-content: flex-end;
|
|
406
608
|
}
|
|
407
609
|
|
|
408
|
-
.
|
|
409
|
-
|
|
410
|
-
|
|
610
|
+
.btn-save {
|
|
611
|
+
background: #8246FF;
|
|
612
|
+
color: #fff;
|
|
613
|
+
padding: 8px 24px;
|
|
411
614
|
}
|
|
412
615
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
font-size: 11px;
|
|
416
|
-
color: #f59e0b;
|
|
417
|
-
margin-bottom: 6px;
|
|
418
|
-
line-height: 1.4;
|
|
419
|
-
display: none;
|
|
616
|
+
.btn-save:hover:not(:disabled) {
|
|
617
|
+
opacity: 0.9;
|
|
420
618
|
}
|
|
421
619
|
|
|
422
|
-
.
|
|
423
|
-
display: block;
|
|
620
|
+
.spinner {
|
|
621
|
+
display: inline-block;
|
|
622
|
+
width: 14px;
|
|
623
|
+
height: 14px;
|
|
624
|
+
border: 2px solid rgba(255, 255, 255, 0.35);
|
|
625
|
+
border-top-color: #fff;
|
|
626
|
+
border-radius: 50%;
|
|
627
|
+
animation: spin 0.6s linear infinite;
|
|
424
628
|
}
|
|
425
629
|
|
|
426
630
|
@keyframes spin {
|
|
427
631
|
to { transform: rotate(360deg); }
|
|
428
632
|
}
|
|
429
633
|
.spin { animation: spin 0.8s linear infinite; }
|
|
430
|
-
`,V='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>',z='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>',W='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="spin"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',Z='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',K='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',u=class{constructor(e){this.selectedModelId="";this.models=[];this.modelPanel=null;this.settings={temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""};this.hasWorldUpdate=!1;this.fabDot=null;this.syncHint=null;this.displayMode="phone";this.displayModeBtns=[];this.tempValueEl=null;this.tempSlider=null;this.segmentBtns=[];this.langSelect=null;this.noteInput=null;this.noteCounter=null;this.saveBtn=null;this.syncBtn=null;this.syncState="idle";this.panel=null;this.callbacks=e,this.host=document.createElement("div"),this.host.id="storvia-settings",this.shadowRoot=this.host.attachShadow({mode:"closed"})}mount(e,t,n,i=!1){this.models=e,this.selectedModelId=t,this.settings={...n},this.hasWorldUpdate=i;try{let s=localStorage.getItem("storvia_display_mode");(s==="phone"||s==="desktop")&&(this.displayMode=s)}catch{}document.body.appendChild(this.host),this.render()}unmount(){this.host.remove()}getSelectedModelId(){return this.selectedModelId}getSettings(){return{...this.settings}}render(){let e=document.createElement("style");e.textContent=j;let t=document.createElement("div"),n=document.createElement("div");n.className="fab-wrap";let i=document.createElement("button");i.className="fab",i.innerHTML=V,i.title="\u6E38\u620F\u8BBE\u7F6E";let s=document.createElement("div");s.className=`fab-dot${this.hasWorldUpdate?" visible":""}`,this.fabDot=s,n.appendChild(i),n.appendChild(s);let r=document.createElement("div");r.className="panel",this.panel=r;let o=document.createElement("div");o.className="panel-header";let c=document.createElement("div");c.className="panel-title",c.textContent="\u6E38\u620F\u8BBE\u7F6E";let p=document.createElement("button");p.className="close-btn",p.innerHTML="\u2715",p.addEventListener("click",()=>r.classList.remove("open")),o.appendChild(c),o.appendChild(p),r.appendChild(o);let d=document.createElement("div");d.className="panel-body",this.models.length>0&&(d.appendChild(this.buildModelSection()),d.appendChild(this.makeDivider())),d.appendChild(this.buildTemperatureSection()),d.appendChild(this.makeDivider()),d.appendChild(this.buildReplyLengthSection()),d.appendChild(this.makeDivider()),d.appendChild(this.buildReplyLanguageSection()),d.appendChild(this.makeDivider()),d.appendChild(this.buildNoteSection()),d.appendChild(this.makeDivider()),d.appendChild(this.buildDisplayModeSection()),d.appendChild(this.makeDivider()),d.appendChild(this.buildSyncSection());let m=document.createElement("div");m.className="save-row";let h=document.createElement("button");h.className="save-btn",h.textContent="\u4FDD\u5B58",this.saveBtn=h,h.addEventListener("click",()=>this.handleSave()),m.appendChild(h),d.appendChild(m),r.appendChild(d),i.addEventListener("click",()=>r.classList.toggle("open")),document.addEventListener("click",I=>{this.host.contains(I.target)||r.classList.remove("open")}),t.appendChild(r),t.appendChild(n),this.shadowRoot.appendChild(e),this.shadowRoot.appendChild(t)}buildModelSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label",t.textContent="AI \u6A21\u578B",e.appendChild(t);let n=document.createElement("div");return n.className="model-list",this.modelPanel=n,this.models.forEach(i=>{let s=document.createElement("button");s.className=`model-option${i.id===this.selectedModelId?" active":""}`,s.innerHTML=`<span class="dot"></span><span>${i.name}</span>`,s.addEventListener("click",()=>{this.selectedModelId=i.id,this.callbacks.onModelChange(i.id);try{localStorage.setItem("storvia_model_id",i.id)}catch{}this.updateModelActive()}),n.appendChild(s)}),e.appendChild(n),e}buildTemperatureSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label";let n=document.createElement("span");n.textContent="\u6E29\u5EA6";let i=document.createElement("span");i.className="value",i.textContent=this.settings.temperature.toFixed(1),this.tempValueEl=i,t.appendChild(n),t.appendChild(i),e.appendChild(t);let s=document.createElement("div");s.className="section-desc",s.textContent="\u66F4\u4F4E\u7684\u6E29\u5EA6\u4F1A\u8BA9 AI \u56DE\u590D\u66F4\u7A33\u5B9A\u3001\u7406\u667A\uFF1B\u66F4\u9AD8\u7684\u6E29\u5EA6\u4F1A\u8BA9 AI \u7684\u56DE\u590D\u66F4\u5177\u591A\u6837\u6027\u548C\u968F\u673A\u6027",e.appendChild(s);let r=document.createElement("div");r.className="slider-wrap";let o=document.createElement("input");o.type="range",o.className="slider",o.min="0",o.max="2",o.step="0.1",o.value=String(this.settings.temperature),this.tempSlider=o,o.addEventListener("input",()=>{let p=parseFloat(o.value);this.settings.temperature=p,this.tempValueEl&&(this.tempValueEl.textContent=p.toFixed(1))}),r.appendChild(o);let c=document.createElement("div");return c.className="slider-labels",c.innerHTML="<span>\u7CBE\u786E</span><span>\u521B\u610F</span>",r.appendChild(c),e.appendChild(r),e}buildReplyLengthSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label",t.textContent="\u56DE\u590D\u957F\u5EA6",e.appendChild(t);let n=document.createElement("div");return n.className="segment",this.segmentBtns=[],M.forEach(i=>{let s=document.createElement("button");s.className=`segment-btn${i.value===this.settings.reply_length?" active":""}`,s.textContent=i.label,s.addEventListener("click",()=>{this.settings.reply_length=i.value,this.segmentBtns.forEach((r,o)=>{r.classList.toggle("active",M[o].value===i.value)})}),this.segmentBtns.push(s),n.appendChild(s)}),e.appendChild(n),e}buildReplyLanguageSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label",t.textContent="\u56DE\u590D\u8BED\u8A00",e.appendChild(t);let n=document.createElement("div");n.className="select-wrap";let i=document.createElement("select");i.className="select",this.langSelect=i,F.forEach(r=>{let o=document.createElement("option");o.value=r.value,o.textContent=r.label,r.value===this.settings.reply_language&&(o.selected=!0),i.appendChild(o)}),i.addEventListener("change",()=>{this.settings.reply_language=i.value});let s=document.createElement("span");return s.className="select-arrow",s.textContent="\u25BE",n.appendChild(i),n.appendChild(s),e.appendChild(n),e}buildNoteSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label";let n=document.createElement("span");n.textContent="\u5907\u6CE8";let i=document.createElement("span");i.textContent=`${this.settings.player_note.length}/50`,this.noteCounter=i,t.appendChild(n),t.appendChild(i),e.appendChild(t);let s=document.createElement("div");s.className="section-desc",s.textContent="\u5199\u4E0B\u4F60\u5BF9\u8FD9\u4E2A\u6E38\u620F\u7684\u5907\u6CE8\uFF0C\u4F1A\u663E\u793A\u5728\u5B58\u6863\u5217\u8868",e.appendChild(s);let r=document.createElement("div");r.className="note-wrap";let o=document.createElement("textarea");return o.className="note-input",o.placeholder="\u5907\u6CE8",o.maxLength=50,o.value=this.settings.player_note,this.noteInput=o,o.addEventListener("input",()=>{this.settings.player_note=o.value,this.noteCounter&&(this.noteCounter.textContent=`${o.value.length}/50`)}),r.appendChild(o),e.appendChild(r),e}buildDisplayModeSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label",t.textContent="\u663E\u793A\u6A21\u5F0F",e.appendChild(t);let n=document.createElement("div");n.className="section-desc",n.textContent="\u7535\u8111\u6A21\u5F0F\u4F1A\u81EA\u52A8\u6A2A\u5C4F\u663E\u793A",e.appendChild(n);let i=document.createElement("div");i.className="segment",this.displayModeBtns=[];let s=[{value:"phone",label:"\u624B\u673A"},{value:"desktop",label:"\u7535\u8111"}];return s.forEach(r=>{let o=document.createElement("button");o.className=`segment-btn${r.value===this.displayMode?" active":""}`,o.textContent=r.label,o.addEventListener("click",()=>{this.displayMode=r.value;try{localStorage.setItem("storvia_display_mode",r.value)}catch{}this.displayModeBtns.forEach((c,p)=>{c.classList.toggle("active",s[p].value===r.value)});try{window.parent.postMessage({type:"storvia-orientation",mode:r.value==="desktop"?"landscape":"portrait"},"*")}catch{}}),this.displayModeBtns.push(o),i.appendChild(o)}),e.appendChild(i),e}buildSyncSection(){let e=document.createElement("div");e.className="section";let t=document.createElement("div");t.className="section-label",t.textContent="\u540C\u6B65\u6E38\u620F\u8BBE\u5B9A",e.appendChild(t);let n=document.createElement("div");n.className=`sync-hint${this.hasWorldUpdate?" visible":""}`,n.textContent="\u26A0 \u4F5C\u8005\u5DF2\u66F4\u65B0\u6E38\u620F\u5185\u5BB9\uFF0C\u5EFA\u8BAE\u70B9\u51FB\u540C\u6B65",this.syncHint=n,e.appendChild(n);let i=document.createElement("div");i.className="sync-desc",i.textContent="\u5982\u679C\u6E38\u620F\u4F5C\u8005\u66F4\u65B0\u4E86\u5185\u5BB9\uFF0C\u70B9\u51FB\u6B64\u6309\u94AE\u53EF\u5C06\u6700\u65B0\u7684\u6E38\u620F\u8BBE\u5B9A\u548C\u5F00\u5E55\u5C0F\u5267\u573A\u540C\u6B65\u5230\u5F53\u524D\u5BF9\u8BDD",e.appendChild(i);let s=document.createElement("button");return s.className="sync-btn",this.syncBtn=s,this.renderSyncBtn(),s.addEventListener("click",async()=>{if(this.syncState!=="loading"){this.setSyncState("loading");try{await this.callbacks.onSync(),this.setSyncState("success"),this.hasWorldUpdate=!1,this.fabDot&&this.fabDot.classList.remove("visible"),this.syncHint&&this.syncHint.classList.remove("visible"),setTimeout(()=>this.setSyncState("idle"),3e3)}catch{this.setSyncState("error"),setTimeout(()=>this.setSyncState("idle"),4e3)}}}),e.appendChild(s),e}makeDivider(){let e=document.createElement("div");return e.className="divider",e}updateModelActive(){this.modelPanel&&this.modelPanel.querySelectorAll(".model-option").forEach((e,t)=>{e.classList.toggle("active",this.models[t].id===this.selectedModelId)})}setSyncState(e){this.syncState=e,this.renderSyncBtn()}renderSyncBtn(){if(!this.syncBtn)return;let e=this.syncState,t={idle:z,loading:W,success:Z,error:K},n={idle:"\u540C\u6B65\u6700\u65B0\u8BBE\u5B9A",loading:"\u540C\u6B65\u4E2D...",success:"\u5DF2\u540C\u6B65",error:"\u540C\u6B65\u5931\u8D25"};this.syncBtn.className=`sync-btn${e==="success"||e==="error"?` ${e}`:""}`,this.syncBtn.disabled=e==="loading",this.syncBtn.innerHTML=`${t[e]}<span>${n[e]}</span>`}async handleSave(){if(!(!this.saveBtn||this.saveBtn.disabled)){this.saveBtn.disabled=!0,this.saveBtn.textContent="\u4FDD\u5B58\u4E2D...";try{await this.callbacks.onSettingsChange({temperature:this.settings.temperature,reply_length:this.settings.reply_length,reply_language:this.settings.reply_language,player_note:this.settings.player_note}),this.saveBtn.textContent="\u5DF2\u4FDD\u5B58",this.saveBtn.classList.add("saved"),setTimeout(()=>{this.saveBtn&&(this.saveBtn.textContent="\u4FDD\u5B58",this.saveBtn.classList.remove("saved"),this.saveBtn.disabled=!1)},2e3)}catch{this.saveBtn.textContent="\u4FDD\u5B58\u5931\u8D25",setTimeout(()=>{this.saveBtn&&(this.saveBtn.textContent="\u4FDD\u5B58",this.saveBtn.disabled=!1)},2e3)}}}};var v=class{constructor(e,t,n,i,s=!1,r){this.http=e;this.getGameId=t;this.getConversationId=n;this.getModelId=i;this.isPreview=s;this.previewConfig=r}updatePreviewConfig(e){this.previewConfig=e}async send(e){if(this.isPreview)return this.sendPreview(e);let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),message:e.message,topic:e.topic,scene_context:e.context,stream:e.stream??!1};if(e.stream){await this.http.stream("/chat",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/chat",t)}async save(e){return this.isPreview?{id:`preview-${Date.now()}`}:this.http.post("/messages/save",{conversation_id:this.getConversationId(),role:e.role,content:e.content,topic:e.topic})}async generate(e){if(this.isPreview)return this.sendPreview({message:"",topic:e.topic,context:(e.context||"")+`
|
|
431
|
-
[\u6307\u4EE4] \u8BF7\u76F4\u63A5\u751F\u6210\u56DE\u590D\uFF0C\u65E0\u9700\u7528\u6237\u8F93\u5165`,stream:e.stream,onChunk:e.onChunk,onDone:e.onDone});let t={conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_context:e.context,stream:e.stream??!1,save:e.save??!0};if(e.stream){await this.http.stream("/generate",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/generate",t)}async retry(e={}){if(this.isPreview)throw new Error("Retry is not supported in preview mode");let t={conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_context:e.context,stream:e.stream??!1};if(e.stream){await this.http.stream("/retry",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/retry",t)}async sendPreview(e){let t={model_id:this.getModelId(),message:e.message,topic:e.topic,context:e.context,prompt_config:this.previewConfig||{},history_messages:[]};if(e.stream){await this.http.stream("/preview",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}let n="";return await this.http.stream("/preview",t,i=>{n+=i},()=>{}),{id:"",content:n}}};var k=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){return this.isPreview?{...this.mem[e]||{}}:this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`)}async update(e,t){if(this.isPreview){this.mem[e]={...this.mem[e]||{},...t};return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,t)}},f=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];this.state=new k(e,t,n)}async list(){return this.isPreview?this.mem.map(e=>({name:e.name,avatar:e.avatar,...e.gender?{gender:e.gender}:{}})):this.http.get(`/conversations/${this.getConversationId()}/characters`)}async get(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:t?.name||e,avatar:t?.avatar,...t?.gender?{gender:t.gender}:{}}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async add(e){if(this.isPreview){this.mem.push(e);return}await this.http.post(`/conversations/${this.getConversationId()}/characters`,e)}async update(e,t){if(this.isPreview){let n=this.mem.find(i=>i.name===e);n&&Object.assign(n,t);return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`,t)}async remove(e){if(this.isPreview){this.mem=this.mem.filter(t=>t.name!==e);return}await this.http.delete(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async detail(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:e,avatar:t?.avatar,state:await this.state.get(e)}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/detail`)}async setPriority(e,t){let n=Math.max(0,Math.min(100,Math.round(t)));this.isPreview||await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{priority:n})}};var y=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[]}async list(){return this.isPreview?[...this.mem]:this.http.get(`/conversations/${this.getConversationId()}/relationships`)}async get(e,t){if(this.isPreview){let n=this.mem.find(i=>i.from===e&&i.to===t);if(n)return{...n};throw new Error("Relationship not found")}return this.http.get(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async add(e){if(this.isPreview){this.mem.push({...e});return}await this.http.post(`/conversations/${this.getConversationId()}/relationships`,e)}async update(e,t,n){if(this.isPreview){let i=this.mem.find(s=>s.from===e&&s.to===t);i?Object.assign(i,n):this.mem.push({from:e,to:t,...n});return}await this.http.patch(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,n)}async remove(e,t){if(this.isPreview){this.mem=this.mem.filter(n=>!(n.from===e&&n.to===t));return}await this.http.delete(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}};var w=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async list(e){if(this.isPreview){if(e!==void 0)return{...this.mem[e]||{}};let t={};for(let[n,i]of Object.entries(this.mem))t[n]={...i};return t}return e!==void 0?this.http.get(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(e)}`):this.http.get(`/conversations/${this.getConversationId()}/inventory`)}async add(e){let{group:t,name:n,count:i=1,desc:s,iconUrl:r}=e;if(this.isPreview){if(!this.mem[t])throw new Error(`Group "${t}" does not exist`);if(n in this.mem[t])throw new Error(`Item "${n}" already exists in group "${t}"`);let o={count:i};s!==void 0&&(o.desc=s),r!==void 0&&(o.iconUrl=r),this.mem[t][n]=o;return}await this.http.post(`/conversations/${this.getConversationId()}/inventory`,{group:t,name:n,count:i,desc:s,iconUrl:r})}async update(e){let{group:t,name:n,...i}=e;if(this.isPreview){let s=this.mem[t];if(!s||!(n in s))throw new Error(`Item "${t}/${n}" not found`);Object.assign(s[n],i);return}await this.http.patch(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,i)}async remove(e){let{group:t,name:n}=e;if(this.isPreview){this.mem[t]&&delete this.mem[t][n];return}await this.http.delete(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`)}async move(e){let{fromGroup:t,toGroup:n,name:i,newName:s}=e;if(this.isPreview){let r=this.mem[t];if(!r||!(i in r))throw new Error(`Source item "${t}/${i}" not found`);if(!this.mem[n])throw new Error(`Target group "${n}" does not exist`);let o=s||i;if(t===n&&o===i)return;if(o in this.mem[n])throw new Error(`Item "${o}" already exists in target group`);this.mem[n][o]=r[i],delete r[i];return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/move`,{fromGroup:t,toGroup:n,name:i,newName:s})}async ensureGroup(e){if(this.isPreview){this.mem[e]||(this.mem[e]={});return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}`,{})}async removeGroup(e,t){let n=t?.cascade??!1;if(this.isPreview){let s=this.mem[e];if(s&&Object.keys(s).length>0&&!n)throw new Error(`Group "${e}" is not empty, pass cascade: true to force delete`);delete this.mem[e];return}let i=n?"?cascade=true":"";await this.http.delete(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}${i}`)}};var b=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(){return this.isPreview?{...this.mem}:this.http.get(`/conversations/${this.getConversationId()}/world`)}async update(e){if(this.isPreview){Object.assign(this.mem,e);return}await this.http.patch(`/conversations/${this.getConversationId()}/world`,e)}};var T=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){if(this.isPreview)return e?{...this.mem[e]||{}}:{...this.mem};let t=e?{group:e}:void 0;return this.http.get(`/conversations/${this.getConversationId()}/player/state`,t)}async update(e,t){if(this.isPreview){this.mem[e]={...this.mem[e]||{},...t};return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,values:t})}},C=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.memPersona={name:""};this.state=new T(e,t,n)}async get(){return this.isPreview?{...this.memPersona}:this.http.get(`/conversations/${this.getConversationId()}/player`)}async update(e){if(this.isPreview){Object.assign(this.memPersona,e);return}await this.http.patch(`/conversations/${this.getConversationId()}/player`,e)}};var x=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){if(this.isPreview)return e!==void 0?this.mem[e]:{...this.mem};let t=await this.http.get(`/conversations/${this.getConversationId()}/custom`);return e!==void 0?t[e]:t}async set(e){if(this.isPreview){for(let[t,n]of Object.entries(e))typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof this.mem[t]=="object"&&this.mem[t]!==null?this.mem[t]={...this.mem[t],...n}:this.mem[t]=n;return}await this.http.patch(`/conversations/${this.getConversationId()}/custom`,e)}async delete(e){if(this.isPreview){delete this.mem[e];return}await this.http.delete(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}`)}async setGroupField(e,t,n){if(this.isPreview){(!this.mem[e]||typeof this.mem[e]!="object")&&(this.mem[e]={}),this.mem[e][t]=n;return}await this.http.patch(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{value:n})}async deleteGroupField(e,t){if(this.isPreview){if(typeof this.mem[e]=="object"&&this.mem[e]!==null){let n=this.mem[e];delete n[t]}return}await this.http.delete(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}};var O="/functions/v1/world-engine/v1",J="https://api.storvia.ai";function Y(){return window.__STORVIA__||{}}function q(a=5e3){let e=Y();return e.apiBase?Promise.resolve(e):new Promise((t,n)=>{let i=setTimeout(()=>{window.removeEventListener("message",s),n(new l("NOT_INITIALIZED","Timed out waiting for __STORVIA__ config from parent frame."))},a);function s(r){let o=null;if(r.data?.type==="storvia-init"&&r.data.apiBase?o={apiBase:r.data.apiBase,gameId:r.data.gameId,accessToken:r.data.accessToken}:r.data?.type==="storvia-preview-init"&&r.data.config&&(o=r.data.config),o&&o.apiBase){clearTimeout(i),window.removeEventListener("message",s);let c=window;c.__STORVIA__=o,t(o)}}window.addEventListener("message",s)})}var S=class{constructor(){this.baseUrl="";this.gameId="";this.conversationId="";this.modelId="";this.accessToken="";this.initialized=!1;this.isPreview=!1;this.previewConfig=void 0}async init(){if(this.initialized)return;let e=await q(),t=e.apiBase;if(!t)throw new l("NOT_INITIALIZED","window.__STORVIA__.apiBase is not set. The platform must inject it before SDK init.");if(this.baseUrl=`${t}${O}`,this.isPreview=!!e.preview,this.previewConfig=e.previewConfig,!e.gameId)throw new l("GAME_NOT_FOUND","window.__STORVIA__.gameId is not set. The platform must inject it before SDK init.");if(this.gameId=e.gameId,!e.accessToken)throw new l("UNAUTHORIZED","window.__STORVIA__.accessToken is not set. The platform must inject the user token before SDK init.");if(this.accessToken=e.accessToken,this.http=new E(this.baseUrl,this.accessToken,!!e.debug),this.isPreview){this.conversationId="00000000-0000-0000-0000-000000000000";let d=await this.fetchModels();this.modelId=e.selectedModelId||d[0]?.id||"",this.settingsSheet=new u({onModelChange:R=>{this.modelId=R},onSettingsChange:()=>Promise.resolve(),onSync:()=>Promise.resolve()}),d.length>0&&this.settingsSheet.mount(d,this.modelId,{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""},!1);let m=()=>this.gameId,h=()=>this.conversationId,I=()=>this.modelId;this.chat=new v(this.http,m,h,I,!0,this.previewConfig),this.characters=new f(this.http,h,!0),this.relationships=new y(this.http,h,!0),this.inventory=new w(this.http,h,!0),this.world=new b(this.http,h,!0),this.player=new C(this.http,h,!0),this.custom=new x(this.http,h,!0),this.initialized=!0,this.listenForPreviewMessages();return}let[n,i]=await Promise.all([this.authenticate(),this.fetchModels()]);this.conversationId=n.conversationId;let s=this.getSavedModelId();this.modelId=s&&i.some(d=>d.id===s)?s:i[0]?.id||"";let r=n.settings||{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""};this.settingsSheet=new u({onModelChange:d=>{this.modelId=d},onSettingsChange:d=>this.saveSettings(d),onSync:()=>this.syncSettings()}),this.settingsSheet.mount(i,this.modelId,r,n.hasWorldUpdate??!1);let o=()=>this.gameId,c=()=>this.conversationId,p=()=>this.modelId;this.chat=new v(this.http,o,c,p),this.characters=new f(this.http,c),this.relationships=new y(this.http,c),this.inventory=new w(this.http,c),this.world=new b(this.http,c),this.player=new C(this.http,c),this.custom=new x(this.http,c),this.initialized=!0}listenForPreviewMessages(){window.addEventListener("message",e=>{!e.data||e.data.type!=="storvia-preview"||(e.data.action==="set-model"&&(this.modelId=e.data.modelId||""),e.data.action==="update-config"&&(this.previewConfig=e.data.previewConfig,this.chat&&this.chat.updatePreviewConfig(this.previewConfig)))})}async saveSettings(e){await this.http.patch("/settings",{conversation_id:this.conversationId,...e})}async syncSettings(){await this.http.post("/sync",{conversation_id:this.conversationId})}async fetchModels(){try{return await this.http.get("/models")}catch{}return[]}async authenticate(){let e=await fetch(`${this.baseUrl}/auth`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`},body:JSON.stringify({game_id:this.gameId})});if(!e.ok)throw e.status===401?new l("UNAUTHORIZED","User not authenticated"):e.status===404?new l("GAME_NOT_FOUND","Game not found or not published"):new l("INTERNAL_ERROR",`Auth failed: HTTP ${e.status}`);let t=await e.json();return t.data??t}getSavedModelId(){try{return localStorage.getItem("storvia_model_id")||""}catch{return""}}async initDev(e){if(this.initialized)return;this.baseUrl=`${J}${O}`,this.gameId=e.gameId,this.isPreview=!0,this.http=new E(this.baseUrl,"",!1,e.apiKey);let t=await this.fetchModels();this.modelId=t[0]?.id||"",this.conversationId="00000000-0000-0000-0000-000000000000",this.settingsSheet=new u({onModelChange:r=>{this.modelId=r},onSettingsChange:()=>Promise.resolve(),onSync:()=>Promise.resolve()}),t.length>0&&this.settingsSheet.mount(t,this.modelId,{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""},!1);let n=()=>this.gameId,i=()=>this.conversationId,s=()=>this.modelId;this.chat=new v(this.http,n,i,s,!0,void 0),this.characters=new f(this.http,i,!0),this.relationships=new y(this.http,i,!0),this.inventory=new w(this.http,i,!0),this.world=new b(this.http,i,!0),this.player=new C(this.http,i,!0),this.custom=new x(this.http,i,!0),this.initialized=!0}};async function $(a){let e=new S;return a?.dev?await e.initDev(a.dev):await e.init(),e}function _(a){return typeof a=="object"&&a!==null&&"value"in a&&"type"in a&&(a.type==="number"||a.type==="text")}function L(a){return _(a)?a.value:a}0&&(module.exports={StorviaError,StorviaSDK,createStorviaSDK,extractFieldValue,isRichFieldValue});
|
|
634
|
+
|
|
635
|
+
/* \u2500\u2500 Mobile: \u5E95\u90E8\u5F39\u51FA sheet \u2500\u2500 */
|
|
636
|
+
@media (max-width: 768px) {
|
|
637
|
+
.panel {
|
|
638
|
+
position: fixed !important;
|
|
639
|
+
left: 0 !important;
|
|
640
|
+
right: 0 !important;
|
|
641
|
+
bottom: 0 !important;
|
|
642
|
+
top: auto !important;
|
|
643
|
+
width: 100% !important;
|
|
644
|
+
max-height: 85vh;
|
|
645
|
+
border-radius: 16px 16px 0 0;
|
|
646
|
+
box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
|
|
647
|
+
transform: translateY(100%);
|
|
648
|
+
transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
|
|
649
|
+
display: flex;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
.panel.open {
|
|
653
|
+
transform: translateY(0);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
.panel::before {
|
|
657
|
+
content: '';
|
|
658
|
+
position: absolute;
|
|
659
|
+
top: 8px;
|
|
660
|
+
left: 50%;
|
|
661
|
+
transform: translateX(-50%);
|
|
662
|
+
width: 36px;
|
|
663
|
+
height: 4px;
|
|
664
|
+
border-radius: 2px;
|
|
665
|
+
background: rgba(255, 255, 255, 0.2);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
.panel-header {
|
|
669
|
+
padding-top: 24px;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.panel-footer {
|
|
673
|
+
padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
`,K='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>',Z='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6M3 12a9 9 0 0 1 15-6.7L21 8M3 22v-6h6M21 12a9 9 0 0 1-15 6.7L3 16"/></svg>',q='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="spin"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',J='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',Q='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',D='<svg class="check" viewBox="0 0 24 24" fill="none" stroke="#8246FF" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',m=48,u=16,ee=5,y=class{constructor(e){this.selectedModelId="";this.models=[];this.settings={temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""};this.activeTab="model";this.selectedCategory=null;this.hasWorldUpdate=!1;this.fabDot=null;this.syncHint=null;this.fabX=0;this.fabY=0;this.fab=null;this.panel=null;this.modelTabBtn=null;this.settingsTabBtn=null;this.modelBody=null;this.settingsBody=null;this.footer=null;this.modelGrid=null;this.modelDetail=null;this.tempValueEl=null;this.segmentBtns=[];this.langDropdown=null;this.langOptions=[];this.langArrow=null;this.langDropdownOpen=!1;this.noteCounter=null;this.saveBtn=null;this.syncBtn=null;this.syncState="idle";this.dragStartX=0;this.dragStartY=0;this.dragOffsetX=0;this.dragOffsetY=0;this.dragMoved=!1;this.dragging=!1;this.handlePointerDown=e=>{this.fab&&(e.preventDefault(),this.dragStartX=e.clientX,this.dragStartY=e.clientY,this.dragOffsetX=e.clientX-this.fabX,this.dragOffsetY=e.clientY-this.fabY,this.dragMoved=!1,this.dragging=!0,this.fab.setPointerCapture(e.pointerId),this.fab.addEventListener("pointermove",this.handlePointerMove),this.fab.addEventListener("pointerup",this.handlePointerUp),this.fab.addEventListener("pointercancel",this.handlePointerUp))};this.handlePointerMove=e=>{if(!this.dragging)return;let t=e.clientX-this.dragStartX,n=e.clientY-this.dragStartY;!this.dragMoved&&Math.hypot(t,n)>ee&&(this.dragMoved=!0,this.fab?.classList.add("dragging"),this.closePanel()),this.dragMoved&&(this.fabX=e.clientX-this.dragOffsetX,this.fabY=e.clientY-this.dragOffsetY,this.applyHostPosition())};this.handlePointerUp=e=>{if(!this.fab)return;this.fab.removeEventListener("pointermove",this.handlePointerMove),this.fab.removeEventListener("pointerup",this.handlePointerUp),this.fab.removeEventListener("pointercancel",this.handlePointerUp);try{this.fab.releasePointerCapture(e.pointerId)}catch{}if(this.dragging=!1,!this.dragMoved){this.togglePanel();return}this.fab.classList.remove("dragging");let n=this.fabX+m/2<window.innerWidth/2;this.fabX=n?u:window.innerWidth-m-u,this.fabY=Math.max(u,Math.min(window.innerHeight-m-u,this.fabY)),this.fab&&(this.fab.style.transition="left 0.25s cubic-bezier(0.32, 0.72, 0, 1), top 0.25s cubic-bezier(0.32, 0.72, 0, 1), transform 0.2s, box-shadow 0.2s"),this.applyHostPosition(),setTimeout(()=>{this.fab&&(this.fab.style.transition="")},260)};this.handleResize=()=>{this.fabX=Math.max(u,Math.min(window.innerWidth-m-u,this.fabX)),this.fabY=Math.max(u,Math.min(window.innerHeight-m-u,this.fabY)),this.applyHostPosition()};this.handleDocClick=e=>{this.host.contains(e.target)||(this.closePanel(),this.closeLangDropdown())};this.savedBodyOverflow=null;this.callbacks=e,this.host=document.createElement("div"),this.host.id="storvia-settings",this.shadowRoot=this.host.attachShadow({mode:"closed"})}mount(e,t,n,i=!1){this.models=e,this.selectedModelId=t,this.settings={...n},this.hasWorldUpdate=i,this.fabX=window.innerWidth-m-u,this.fabY=window.innerHeight-m-u,document.body.appendChild(this.host),this.render(),this.applyHostPosition(),window.addEventListener("resize",this.handleResize),document.addEventListener("click",this.handleDocClick)}unmount(){window.removeEventListener("resize",this.handleResize),document.removeEventListener("click",this.handleDocClick),this.host.remove()}getSelectedModelId(){return this.selectedModelId}getSettings(){return{...this.settings}}render(){let e=document.createElement("style");e.textContent=W;let t=document.createElement("div");t.className="fab-wrap";let n=document.createElement("div");n.className="fab",n.title="\u6E38\u620F\u8BBE\u7F6E";let i=document.createElement("img");i.src=Y,i.alt="Storvia",n.appendChild(i),this.fab=n;let s=document.createElement("div");s.className=`fab-dot${this.hasWorldUpdate?" visible":""}`,this.fabDot=s,t.appendChild(n),t.appendChild(s);let r=document.createElement("div");r.className="panel",this.panel=r;let o=document.createElement("div");o.className="panel-header";let a=document.createElement("h2");a.className="panel-title",a.textContent="\u6E38\u620F\u8BBE\u7F6E";let c=document.createElement("button");c.className="close-btn",c.innerHTML=K,c.addEventListener("click",()=>this.closePanel()),o.appendChild(a),o.appendChild(c),r.appendChild(o);let d=document.createElement("div");d.className="tabs",this.modelTabBtn=this.createTabBtn("model","\u6A21\u578B\u9009\u62E9"),this.settingsTabBtn=this.createTabBtn("settings","\u6E38\u620F\u8BBE\u7F6E"),this.models.length===0&&(this.activeTab="settings",this.modelTabBtn.style.display="none"),d.appendChild(this.modelTabBtn),d.appendChild(this.settingsTabBtn),r.appendChild(d);let h=document.createElement("div");h.className="panel-body",this.modelBody=this.buildModelTab(),this.settingsBody=this.buildSettingsTab(),h.appendChild(this.modelBody),h.appendChild(this.settingsBody),r.appendChild(h);let g=document.createElement("div");g.className="panel-footer";let v=document.createElement("button");v.className="btn btn-save",v.textContent="\u4FDD\u5B58",this.saveBtn=v,v.addEventListener("click",()=>this.handleSave()),g.appendChild(v),this.footer=g,r.appendChild(g),n.addEventListener("pointerdown",this.handlePointerDown);let f=document.createElement("div");f.appendChild(r),f.appendChild(t),this.shadowRoot.appendChild(e),this.shadowRoot.appendChild(f),this.applyTab()}createTabBtn(e,t){let n=document.createElement("button");return n.className=`tab-btn${this.activeTab===e?" active":""}`,n.textContent=t,n.addEventListener("click",()=>{this.activeTab=e,this.applyTab()}),n}applyTab(){this.modelTabBtn&&this.modelTabBtn.classList.toggle("active",this.activeTab==="model"),this.settingsTabBtn&&this.settingsTabBtn.classList.toggle("active",this.activeTab==="settings"),this.modelBody&&(this.modelBody.style.display=this.activeTab==="model"?"block":"none"),this.settingsBody&&(this.settingsBody.style.display=this.activeTab==="settings"?"block":"none"),this.footer&&(this.footer.style.display=this.activeTab==="settings"?"flex":"none")}buildModelTab(){let e=document.createElement("div"),t=this.getCategories();if(t.length>0){let s=document.createElement("div");s.className="category-tabs";let r=(o,a)=>{let c=document.createElement("button");return c.className=`category-tab${this.selectedCategory===a?" active":""}`,c.textContent=o,c.addEventListener("click",()=>{this.selectedCategory=a,s.querySelectorAll(".category-tab").forEach(d=>d.classList.remove("active")),c.classList.add("active"),this.renderModelGrid()}),c};s.appendChild(r("\u5168\u90E8",null)),t.forEach(o=>s.appendChild(r(o,o))),e.appendChild(s)}let n=document.createElement("div");n.className="models-grid",this.modelGrid=n,e.appendChild(n);let i=document.createElement("div");return i.className="model-detail",i.style.display="none",this.modelDetail=i,e.appendChild(i),this.renderModelGrid(),this.renderModelDetail(),e}getCategories(){let e=new Set;return this.models.forEach(t=>{t.category&&e.add(t.category)}),Array.from(e)}getFilteredModels(){return this.selectedCategory?this.models.filter(e=>e.category===this.selectedCategory):this.models}renderModelGrid(){this.modelGrid&&(this.modelGrid.innerHTML="",this.getFilteredModels().forEach(e=>{let t=document.createElement("button"),n=e.is_active!==!1;t.className=`model-card${e.id===this.selectedModelId?" selected":""}${n?"":" disabled"}`;let i=this.getStatusDotColor(e);t.innerHTML=`<span class="status-dot" style="background:${i}"></span><span class="model-name">${this.escapeHtml(e.name)}</span>`,t.addEventListener("click",()=>this.handleSelectModel(e)),this.modelGrid.appendChild(t)}))}handleSelectModel(e){if(this.selectedModelId=e.id,e.is_active!==!1){this.callbacks.onModelChange(e.id);try{localStorage.setItem("storvia_model_id",e.id)}catch{}}let t=this.getFilteredModels();this.modelGrid&&this.modelGrid.querySelectorAll(".model-card").forEach((n,i)=>{n.classList.toggle("selected",t[i].id===this.selectedModelId)}),this.renderModelDetail()}renderModelDetail(){if(!this.modelDetail)return;let e=this.models.find(r=>r.id===this.selectedModelId);if(!e){this.modelDetail.style.display="none";return}this.modelDetail.style.display="block";let t=this.getStatusClass(e),n=this.getStatusText(e),i=this.getCreditsRange(e),s=e.description||"";this.modelDetail.innerHTML=`
|
|
677
|
+
<div class="detail-header">
|
|
678
|
+
<span class="detail-title">${this.escapeHtml(e.name)}</span>
|
|
679
|
+
<span class="detail-status ${t}">${n}</span>
|
|
680
|
+
</div>
|
|
681
|
+
${i?`<div class="detail-credits">
|
|
682
|
+
<span class="credits-label">\u6D88\u8017</span>
|
|
683
|
+
<span class="credits-value">${i}</span>
|
|
684
|
+
<img class="credits-icon" src="${X}" alt="credits" />
|
|
685
|
+
<span class="credits-unit">/\u6B21</span>
|
|
686
|
+
</div>`:""}
|
|
687
|
+
${s?`<div class="detail-description">${this.escapeHtml(s)}</div>`:""}
|
|
688
|
+
`}getStatusDotColor(e){if(e.is_active===!1)return"#6b7280";let t=e.success_rate??100;return t>=95?"#10b981":t>=80?"#3b82f6":t>=60?"#eab308":"#f97316"}getStatusClass(e){if(e.is_active===!1)return"inactive";let t=e.success_rate??100;return t>=95?"excellent":t>=80?"good":t>=60?"normal":"crowded"}getStatusText(e){if(e.is_active===!1)return"\u505C\u7528";let t=e.success_rate??100;return t>=95?"\u6D41\u7545":t>=80?"\u826F\u597D":t>=60?"\u4E00\u822C":"\u62E5\u6324"}getCreditsRange(e){let t=e.credits_config?.min??0,n=e.credits_config?.max??0;return t===0&&n===0?"":t===n?`${t}`:`${t}\uFF5E${n}`}buildSettingsTab(){let e=document.createElement("div"),t=document.createElement("div");return t.className="form-stack",t.appendChild(this.buildTemperatureSection()),t.appendChild(this.buildReplyLengthSection()),t.appendChild(this.buildReplyLanguageSection()),t.appendChild(this.buildNoteSection()),t.appendChild(this.buildSyncSection()),e.appendChild(t),e}buildTemperatureSection(){let e=document.createElement("div");e.className="form-group";let t=document.createElement("label");t.className="form-label";let n=document.createElement("span");n.textContent="\u6E29\u5EA6";let i=document.createElement("span");i.className="temperature-value",i.textContent=this.settings.temperature.toFixed(1),this.tempValueEl=i,t.appendChild(n),t.appendChild(i),e.appendChild(t);let s=document.createElement("p");s.className="form-hint",s.textContent="\u66F4\u4F4E\u8BA9 AI \u56DE\u590D\u66F4\u7A33\u5B9A\u7406\u667A\uFF0C\u66F4\u9AD8\u8BA9\u56DE\u590D\u66F4\u5177\u591A\u6837\u6027",e.appendChild(s);let r=document.createElement("input");r.type="range",r.className="slider",r.min="0",r.max="1",r.step="0.1",r.value=String(this.settings.temperature),r.addEventListener("input",()=>{let a=parseFloat(r.value);this.settings.temperature=a,this.tempValueEl&&(this.tempValueEl.textContent=a.toFixed(1))}),e.appendChild(r);let o=document.createElement("div");return o.className="slider-labels",o.innerHTML="<span>\u7CBE\u786E</span><span>\u521B\u610F</span>",e.appendChild(o),e}buildReplyLengthSection(){let e=document.createElement("div");e.className="form-group";let t=document.createElement("label");t.className="form-label",t.textContent="\u56DE\u590D\u957F\u5EA6",e.appendChild(t);let n=document.createElement("div");return n.className="segment-control",this.segmentBtns=[],N.forEach(i=>{let s=document.createElement("button");s.className=`segment-button${i.value===this.settings.reply_length?" active":""}`,s.textContent=i.label,s.addEventListener("click",()=>{this.settings.reply_length=i.value,this.segmentBtns.forEach((r,o)=>{r.classList.toggle("active",N[o].value===i.value)})}),this.segmentBtns.push(s),n.appendChild(s)}),e.appendChild(n),e}buildReplyLanguageSection(){let e=document.createElement("div");e.className="form-group";let t=document.createElement("label");t.className="form-label",t.textContent="\u56DE\u590D\u8BED\u8A00",e.appendChild(t);let n=document.createElement("div");n.className="custom-select";let i=document.createElement("button");i.className="select-trigger";let s=document.createElement("span");s.textContent=R.find(a=>a.value===this.settings.reply_language)?.label||"";let r=document.createElement("span");r.className="select-arrow",r.textContent="\u25BE",this.langArrow=r,i.appendChild(s),i.appendChild(r),i.addEventListener("click",a=>{a.stopPropagation(),this.toggleLangDropdown()}),n.appendChild(i);let o=document.createElement("div");return o.className="select-dropdown",this.langDropdown=o,this.langOptions=[],R.forEach(a=>{let c=document.createElement("button");c.className=`select-option${a.value===this.settings.reply_language?" active":""}`,c.innerHTML=`<span>${a.label}</span>${a.value===this.settings.reply_language?D:""}`,c.addEventListener("click",()=>{this.settings.reply_language=a.value,s.textContent=a.label,this.langOptions.forEach((d,h)=>{d.classList.toggle("active",R[h].value===a.value),d.innerHTML=`<span>${R[h].label}</span>${R[h].value===a.value?D:""}`}),this.closeLangDropdown()}),this.langOptions.push(c),o.appendChild(c)}),n.appendChild(o),e.appendChild(n),e}toggleLangDropdown(){this.langDropdownOpen?this.closeLangDropdown():this.openLangDropdown()}openLangDropdown(){this.langDropdownOpen=!0,this.langDropdown?.classList.add("open"),this.langArrow&&(this.langArrow.textContent="\u25B4")}closeLangDropdown(){this.langDropdownOpen=!1,this.langDropdown?.classList.remove("open"),this.langArrow&&(this.langArrow.textContent="\u25BE")}buildNoteSection(){let e=document.createElement("div");e.className="form-group";let t=document.createElement("label");t.className="form-label";let n=document.createElement("span");n.textContent="\u5907\u6CE8";let i=document.createElement("span");i.className="char-count",i.textContent=`${this.settings.player_note.length}/50`,this.noteCounter=i,t.appendChild(n),t.appendChild(i),e.appendChild(t);let s=document.createElement("p");s.className="form-hint",s.textContent="\u5199\u4E0B\u4F60\u5BF9\u8FD9\u4E2A\u6E38\u620F\u7684\u5907\u6CE8\uFF0C\u4F1A\u663E\u793A\u5728\u5B58\u6863\u5217\u8868",e.appendChild(s);let r=document.createElement("textarea");return r.className="player-note-input",r.placeholder="\u5907\u6CE8",r.maxLength=50,r.rows=2,r.value=this.settings.player_note,r.addEventListener("input",()=>{this.settings.player_note=r.value,this.noteCounter&&(this.noteCounter.textContent=`${r.value.length}/50`)}),e.appendChild(r),e}buildSyncSection(){let e=document.createElement("div");e.className="form-group";let t=document.createElement("label");t.className="form-label",t.textContent="\u540C\u6B65\u6E38\u620F\u8BBE\u5B9A",e.appendChild(t);let n=document.createElement("p");n.className=`sync-hint${this.hasWorldUpdate?" visible":""}`,n.textContent="\u26A0 \u4F5C\u8005\u5DF2\u66F4\u65B0\u6E38\u620F\u5185\u5BB9\uFF0C\u5EFA\u8BAE\u70B9\u51FB\u540C\u6B65",this.syncHint=n,e.appendChild(n);let i=document.createElement("p");i.className="form-hint",i.textContent="\u5C06\u6700\u65B0\u6E38\u620F\u8BBE\u5B9A\u548C\u5F00\u5E55\u5C0F\u5267\u573A\u540C\u6B65\u5230\u5F53\u524D\u5BF9\u8BDD",e.appendChild(i);let s=document.createElement("button");return s.className="btn btn-sync",this.syncBtn=s,this.renderSyncBtn(),s.addEventListener("click",async()=>{if(this.syncState!=="loading"){this.setSyncState("loading");try{await this.callbacks.onSync(),this.setSyncState("success"),this.hasWorldUpdate=!1,this.fabDot&&this.fabDot.classList.remove("visible"),this.syncHint&&this.syncHint.classList.remove("visible"),setTimeout(()=>this.setSyncState("idle"),3e3)}catch{this.setSyncState("error"),setTimeout(()=>this.setSyncState("idle"),4e3)}}}),e.appendChild(s),e}setSyncState(e){this.syncState=e,this.renderSyncBtn()}renderSyncBtn(){if(!this.syncBtn)return;let e=this.syncState,t={idle:Z,loading:q,success:J,error:Q},n={idle:"\u540C\u6B65\u6700\u65B0\u8BBE\u5B9A",loading:"\u540C\u6B65\u4E2D...",success:"\u5DF2\u540C\u6B65",error:"\u540C\u6B65\u5931\u8D25"};this.syncBtn.className=`btn btn-sync${e==="success"||e==="error"?` ${e}`:""}`,this.syncBtn.disabled=e==="loading",this.syncBtn.innerHTML=`${t[e]}<span>${n[e]}</span>`}async handleSave(){if(!(!this.saveBtn||this.saveBtn.disabled)){this.saveBtn.disabled=!0,this.saveBtn.innerHTML='<span class="spinner"></span>\u4FDD\u5B58\u4E2D...';try{await this.callbacks.onSettingsChange({temperature:this.settings.temperature,reply_length:this.settings.reply_length,reply_language:this.settings.reply_language,player_note:this.settings.player_note}),this.saveBtn&&(this.saveBtn.textContent="\u4FDD\u5B58",this.saveBtn.disabled=!1)}catch{this.saveBtn&&(this.saveBtn.textContent="\u4FDD\u5B58\u5931\u8D25",setTimeout(()=>{this.saveBtn&&(this.saveBtn.textContent="\u4FDD\u5B58",this.saveBtn.disabled=!1)},2e3))}}}escapeHtml(e){return e.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t])}applyHostPosition(){this.host.style.left=`${this.fabX}px`,this.host.style.top=`${this.fabY}px`,this.host.style.right="auto",this.host.style.bottom="auto",this.applyPanelPosition()}isMobile(){return window.innerWidth<=768}applyPanelPosition(){if(!this.panel)return;if(this.isMobile()){this.panel.style.left="",this.panel.style.right="",this.panel.style.top="",this.panel.style.bottom="";return}let e=this.fabX+m/2<window.innerWidth/2,t=380;e?(this.panel.style.left="0",this.panel.style.right="auto"):(this.panel.style.left=`${m-t}px`,this.panel.style.right="auto"),this.fabY>500?(this.panel.style.bottom=`${m+8}px`,this.panel.style.top="auto"):(this.panel.style.top=`${m+8}px`,this.panel.style.bottom="auto")}togglePanel(){this.panel&&(this.panel.classList.contains("open")?this.closePanel():(this.applyPanelPosition(),this.panel.classList.add("open"),requestAnimationFrame(()=>{this.panel?.classList.contains("open")&&(this.fab&&(this.fab.style.visibility="hidden"),this.fabDot&&(this.fabDot.style.visibility="hidden"))}),this.isMobile()&&this.lockBodyScroll()))}closePanel(){this.panel&&this.panel.classList.remove("open"),this.fab&&(this.fab.style.visibility="visible"),this.fabDot&&(this.fabDot.style.visibility="visible"),this.unlockBodyScroll()}lockBodyScroll(){this.savedBodyOverflow===null&&(this.savedBodyOverflow=document.body.style.overflow||"",document.body.style.overflow="hidden")}unlockBodyScroll(){this.savedBodyOverflow!==null&&(document.body.style.overflow=this.savedBodyOverflow,this.savedBodyOverflow=null)}};var w=class{constructor(e,t,n,i,s=!1,r){this.http=e;this.getGameId=t;this.getConversationId=n;this.getModelId=i;this.isPreview=s;this.previewConfig=r}updatePreviewConfig(e){this.previewConfig=e}async send(e){if(this.isPreview)return this.sendPreview(e);let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),message:e.message,topic:e.topic,scene_key:e.scene_key,stream:e.stream??!1};if(e.stream){await this.http.stream("/chat",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/chat",t)}async save(e){return this.isPreview?{id:`preview-${Date.now()}`}:this.http.post("/messages/save",{conversation_id:this.getConversationId(),role:e.role,content:e.content,topic:e.topic})}async generate(e){if(this.isPreview)return this.sendPreview({message:"",topic:e.topic,scene_key:e.scene_key,stream:e.stream,onChunk:e.onChunk,onDone:e.onDone});let t={conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.scene_key,stream:e.stream??!1,save:e.save??!0};if(e.stream){await this.http.stream("/generate",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/generate",t)}async retry(e={}){if(this.isPreview)throw new Error("Retry is not supported in preview mode");let t={conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.scene_key,stream:e.stream??!1};if(e.stream){await this.http.stream("/retry",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}return this.http.post("/retry",t)}async sendPreview(e){let t={model_id:this.getModelId(),message:e.message,topic:e.topic,scene_key:e.scene_key,history_messages:[]};if(this.previewConfig?t.prompt_config=this.previewConfig:t.game_id=this.getGameId(),e.stream){await this.http.stream("/preview",t,e.onChunk??(()=>{}),e.onDone??(()=>{}));return}let n="";return await this.http.stream("/preview",t,i=>{n+=i},()=>{}),{id:"",content:n}}};var _=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){return this.isPreview?{...this.mem[e]||{}}:this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`)}async update(e,t){if(this.isPreview){this.mem[e]={...this.mem[e]||{},...t};return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,t)}},C=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];this.state=new _(e,t,n)}async list(){return this.isPreview?this.mem.map(e=>({name:e.name,avatar:e.avatar,...e.gender?{gender:e.gender}:{}})):this.http.get(`/conversations/${this.getConversationId()}/characters`)}async get(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:t?.name||e,avatar:t?.avatar,...t?.gender?{gender:t.gender}:{}}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async add(e){if(this.isPreview){this.mem.push(e);return}await this.http.post(`/conversations/${this.getConversationId()}/characters`,e)}async update(e,t){if(this.isPreview){let n=this.mem.find(i=>i.name===e);n&&Object.assign(n,t);return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`,t)}async remove(e){if(this.isPreview){this.mem=this.mem.filter(t=>t.name!==e);return}await this.http.delete(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async detail(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:e,avatar:t?.avatar,state:await this.state.get(e)}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/detail`)}async setPriority(e,t){let n=Math.max(0,Math.min(100,Math.round(t)));this.isPreview||await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{priority:n})}};var x=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[]}async list(){return this.isPreview?[...this.mem]:this.http.get(`/conversations/${this.getConversationId()}/relationships`)}async get(e,t){if(this.isPreview){let n=this.mem.find(i=>i.from===e&&i.to===t);if(n)return{...n};throw new Error("Relationship not found")}return this.http.get(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async add(e){if(this.isPreview){this.mem.push({...e});return}await this.http.post(`/conversations/${this.getConversationId()}/relationships`,e)}async update(e,t,n){if(this.isPreview){let i=this.mem.find(s=>s.from===e&&s.to===t);i?Object.assign(i,n):this.mem.push({from:e,to:t,...n});return}await this.http.patch(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,n)}async remove(e,t){if(this.isPreview){this.mem=this.mem.filter(n=>!(n.from===e&&n.to===t));return}await this.http.delete(`/conversations/${this.getConversationId()}/relationships/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}};var I=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async list(e){if(this.isPreview){if(e!==void 0)return{...this.mem[e]||{}};let t={};for(let[n,i]of Object.entries(this.mem))t[n]={...i};return t}return e!==void 0?this.http.get(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(e)}`):this.http.get(`/conversations/${this.getConversationId()}/inventory`)}async add(e){let{group:t,name:n,count:i=1,desc:s,iconUrl:r}=e;if(this.isPreview){if(!this.mem[t])throw new Error(`Group "${t}" does not exist`);if(n in this.mem[t])throw new Error(`Item "${n}" already exists in group "${t}"`);let o={count:i};s!==void 0&&(o.desc=s),r!==void 0&&(o.iconUrl=r),this.mem[t][n]=o;return}await this.http.post(`/conversations/${this.getConversationId()}/inventory`,{group:t,name:n,count:i,desc:s,iconUrl:r})}async update(e){let{group:t,name:n,...i}=e;if(this.isPreview){let s=this.mem[t];if(!s||!(n in s))throw new Error(`Item "${t}/${n}" not found`);Object.assign(s[n],i);return}await this.http.patch(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,i)}async remove(e){let{group:t,name:n}=e;if(this.isPreview){this.mem[t]&&delete this.mem[t][n];return}await this.http.delete(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`)}async move(e){let{fromGroup:t,toGroup:n,name:i,newName:s}=e;if(this.isPreview){let r=this.mem[t];if(!r||!(i in r))throw new Error(`Source item "${t}/${i}" not found`);if(!this.mem[n])throw new Error(`Target group "${n}" does not exist`);let o=s||i;if(t===n&&o===i)return;if(o in this.mem[n])throw new Error(`Item "${o}" already exists in target group`);this.mem[n][o]=r[i],delete r[i];return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/move`,{fromGroup:t,toGroup:n,name:i,newName:s})}async ensureGroup(e){if(this.isPreview){this.mem[e]||(this.mem[e]={});return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}`,{})}async removeGroup(e,t){let n=t?.cascade??!1;if(this.isPreview){let s=this.mem[e];if(s&&Object.keys(s).length>0&&!n)throw new Error(`Group "${e}" is not empty, pass cascade: true to force delete`);delete this.mem[e];return}let i=n?"?cascade=true":"";await this.http.delete(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}${i}`)}};var E=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(){return this.isPreview?{...this.mem}:this.http.get(`/conversations/${this.getConversationId()}/world`)}async update(e){if(this.isPreview){Object.assign(this.mem,e);return}await this.http.patch(`/conversations/${this.getConversationId()}/world`,e)}};var O=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){if(this.isPreview)return e?{...this.mem[e]||{}}:{...this.mem};let t=e?{group:e}:void 0;return this.http.get(`/conversations/${this.getConversationId()}/player/state`,t)}async update(e,t){if(this.isPreview){this.mem[e]={...this.mem[e]||{},...t};return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,values:t})}},S=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.memPersona={name:""};this.state=new O(e,t,n)}async get(){return this.isPreview?{...this.memPersona}:this.http.get(`/conversations/${this.getConversationId()}/player`)}async update(e){if(this.isPreview){Object.assign(this.memPersona,e);return}await this.http.patch(`/conversations/${this.getConversationId()}/player`,e)}};var k=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={}}async get(e){if(this.isPreview)return e!==void 0?this.mem[e]:{...this.mem};let t=await this.http.get(`/conversations/${this.getConversationId()}/custom`);return e!==void 0?t[e]:t}async set(e){if(this.isPreview){for(let[t,n]of Object.entries(e))typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof this.mem[t]=="object"&&this.mem[t]!==null?this.mem[t]={...this.mem[t],...n}:this.mem[t]=n;return}await this.http.patch(`/conversations/${this.getConversationId()}/custom`,e)}async delete(e){if(this.isPreview){delete this.mem[e];return}await this.http.delete(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}`)}async setGroupField(e,t,n){if(this.isPreview){(!this.mem[e]||typeof this.mem[e]!="object")&&(this.mem[e]={}),this.mem[e][t]=n;return}await this.http.patch(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{value:n})}async deleteGroupField(e,t){if(this.isPreview){if(typeof this.mem[e]=="object"&&this.mem[e]!==null){let n=this.mem[e];delete n[t]}return}await this.http.delete(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}};var B="/functions/v1/world-engine/v1",te="https://api.storvia.ai";function ne(){return window.__STORVIA__||{}}function ie(l=5e3){let e=ne();return e.apiBase?Promise.resolve(e):new Promise((t,n)=>{let i=setTimeout(()=>{window.removeEventListener("message",s),n(new p("NOT_INITIALIZED","Timed out waiting for __STORVIA__ config from parent frame."))},l);function s(r){let o=null;if(r.data?.type==="storvia-init"&&r.data.apiBase?o={apiBase:r.data.apiBase,gameId:r.data.gameId,accessToken:r.data.accessToken}:r.data?.type==="storvia-preview-init"&&r.data.config&&(o=r.data.config),o&&o.apiBase){clearTimeout(i),window.removeEventListener("message",s);let a=window;a.__STORVIA__=o,t(o)}}window.addEventListener("message",s)})}var T=class{constructor(){this.baseUrl="";this.gameId="";this.conversationId="";this.modelId="";this.accessToken="";this.initialized=!1;this.isPreview=!1;this.previewConfig=void 0}async init(){if(this.initialized)return;let e=await ie(),t=e.apiBase;if(!t)throw new p("NOT_INITIALIZED","window.__STORVIA__.apiBase is not set. The platform must inject it before SDK init.");if(this.baseUrl=`${t}${B}`,this.isPreview=!!e.preview,this.previewConfig=e.previewConfig,!e.gameId)throw new p("GAME_NOT_FOUND","window.__STORVIA__.gameId is not set. The platform must inject it before SDK init.");if(this.gameId=e.gameId,!e.accessToken)throw new p("UNAUTHORIZED","window.__STORVIA__.accessToken is not set. The platform must inject the user token before SDK init.");if(this.accessToken=e.accessToken,this.http=new P(this.baseUrl,this.accessToken,!!e.debug),this.isPreview){this.conversationId="00000000-0000-0000-0000-000000000000";let d=await this.fetchModels();this.modelId=e.selectedModelId||d[0]?.id||"",this.settingsSheet=new y({onModelChange:f=>{this.modelId=f},onSettingsChange:()=>Promise.resolve(),onSync:()=>Promise.resolve()}),d.length>0&&this.settingsSheet.mount(d,this.modelId,{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""},!1);let h=()=>this.gameId,g=()=>this.conversationId,v=()=>this.modelId;this.chat=new w(this.http,h,g,v,!0,this.previewConfig),this.characters=new C(this.http,g,!0),this.relationships=new x(this.http,g,!0),this.inventory=new I(this.http,g,!0),this.world=new E(this.http,g,!0),this.player=new S(this.http,g,!0),this.custom=new k(this.http,g,!0),this.initialized=!0,this.listenForPreviewMessages();return}let[n,i]=await Promise.all([this.authenticate(),this.fetchModels()]);this.conversationId=n.conversationId;let s=this.getSavedModelId();this.modelId=s&&i.some(d=>d.id===s)?s:i[0]?.id||"";let r=n.settings||{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""};this.settingsSheet=new y({onModelChange:d=>{this.modelId=d},onSettingsChange:d=>this.saveSettings(d),onSync:()=>this.syncSettings()}),this.settingsSheet.mount(i,this.modelId,r,n.hasWorldUpdate??!1);let o=()=>this.gameId,a=()=>this.conversationId,c=()=>this.modelId;this.chat=new w(this.http,o,a,c),this.characters=new C(this.http,a),this.relationships=new x(this.http,a),this.inventory=new I(this.http,a),this.world=new E(this.http,a),this.player=new S(this.http,a),this.custom=new k(this.http,a),this.initialized=!0}listenForPreviewMessages(){window.addEventListener("message",e=>{!e.data||e.data.type!=="storvia-preview"||(e.data.action==="set-model"&&(this.modelId=e.data.modelId||""),e.data.action==="update-config"&&(this.previewConfig=e.data.previewConfig,this.chat&&this.chat.updatePreviewConfig(this.previewConfig)))})}async saveSettings(e){await this.http.patch("/settings",{conversation_id:this.conversationId,...e})}async syncSettings(){await this.http.post("/sync",{conversation_id:this.conversationId})}async fetchModels(){try{return await this.http.get("/models")}catch{}return[]}async authenticate(){let e=await fetch(`${this.baseUrl}/auth`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`},body:JSON.stringify({game_id:this.gameId})});if(!e.ok)throw e.status===401?new p("UNAUTHORIZED","User not authenticated"):e.status===404?new p("GAME_NOT_FOUND","Game not found or not published"):new p("INTERNAL_ERROR",`Auth failed: HTTP ${e.status}`);let t=await e.json();return t.data??t}getSavedModelId(){try{return localStorage.getItem("storvia_model_id")||""}catch{return""}}async initDev(e){if(this.initialized)return;this.baseUrl=`${te}${B}`,this.gameId=e.gameId,this.isPreview=!0,this.http=new P(this.baseUrl,"",!1,e.apiKey);let t=await this.fetchModels();this.modelId=t[0]?.id||"",this.conversationId="00000000-0000-0000-0000-000000000000",this.settingsSheet=new y({onModelChange:r=>{this.modelId=r},onSettingsChange:()=>Promise.resolve(),onSync:()=>Promise.resolve()}),t.length>0&&this.settingsSheet.mount(t,this.modelId,{temperature:1,reply_length:"medium",reply_language:"zh-CN",player_note:""},!1);let n=()=>this.gameId,i=()=>this.conversationId,s=()=>this.modelId;this.chat=new w(this.http,n,i,s,!0,void 0),this.characters=new C(this.http,i,!0),this.relationships=new x(this.http,i,!0),this.inventory=new I(this.http,i,!0),this.world=new E(this.http,i,!0),this.player=new S(this.http,i,!0),this.custom=new k(this.http,i,!0),this.initialized=!0}};async function H(l){let e=new T;return l?.dev?await e.initDev(l.dev):await e.init(),e}function $(l){return typeof l=="object"&&l!==null&&"value"in l&&"type"in l&&(l.type==="number"||l.type==="text")}function U(l){return $(l)?l.value:l}0&&(module.exports={StorviaError,StorviaSDK,createStorviaSDK,extractFieldValue,isRichFieldValue});
|