@storvia/sdk 0.10.4 → 0.10.6

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 CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var le=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(o,e)=>{for(var t in e)le(o,t,{get:e[t],enumerable:!0})},nt=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Je(e))!et.call(o,r)&&r!==t&&le(o,r,{get:()=>e[r],enumerable:!(n=Xe(e,r))||n.enumerable});return o};var rt=o=>nt(le({},"__esModule",{value:!0}),o);var _t={};tt(_t,{HOST_NOTIFY_MAX_LENGTH:()=>ve,HOST_NOTIFY_MIN_INTERVAL_MS:()=>Ie,HOST_PANEL_SCOPES:()=>he,HOST_REFRESH_MIN_INTERVAL_MS:()=>Ee,HostModule:()=>A,PROTOCOL_VERSION:()=>$,StorviaBus:()=>x,StorviaError:()=>g,StorviaSDK:()=>ne,createStorviaSDK:()=>Qe,envelope:()=>C,extractFieldValue:()=>Ze,isProtocolEnvelope:()=>J,isRichFieldValue:()=>ye,setToastEnabled:()=>Ge,showToast:()=>ee});module.exports=rt(_t);var g=class extends Error{constructor(e,t,n){super(t),this.name="StorviaError",this.code=e,n?.length&&(this.matchedWords=n)}};var $=1,he=["player","characters","inventory","relations","world"];function J(o){if(!o||typeof o!="object")return!1;let e=o;return typeof e.protocol=="number"&&typeof e.type=="string"&&"payload"in e}function C(o,e,t){return{protocol:1,type:o,payload:e,...t?.id?{id:t.id}:{},...t?.ackId?{ackId:t.ackId}:{}}}var x=class{constructor(e){this.handlers=new Map;this.pendingAcks=new Map;this.listener=null;this.incoming=e.incoming,this.getOutgoing=e.outgoing,this.verifySource=e.verifySource??(()=>!0),this.validate=e.validate,this.debug=!!e.debug,this.getTransferables=e.transfer??(()=>{}),this.customSend=e.customSend,this.attach()}attach(){this.listener=e=>{if((this.incoming instanceof Window||this.incoming===window)&&!this.verifySource(e))return;let t=e.data;if(!J(t))return;if(t.protocol!==1){this.debug&&console.warn("[StorviaBus] protocol mismatch",{expected:1,got:t.protocol,type:t.type});return}if(this.validate&&!this.validate(t)){this.debug&&console.warn("[StorviaBus] validation failed",t);return}if(t.ackId){let r=this.pendingAcks.get(t.ackId);if(r){this.pendingAcks.delete(t.ackId),r(t);return}}let n=this.handlers.get(t.type);if(!n||n.size===0){this.debug&&console.debug("[StorviaBus] no handler for",t.type);return}n.forEach(r=>{try{r(t)}catch(i){console.error(`[StorviaBus] handler '${t.type}' threw:`,i)}})},this.incoming.addEventListener("message",this.listener),this.incoming instanceof MessagePort&&this.incoming.start()}on(e,t){let n=this.handlers.get(e);n||(n=new Set,this.handlers.set(e,n));let r=t;return n.add(r),()=>n.delete(r)}send(e){let t=e.protocol?e:C(e.type,e.payload,{id:e.id,ackId:e.ackId});if(this.customSend){try{this.customSend(t)}catch(i){console.error("[StorviaBus] customSend failed:",i,{type:e.type})}return}let n=this.getOutgoing();if(!n){this.debug&&console.warn("[StorviaBus] outgoing target unavailable, drop:",e.type);return}let r=this.getTransferables(t);try{n instanceof MessagePort?n.postMessage(t,r??[]):n.postMessage(t,"*",r??[])}catch(i){console.error("[StorviaBus] postMessage failed:",i,{type:e.type})}}request(e,t=1e4){return new Promise((n,r)=>{let i=e.id??ot(),s=C(e.type,e.payload,{id:i}),d=setTimeout(()=>{this.pendingAcks.delete(i),r(new Error(`[StorviaBus] request '${e.type}' timed out after ${t}ms`))},t);this.pendingAcks.set(i,c=>{clearTimeout(d),n(c)}),this.send(s)})}destroy(){if(this.listener&&(this.incoming.removeEventListener("message",this.listener),this.listener=null),this.incoming instanceof MessagePort)try{this.incoming.close()}catch{}this.handlers.clear(),this.pendingAcks.clear()}};function ot(){return`bus-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var it=["zh","zh-Hant","en","ja","ko"];var st={common:{unknownError:"\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",violationWords:"\u5185\u5BB9\u5305\u542B\u4E0D\u7B26\u5408\u793E\u533A\u89C4\u8303\u7684\u7528\u8BCD{words}\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5",close:"\u5173\u95ED"},errors:{UNAUTHORIZED:"\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",INSUFFICIENT_CREDITS:"\u82B1\u56ED\u5E01\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u7EE7\u7EED\u6E38\u620F",VIOLATION_WORD_DETECTED:"\u5185\u5BB9\u542B\u6709\u8FDD\u7981\u8BCD\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5",CONTENT_FILTERED:"\u5185\u5BB9\u88AB\u5B89\u5168\u7B56\u7565\u62E6\u622A\uFF0C\u8BF7\u8C03\u6574\u540E\u91CD\u8BD5",MODEL_REFUSAL:"\u6A21\u578B\u62D2\u7EDD\u54CD\u5E94\uFF0C\u6362\u4E2A\u8BF4\u6CD5\u8BD5\u8BD5",STREAM_INTERRUPTED:"\u56DE\u590D\u5DF2\u4E2D\u65AD\uFF0C\u8BF7\u91CD\u8BD5",RATE_LIMITED:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",GENERATING_IN_PROGRESS:"\u5F53\u524D\u5267\u60C5\u6B63\u5728\u751F\u6210\u4E2D\uFF0C\u8BF7\u7A0D\u5019",CONCURRENT_GENERATION_LIMIT:"\u540C\u65F6\u8FDB\u884C\u7684\u5267\u60C5\u592A\u591A\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5",INVENTORY_LIMIT:"\u7269\u54C1\u680F\u5DF2\u6EE1\uFF0C\u8BF7\u5148\u6E05\u7406\u518D\u6DFB\u52A0",CUSTOM_FIELDS_LIMIT:"\u6269\u5C55\u5C5E\u6027\u5B57\u6BB5\u5DF2\u6EE1\uFF0C\u8BF7\u5148\u5220\u9664\u518D\u6DFB\u52A0",MODEL_NOT_FOUND:"\u6240\u9009\u6A21\u578B\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5207\u6362\u5176\u4ED6\u6A21\u578B",GAME_NOT_FOUND:"\u672A\u627E\u5230\u5BF9\u5E94\u6E38\u620F",INVALID_REQUEST:"\u8BF7\u6C42\u65E0\u6548\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",INVALID_EXTRACT_RULE:"\u56DE\u590D\u63D0\u53D6\u914D\u7F6E\u65E0\u6548\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",INTERNAL_ERROR:"\u670D\u52A1\u51FA\u4E86\u70B9\u5C0F\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",NOT_INITIALIZED:"SDK \u5C1A\u672A\u521D\u59CB\u5316",NOT_SUPPORTED_IN_PREVIEW:"\u5F53\u524D\u63A5\u53E3\u5728\u9884\u89C8\u6A21\u5F0F\u4E0B\u4E0D\u53EF\u7528",NETWORK_ERROR:"\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u8FDE\u63A5",REQUEST_TIMEOUT:"\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",MODEL_LOADING_TIMEOUT:"\u6A21\u578B\u54CD\u5E94\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",DAISY_CARD_REQUIRED:"\u56DE\u6EAF\u6D88\u606F\u9700\u8981\u6709\u6548\u7684\u96CF\u83CA\u5361\u8BA2\u9605",MESSAGE_NOT_FOUND:"\u6D88\u606F\u4E0D\u5B58\u5728\u6216\u65E0\u6743\u64CD\u4F5C",MESSAGE_TOO_OLD:"\u4EC5\u53EF\u56DE\u6EAF 30 \u5929\u5185\u7684\u6D88\u606F",NO_MESSAGES_TO_DELETE:"\u8BE5\u6D88\u606F\u4E4B\u540E\u6CA1\u6709\u53EF\u56DE\u6EAF\u7684\u6D88\u606F",GENERATION_TIMEOUT:"\u751F\u6210\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5",GENERATION_LOST:"\u751F\u6210\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u82E5\u5185\u5BB9\u5DF2\u751F\u6210\uFF0C\u5237\u65B0\u540E\u53EF\u89C1",REPETITION_LOOP:"\u56DE\u590D\u51FA\u73B0\u91CD\u590D\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u4E2A\u8BF4\u6CD5",SAVE_FAILED:"\u6D88\u606F\u4FDD\u5B58\u5931\u8D25\uFF0C\u672C\u6B21\u4E0D\u6263\u8D39\uFF0C\u8BF7\u91CD\u8BD5",FINALIZE_FAILED:"\u56DE\u590D\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",CONVERSATION_NOT_FOUND:"\u672A\u627E\u5230\u5BF9\u5E94\u4F1A\u8BDD",EMPTY_MESSAGE:"\u6D88\u606F\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A",CONTINUE_MODEL_NOT_AVAILABLE:"\u7EED\u5199\u6A21\u578B\u5F53\u524D\u4E0D\u53EF\u7528",CONTINUE_PROMPT_MISSING:"\u7EED\u5199\u914D\u7F6E\u7F3A\u5931",GENERATION_ABORTED:"\u751F\u6210\u5DF2\u505C\u6B62"}},at={common:{unknownError:"\u64CD\u4F5C\u5931\u6557\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",violationWords:"\u5167\u5BB9\u5305\u542B\u4E0D\u7B26\u5408\u793E\u7FA4\u898F\u7BC4\u7684\u7528\u8A5E{words}\uFF0C\u8ACB\u4FEE\u6539\u5F8C\u91CD\u8A66",close:"\u95DC\u9589"},errors:{UNAUTHORIZED:"\u767B\u5165\u5DF2\u5931\u6548\uFF0C\u8ACB\u91CD\u65B0\u767B\u5165",INSUFFICIENT_CREDITS:"\u82B1\u5712\u5E63\u4E0D\u8DB3\uFF0C\u8ACB\u5132\u503C\u5F8C\u518D\u7E7C\u7E8C\u904A\u6232",VIOLATION_WORD_DETECTED:"\u5167\u5BB9\u542B\u6709\u9055\u7981\u8A5E\uFF0C\u8ACB\u4FEE\u6539\u5F8C\u91CD\u8A66",CONTENT_FILTERED:"\u5167\u5BB9\u88AB\u5B89\u5168\u7B56\u7565\u6514\u622A\uFF0C\u8ACB\u8ABF\u6574\u5F8C\u91CD\u8A66",MODEL_REFUSAL:"\u6A21\u578B\u62D2\u7D55\u56DE\u61C9\uFF0C\u63DB\u500B\u8AAA\u6CD5\u8A66\u8A66",STREAM_INTERRUPTED:"\u56DE\u8986\u5DF2\u4E2D\u65B7\uFF0C\u8ACB\u91CD\u8A66",RATE_LIMITED:"\u64CD\u4F5C\u904E\u65BC\u983B\u7E41\uFF0C\u8ACB\u7A0D\u5F8C\u518D\u8A66",GENERATING_IN_PROGRESS:"\u76EE\u524D\u5287\u60C5\u6B63\u5728\u751F\u6210\u4E2D\uFF0C\u8ACB\u7A0D\u5019",CONCURRENT_GENERATION_LIMIT:"\u540C\u6642\u9032\u884C\u7684\u5287\u60C5\u592A\u591A\uFF0C\u8ACB\u7A0D\u5019\u518D\u8A66",INVENTORY_LIMIT:"\u9053\u5177\u6B04\u5DF2\u6EFF\uFF0C\u8ACB\u5148\u6E05\u7406\u518D\u65B0\u589E",CUSTOM_FIELDS_LIMIT:"\u64F4\u5145\u5C6C\u6027\u6B04\u4F4D\u5DF2\u6EFF\uFF0C\u8ACB\u5148\u522A\u9664\u518D\u65B0\u589E",MODEL_NOT_FOUND:"\u6240\u9078\u6A21\u578B\u4E0D\u53EF\u7528\uFF0C\u8ACB\u5207\u63DB\u5176\u4ED6\u6A21\u578B",GAME_NOT_FOUND:"\u627E\u4E0D\u5230\u5C0D\u61C9\u904A\u6232",INVALID_REQUEST:"\u8ACB\u6C42\u7121\u6548\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",INVALID_EXTRACT_RULE:"\u56DE\u8986\u64F7\u53D6\u8A2D\u5B9A\u7121\u6548\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",INTERNAL_ERROR:"\u670D\u52D9\u51FA\u4E86\u9EDE\u5C0F\u554F\u984C\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",NOT_INITIALIZED:"SDK \u5C1A\u672A\u521D\u59CB\u5316",NOT_SUPPORTED_IN_PREVIEW:"\u76EE\u524D\u4ECB\u9762\u5728\u9810\u89BD\u6A21\u5F0F\u4E0B\u4E0D\u53EF\u7528",NETWORK_ERROR:"\u7DB2\u8DEF\u7570\u5E38\uFF0C\u8ACB\u6AA2\u67E5\u9023\u7DDA",REQUEST_TIMEOUT:"\u8ACB\u6C42\u903E\u6642\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",MODEL_LOADING_TIMEOUT:"\u6A21\u578B\u56DE\u61C9\u903E\u6642\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",DAISY_CARD_REQUIRED:"\u56DE\u6EAF\u8A0A\u606F\u9700\u8981\u6709\u6548\u7684\u96DB\u83CA\u5361\u8A02\u95B1",MESSAGE_NOT_FOUND:"\u8A0A\u606F\u4E0D\u5B58\u5728\u6216\u7121\u6B0A\u64CD\u4F5C",MESSAGE_TOO_OLD:"\u50C5\u53EF\u56DE\u6EAF 30 \u5929\u5167\u7684\u8A0A\u606F",NO_MESSAGES_TO_DELETE:"\u8A72\u8A0A\u606F\u4E4B\u5F8C\u6C92\u6709\u53EF\u56DE\u6EAF\u7684\u8A0A\u606F",GENERATION_TIMEOUT:"\u751F\u6210\u903E\u6642\uFF0C\u8ACB\u91CD\u8A66",GENERATION_LOST:"\u751F\u6210\u9023\u7DDA\u4E2D\u65B7\uFF0C\u8ACB\u91CD\u8A66\uFF1B\u82E5\u5167\u5BB9\u5DF2\u751F\u6210\uFF0C\u91CD\u65B0\u6574\u7406\u5F8C\u53EF\u898B",REPETITION_LOOP:"\u56DE\u8986\u51FA\u73FE\u91CD\u8907\uFF0C\u8ACB\u91CD\u8A66\u6216\u63DB\u500B\u8AAA\u6CD5",SAVE_FAILED:"\u8A0A\u606F\u5132\u5B58\u5931\u6557\uFF0C\u672C\u6B21\u4E0D\u6263\u8CBB\uFF0C\u8ACB\u91CD\u8A66",FINALIZE_FAILED:"\u56DE\u8986\u8655\u7406\u5931\u6557\uFF0C\u8ACB\u91CD\u8A66",CONVERSATION_NOT_FOUND:"\u627E\u4E0D\u5230\u5C0D\u61C9\u5C0D\u8A71",EMPTY_MESSAGE:"\u8A0A\u606F\u5167\u5BB9\u4E0D\u80FD\u70BA\u7A7A",CONTINUE_MODEL_NOT_AVAILABLE:"\u7E8C\u5BEB\u6A21\u578B\u76EE\u524D\u4E0D\u53EF\u7528",CONTINUE_PROMPT_MISSING:"\u7E8C\u5BEB\u8A2D\u5B9A\u7F3A\u5931",GENERATION_ABORTED:"\u751F\u6210\u5DF2\u505C\u6B62"}},dt={common:{unknownError:"Something went wrong. Please try again.",violationWords:"Your content contains words that violate our community guidelines{words}. Please revise and try again.",close:"Close"},errors:{UNAUTHORIZED:"Your session has expired. Please sign in again.",INSUFFICIENT_CREDITS:"Not enough Garden Coins. Please top up to continue.",VIOLATION_WORD_DETECTED:"Your content contains prohibited words. Please revise and try again.",CONTENT_FILTERED:"Content was blocked by the safety filter. Please adjust and try again.",MODEL_REFUSAL:"The model declined to respond. Try rephrasing.",STREAM_INTERRUPTED:"The reply was interrupted. Please try again.",RATE_LIMITED:"Too many requests. Please wait a moment.",GENERATING_IN_PROGRESS:"A reply is already being generated. Please wait.",CONCURRENT_GENERATION_LIMIT:"Too many replies generating at once. Please wait.",INVENTORY_LIMIT:"Inventory is full. Remove some items first.",CUSTOM_FIELDS_LIMIT:"Custom field limit reached. Delete some fields first.",MODEL_NOT_FOUND:"That model is unavailable. Please pick another one.",GAME_NOT_FOUND:"Game not found.",INVALID_REQUEST:"Invalid request. Please try again.",INVALID_EXTRACT_RULE:"Invalid reply-extraction rule. Please try again.",INTERNAL_ERROR:"Something went wrong on our end. Please try again.",NOT_INITIALIZED:"The SDK is not initialized yet.",NOT_SUPPORTED_IN_PREVIEW:"This action is unavailable in preview mode.",NETWORK_ERROR:"Network error. Please check your connection.",REQUEST_TIMEOUT:"Request timed out. Please try again.",MODEL_LOADING_TIMEOUT:"The model took too long to respond. Please try again.",DAISY_CARD_REQUIRED:"Rolling back messages requires an active Daisy Card subscription.",MESSAGE_NOT_FOUND:"Message not found, or you do not have access to it.",MESSAGE_TOO_OLD:"You can only roll back messages from the last 30 days.",NO_MESSAGES_TO_DELETE:"There are no messages after this one to roll back.",GENERATION_TIMEOUT:"Generation timed out. Please try again.",GENERATION_LOST:"Lost connection while generating. Try again \u2014 if it finished, refresh to see it.",REPETITION_LOOP:"The reply started repeating itself. Try again or rephrase.",SAVE_FAILED:"Failed to save the message. You were not charged. Please try again.",FINALIZE_FAILED:"Failed to finish processing the reply. Please try again.",CONVERSATION_NOT_FOUND:"Conversation not found.",EMPTY_MESSAGE:"Message cannot be empty.",CONTINUE_MODEL_NOT_AVAILABLE:"The continuation model is currently unavailable.",CONTINUE_PROMPT_MISSING:"Continuation settings are missing.",GENERATION_ABORTED:"Generation stopped."}},ct={common:{unknownError:"\u64CD\u4F5C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",violationWords:"\u30B3\u30DF\u30E5\u30CB\u30C6\u30A3\u30AC\u30A4\u30C9\u30E9\u30A4\u30F3\u306B\u53CD\u3059\u308B\u8A9E\u53E5{words}\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059\u3002\u4FEE\u6B63\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",close:"\u9589\u3058\u308B"},errors:{UNAUTHORIZED:"\u30ED\u30B0\u30A4\u30F3\u306E\u6709\u52B9\u671F\u9650\u304C\u5207\u308C\u307E\u3057\u305F\u3002\u518D\u5EA6\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\u3002",INSUFFICIENT_CREDITS:"\u30AC\u30FC\u30C7\u30F3\u30B3\u30A4\u30F3\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002\u30C1\u30E3\u30FC\u30B8\u3057\u3066\u304B\u3089\u7D9A\u3051\u3066\u304F\u3060\u3055\u3044\u3002",VIOLATION_WORD_DETECTED:"\u7981\u6B62\u8A9E\u53E5\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059\u3002\u4FEE\u6B63\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",CONTENT_FILTERED:"\u5B89\u5168\u30DD\u30EA\u30B7\u30FC\u306B\u3088\u308A\u30D6\u30ED\u30C3\u30AF\u3055\u308C\u307E\u3057\u305F\u3002\u5185\u5BB9\u3092\u8ABF\u6574\u3057\u3066\u304F\u3060\u3055\u3044\u3002",MODEL_REFUSAL:"\u30E2\u30C7\u30EB\u304C\u5FDC\u7B54\u3092\u62D2\u5426\u3057\u307E\u3057\u305F\u3002\u8868\u73FE\u3092\u5909\u3048\u3066\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",STREAM_INTERRUPTED:"\u8FD4\u4FE1\u304C\u4E2D\u65AD\u3055\u308C\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",RATE_LIMITED:"\u64CD\u4F5C\u304C\u983B\u7E41\u3059\u304E\u307E\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",GENERATING_IN_PROGRESS:"\u73FE\u5728\u30B9\u30C8\u30FC\u30EA\u30FC\u3092\u751F\u6210\u4E2D\u3067\u3059\u3002\u304A\u5F85\u3061\u304F\u3060\u3055\u3044\u3002",CONCURRENT_GENERATION_LIMIT:"\u540C\u6642\u306B\u751F\u6210\u4E2D\u306E\u30B9\u30C8\u30FC\u30EA\u30FC\u304C\u591A\u3059\u304E\u307E\u3059\u3002\u304A\u5F85\u3061\u304F\u3060\u3055\u3044\u3002",INVENTORY_LIMIT:"\u6301\u3061\u7269\u304C\u3044\u3063\u3071\u3044\u3067\u3059\u3002\u6574\u7406\u3057\u3066\u304B\u3089\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002",CUSTOM_FIELDS_LIMIT:"\u62E1\u5F35\u5C5E\u6027\u306E\u9805\u76EE\u304C\u4E0A\u9650\u306B\u9054\u3057\u307E\u3057\u305F\u3002\u524A\u9664\u3057\u3066\u304B\u3089\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002",MODEL_NOT_FOUND:"\u9078\u629E\u3057\u305F\u30E2\u30C7\u30EB\u306F\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002\u5225\u306E\u30E2\u30C7\u30EB\u3092\u304A\u9078\u3073\u304F\u3060\u3055\u3044\u3002",GAME_NOT_FOUND:"\u5BFE\u8C61\u306E\u30B2\u30FC\u30E0\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",INVALID_REQUEST:"\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u7121\u52B9\u3067\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",INVALID_EXTRACT_RULE:"\u8FD4\u4FE1\u62BD\u51FA\u306E\u8A2D\u5B9A\u304C\u7121\u52B9\u3067\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",INTERNAL_ERROR:"\u30B5\u30FC\u30D0\u30FC\u5074\u3067\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",NOT_INITIALIZED:"SDK \u304C\u307E\u3060\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002",NOT_SUPPORTED_IN_PREVIEW:"\u3053\u306E\u6A5F\u80FD\u306F\u30D7\u30EC\u30D3\u30E5\u30FC\u30E2\u30FC\u30C9\u3067\u306F\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002",NETWORK_ERROR:"\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC\u3067\u3059\u3002\u63A5\u7D9A\u3092\u3054\u78BA\u8A8D\u304F\u3060\u3055\u3044\u3002",REQUEST_TIMEOUT:"\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",MODEL_LOADING_TIMEOUT:"\u30E2\u30C7\u30EB\u306E\u5FDC\u7B54\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",DAISY_CARD_REQUIRED:"\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u306B\u306F\u30C7\u30A4\u30B8\u30FC\u30AB\u30FC\u30C9\u306E\u6709\u52B9\u306A\u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u304C\u5FC5\u8981\u3067\u3059\u3002",MESSAGE_NOT_FOUND:"\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u5B58\u5728\u3057\u306A\u3044\u304B\u3001\u64CD\u4F5C\u3059\u308B\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093\u3002",MESSAGE_TOO_OLD:"\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u3067\u304D\u308B\u306E\u306F 30 \u65E5\u4EE5\u5185\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u307F\u3067\u3059\u3002",NO_MESSAGES_TO_DELETE:"\u3053\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u3088\u308A\u5F8C\u306B\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u3067\u304D\u308B\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u3042\u308A\u307E\u305B\u3093\u3002",GENERATION_TIMEOUT:"\u751F\u6210\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",GENERATION_LOST:"\u751F\u6210\u4E2D\u306B\u63A5\u7D9A\u304C\u5207\u308C\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002\u751F\u6210\u6E08\u307F\u306E\u5834\u5408\u306F\u518D\u8AAD\u307F\u8FBC\u307F\u3067\u8868\u793A\u3055\u308C\u307E\u3059\u3002",REPETITION_LOOP:"\u8FD4\u4FE1\u304C\u7E70\u308A\u8FD4\u3057\u306B\u306A\u308A\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u3044\u305F\u3060\u304F\u304B\u3001\u8868\u73FE\u3092\u5909\u3048\u3066\u304F\u3060\u3055\u3044\u3002",SAVE_FAILED:"\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u4FDD\u5B58\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u4ECA\u56DE\u306F\u8AB2\u91D1\u3055\u308C\u307E\u305B\u3093\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",FINALIZE_FAILED:"\u8FD4\u4FE1\u306E\u51E6\u7406\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",CONVERSATION_NOT_FOUND:"\u5BFE\u8C61\u306E\u4F1A\u8A71\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",EMPTY_MESSAGE:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u3002",CONTINUE_MODEL_NOT_AVAILABLE:"\u7D9A\u304D\u3092\u66F8\u304F\u30E2\u30C7\u30EB\u304C\u73FE\u5728\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002",CONTINUE_PROMPT_MISSING:"\u7D9A\u304D\u3092\u66F8\u304F\u8A2D\u5B9A\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",GENERATION_ABORTED:"\u751F\u6210\u3092\u505C\u6B62\u3057\u307E\u3057\u305F\u3002"}},lt={common:{unknownError:"\uC791\uC5C5\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",violationWords:"\uCEE4\uBBA4\uB2C8\uD2F0 \uADDC\uC815\uC5D0 \uC5B4\uAE0B\uB098\uB294 \uB2E8\uC5B4{words}\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4. \uC218\uC815 \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",close:"\uB2EB\uAE30"},errors:{UNAUTHORIZED:"\uB85C\uADF8\uC778\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uB85C\uADF8\uC778\uD574 \uC8FC\uC138\uC694.",INSUFFICIENT_CREDITS:"\uAC00\uB4E0 \uCF54\uC778\uC774 \uBD80\uC871\uD569\uB2C8\uB2E4. \uCDA9\uC804 \uD6C4 \uACC4\uC18D\uD574 \uC8FC\uC138\uC694.",VIOLATION_WORD_DETECTED:"\uAE08\uC9C0\uB41C \uB2E8\uC5B4\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4. \uC218\uC815 \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",CONTENT_FILTERED:"\uC548\uC804 \uC815\uCC45\uC5D0 \uC758\uD574 \uCC28\uB2E8\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB0B4\uC6A9\uC744 \uC218\uC815\uD574 \uC8FC\uC138\uC694.",MODEL_REFUSAL:"\uBAA8\uB378\uC774 \uC751\uB2F5\uC744 \uAC70\uBD80\uD588\uC2B5\uB2C8\uB2E4. \uB2E4\uB974\uAC8C \uD45C\uD604\uD574 \uBCF4\uC138\uC694.",STREAM_INTERRUPTED:"\uC751\uB2F5\uC774 \uC911\uB2E8\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",RATE_LIMITED:"\uC694\uCCAD\uC774 \uB108\uBB34 \uC7A6\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",GENERATING_IN_PROGRESS:"\uD604\uC7AC \uC2A4\uD1A0\uB9AC\uB97C \uC0DD\uC131 \uC911\uC785\uB2C8\uB2E4. \uC7A0\uC2DC\uB9CC \uAE30\uB2E4\uB824 \uC8FC\uC138\uC694.",CONCURRENT_GENERATION_LIMIT:"\uB3D9\uC2DC\uC5D0 \uC0DD\uC131 \uC911\uC778 \uC2A4\uD1A0\uB9AC\uAC00 \uB108\uBB34 \uB9CE\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INVENTORY_LIMIT:"\uC18C\uC9C0\uD488\uC774 \uAC00\uB4DD \uCC3C\uC2B5\uB2C8\uB2E4. \uC815\uB9AC \uD6C4 \uCD94\uAC00\uD574 \uC8FC\uC138\uC694.",CUSTOM_FIELDS_LIMIT:"\uD655\uC7A5 \uC18D\uC131 \uD56D\uBAA9\uC774 \uAC00\uB4DD \uCC3C\uC2B5\uB2C8\uB2E4. \uC0AD\uC81C \uD6C4 \uCD94\uAC00\uD574 \uC8FC\uC138\uC694.",MODEL_NOT_FOUND:"\uC120\uD0DD\uD55C \uBAA8\uB378\uC744 \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. \uB2E4\uB978 \uBAA8\uB378\uC744 \uC120\uD0DD\uD574 \uC8FC\uC138\uC694.",GAME_NOT_FOUND:"\uD574\uB2F9 \uAC8C\uC784\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",INVALID_REQUEST:"\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INVALID_EXTRACT_RULE:"\uC751\uB2F5 \uCD94\uCD9C \uC124\uC815\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INTERNAL_ERROR:"\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",NOT_INITIALIZED:"SDK\uAC00 \uC544\uC9C1 \uCD08\uAE30\uD654\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.",NOT_SUPPORTED_IN_PREVIEW:"\uC774 \uAE30\uB2A5\uC740 \uBBF8\uB9AC\uBCF4\uAE30 \uBAA8\uB4DC\uC5D0\uC11C \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",NETWORK_ERROR:"\uB124\uD2B8\uC6CC\uD06C \uC624\uB958\uC785\uB2C8\uB2E4. \uC5F0\uACB0\uC744 \uD655\uC778\uD574 \uC8FC\uC138\uC694.",REQUEST_TIMEOUT:"\uC694\uCCAD \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",MODEL_LOADING_TIMEOUT:"\uBAA8\uB378 \uC751\uB2F5 \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",DAISY_CARD_REQUIRED:"\uBA54\uC2DC\uC9C0 \uB418\uB3CC\uB9AC\uAE30\uB294 \uB370\uC774\uC9C0 \uCE74\uB4DC \uAD6C\uB3C5\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.",MESSAGE_NOT_FOUND:"\uBA54\uC2DC\uC9C0\uAC00 \uC5C6\uAC70\uB098 \uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.",MESSAGE_TOO_OLD:"30\uC77C \uC774\uB0B4\uC758 \uBA54\uC2DC\uC9C0\uB9CC \uB418\uB3CC\uB9B4 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",NO_MESSAGES_TO_DELETE:"\uC774 \uBA54\uC2DC\uC9C0 \uC774\uD6C4\uC5D0 \uB418\uB3CC\uB9B4 \uBA54\uC2DC\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.",GENERATION_TIMEOUT:"\uC0DD\uC131 \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",GENERATION_LOST:"\uC0DD\uC131 \uC911 \uC5F0\uACB0\uC774 \uB04A\uACBC\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694. \uC774\uBBF8 \uC0DD\uC131\uB418\uC5C8\uB2E4\uBA74 \uC0C8\uB85C\uACE0\uCE68\uD558\uBA74 \uBCF4\uC785\uB2C8\uB2E4.",REPETITION_LOOP:"\uC751\uB2F5\uC774 \uBC18\uBCF5\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD558\uAC70\uB098 \uB2E4\uB974\uAC8C \uD45C\uD604\uD574 \uC8FC\uC138\uC694.",SAVE_FAILED:"\uBA54\uC2DC\uC9C0 \uC800\uC7A5\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uC774\uBC88\uC5D0\uB294 \uCC28\uAC10\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",FINALIZE_FAILED:"\uC751\uB2F5 \uCC98\uB9AC\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",CONVERSATION_NOT_FOUND:"\uD574\uB2F9 \uB300\uD654\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",EMPTY_MESSAGE:"\uBA54\uC2DC\uC9C0\uB97C \uC785\uB825\uD574 \uC8FC\uC138\uC694.",CONTINUE_MODEL_NOT_AVAILABLE:"\uC774\uC5B4\uC4F0\uAE30 \uBAA8\uB378\uC744 \uD604\uC7AC \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",CONTINUE_PROMPT_MISSING:"\uC774\uC5B4\uC4F0\uAE30 \uC124\uC815\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.",GENERATION_ABORTED:"\uC0DD\uC131\uC744 \uC911\uC9C0\uD588\uC2B5\uB2C8\uB2E4."}},be={zh:st,"zh-Hant":at,en:dt,ja:ct,ko:lt},se="zh";function Ne(o){if(!o)return null;let e=o.trim();if(!e)return null;if(it.includes(e))return e;let t=e.toLowerCase();return t.startsWith("zh")?/hant|tw|hk|mo/.test(t)?"zh-Hant":"zh":t.startsWith("ja")?"ja":t.startsWith("ko")?"ko":t.startsWith("en")?"en":null}function Ae(o){let e=Ne(o);e&&(se=e)}function ke(){if(typeof navigator>"u")return;let o=Ne(navigator.language);o&&(se=o)}function De(o){return be[se].errors[o]}function ae(o){return be[se].common[o]}var ue=null;function Le(o){ue=o}var Me="storvia-sdk-toast-style",de="storvia-sdk-toast-stack",ht=`
1
+ "use strict";var he=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var nt=(o,e)=>{for(var t in e)he(o,t,{get:e[t],enumerable:!0})},rt=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of et(e))!tt.call(o,r)&&r!==t&&he(o,r,{get:()=>e[r],enumerable:!(n=Je(e,r))||n.enumerable});return o};var ot=o=>rt(he({},"__esModule",{value:!0}),o);var St={};nt(St,{HOST_NOTIFY_MAX_LENGTH:()=>Ie,HOST_NOTIFY_MIN_INTERVAL_MS:()=>Ee,HOST_PANEL_SCOPES:()=>ue,HOST_REFRESH_MIN_INTERVAL_MS:()=>ce,HostModule:()=>A,MAIN_CHAT_TOPIC:()=>We,PROTOCOL_VERSION:()=>$,StorviaBus:()=>x,StorviaError:()=>g,StorviaSDK:()=>ne,createStorviaSDK:()=>Ze,envelope:()=>T,extractFieldValue:()=>Xe,isProtocolEnvelope:()=>J,isRichFieldValue:()=>ye,setToastEnabled:()=>Ge,showToast:()=>ee});module.exports=ot(St);var g=class extends Error{constructor(e,t,n){super(t),this.name="StorviaError",this.code=e,n?.length&&(this.matchedWords=n)}};var $=1,ue=["player","characters","inventory","relations","world"];function J(o){if(!o||typeof o!="object")return!1;let e=o;return typeof e.protocol=="number"&&typeof e.type=="string"&&"payload"in e}function T(o,e,t){return{protocol:1,type:o,payload:e,...t?.id?{id:t.id}:{},...t?.ackId?{ackId:t.ackId}:{}}}var x=class{constructor(e){this.handlers=new Map;this.pendingAcks=new Map;this.listener=null;this.incoming=e.incoming,this.getOutgoing=e.outgoing,this.verifySource=e.verifySource??(()=>!0),this.validate=e.validate,this.debug=!!e.debug,this.getTransferables=e.transfer??(()=>{}),this.customSend=e.customSend,this.attach()}attach(){this.listener=e=>{if((this.incoming instanceof Window||this.incoming===window)&&!this.verifySource(e))return;let t=e.data;if(!J(t))return;if(t.protocol!==1){this.debug&&console.warn("[StorviaBus] protocol mismatch",{expected:1,got:t.protocol,type:t.type});return}if(this.validate&&!this.validate(t)){this.debug&&console.warn("[StorviaBus] validation failed",t);return}if(t.ackId){let r=this.pendingAcks.get(t.ackId);if(r){this.pendingAcks.delete(t.ackId),r(t);return}}let n=this.handlers.get(t.type);if(!n||n.size===0){this.debug&&console.debug("[StorviaBus] no handler for",t.type);return}n.forEach(r=>{try{r(t)}catch(i){console.error(`[StorviaBus] handler '${t.type}' threw:`,i)}})},this.incoming.addEventListener("message",this.listener),this.incoming instanceof MessagePort&&this.incoming.start()}on(e,t){let n=this.handlers.get(e);n||(n=new Set,this.handlers.set(e,n));let r=t;return n.add(r),()=>n.delete(r)}send(e){let t=e.protocol?e:T(e.type,e.payload,{id:e.id,ackId:e.ackId});if(this.customSend){try{this.customSend(t)}catch(i){console.error("[StorviaBus] customSend failed:",i,{type:e.type})}return}let n=this.getOutgoing();if(!n){this.debug&&console.warn("[StorviaBus] outgoing target unavailable, drop:",e.type);return}let r=this.getTransferables(t);try{n instanceof MessagePort?n.postMessage(t,r??[]):n.postMessage(t,"*",r??[])}catch(i){console.error("[StorviaBus] postMessage failed:",i,{type:e.type})}}request(e,t=1e4){return new Promise((n,r)=>{let i=e.id??it(),s=T(e.type,e.payload,{id:i}),d=setTimeout(()=>{this.pendingAcks.delete(i),r(new Error(`[StorviaBus] request '${e.type}' timed out after ${t}ms`))},t);this.pendingAcks.set(i,c=>{clearTimeout(d),n(c)}),this.send(s)})}destroy(){if(this.listener&&(this.incoming.removeEventListener("message",this.listener),this.listener=null),this.incoming instanceof MessagePort)try{this.incoming.close()}catch{}this.handlers.clear(),this.pendingAcks.clear()}};function it(){return`bus-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var st=["zh","zh-Hant","en","ja","ko"];var at={common:{unknownError:"\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",violationWords:"\u5185\u5BB9\u5305\u542B\u4E0D\u7B26\u5408\u793E\u533A\u89C4\u8303\u7684\u7528\u8BCD{words}\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5",close:"\u5173\u95ED"},errors:{UNAUTHORIZED:"\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",INSUFFICIENT_CREDITS:"\u82B1\u56ED\u5E01\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u7EE7\u7EED\u6E38\u620F",VIOLATION_WORD_DETECTED:"\u5185\u5BB9\u542B\u6709\u8FDD\u7981\u8BCD\uFF0C\u8BF7\u4FEE\u6539\u540E\u91CD\u8BD5",CONTENT_FILTERED:"\u5185\u5BB9\u88AB\u5B89\u5168\u7B56\u7565\u62E6\u622A\uFF0C\u8BF7\u8C03\u6574\u540E\u91CD\u8BD5",MODEL_REFUSAL:"\u6A21\u578B\u62D2\u7EDD\u54CD\u5E94\uFF0C\u6362\u4E2A\u8BF4\u6CD5\u8BD5\u8BD5",STREAM_INTERRUPTED:"\u56DE\u590D\u5DF2\u4E2D\u65AD\uFF0C\u8BF7\u91CD\u8BD5",RATE_LIMITED:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",GENERATING_IN_PROGRESS:"\u5F53\u524D\u5267\u60C5\u6B63\u5728\u751F\u6210\u4E2D\uFF0C\u8BF7\u7A0D\u5019",CONCURRENT_GENERATION_LIMIT:"\u540C\u65F6\u8FDB\u884C\u7684\u5267\u60C5\u592A\u591A\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5",INVENTORY_LIMIT:"\u7269\u54C1\u680F\u5DF2\u6EE1\uFF0C\u8BF7\u5148\u6E05\u7406\u518D\u6DFB\u52A0",CUSTOM_FIELDS_LIMIT:"\u6269\u5C55\u5C5E\u6027\u5B57\u6BB5\u5DF2\u6EE1\uFF0C\u8BF7\u5148\u5220\u9664\u518D\u6DFB\u52A0",MODEL_NOT_FOUND:"\u6240\u9009\u6A21\u578B\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5207\u6362\u5176\u4ED6\u6A21\u578B",GAME_NOT_FOUND:"\u672A\u627E\u5230\u5BF9\u5E94\u6E38\u620F",INVALID_REQUEST:"\u8BF7\u6C42\u65E0\u6548\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",INVALID_EXTRACT_RULE:"\u56DE\u590D\u63D0\u53D6\u914D\u7F6E\u65E0\u6548\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",INTERNAL_ERROR:"\u670D\u52A1\u51FA\u4E86\u70B9\u5C0F\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",NOT_INITIALIZED:"SDK \u5C1A\u672A\u521D\u59CB\u5316",NOT_SUPPORTED_IN_PREVIEW:"\u5F53\u524D\u63A5\u53E3\u5728\u9884\u89C8\u6A21\u5F0F\u4E0B\u4E0D\u53EF\u7528",NETWORK_ERROR:"\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u8FDE\u63A5",REQUEST_TIMEOUT:"\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",MODEL_LOADING_TIMEOUT:"\u6A21\u578B\u54CD\u5E94\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",DAISY_CARD_REQUIRED:"\u56DE\u6EAF\u6D88\u606F\u9700\u8981\u6709\u6548\u7684\u96CF\u83CA\u5361\u8BA2\u9605",MESSAGE_NOT_FOUND:"\u6D88\u606F\u4E0D\u5B58\u5728\u6216\u65E0\u6743\u64CD\u4F5C",MESSAGE_TOO_OLD:"\u4EC5\u53EF\u56DE\u6EAF 30 \u5929\u5185\u7684\u6D88\u606F",NO_MESSAGES_TO_DELETE:"\u8BE5\u6D88\u606F\u4E4B\u540E\u6CA1\u6709\u53EF\u56DE\u6EAF\u7684\u6D88\u606F",GENERATION_TIMEOUT:"\u751F\u6210\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5",GENERATION_LOST:"\u751F\u6210\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u82E5\u5185\u5BB9\u5DF2\u751F\u6210\uFF0C\u5237\u65B0\u540E\u53EF\u89C1",REPETITION_LOOP:"\u56DE\u590D\u51FA\u73B0\u91CD\u590D\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u4E2A\u8BF4\u6CD5",SAVE_FAILED:"\u6D88\u606F\u4FDD\u5B58\u5931\u8D25\uFF0C\u672C\u6B21\u4E0D\u6263\u8D39\uFF0C\u8BF7\u91CD\u8BD5",FINALIZE_FAILED:"\u56DE\u590D\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",CONVERSATION_NOT_FOUND:"\u672A\u627E\u5230\u5BF9\u5E94\u4F1A\u8BDD",EMPTY_MESSAGE:"\u6D88\u606F\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A",CONTINUE_MODEL_NOT_AVAILABLE:"\u7EED\u5199\u6A21\u578B\u5F53\u524D\u4E0D\u53EF\u7528",CONTINUE_PROMPT_MISSING:"\u7EED\u5199\u914D\u7F6E\u7F3A\u5931",GENERATION_ABORTED:"\u751F\u6210\u5DF2\u505C\u6B62"}},dt={common:{unknownError:"\u64CD\u4F5C\u5931\u6557\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",violationWords:"\u5167\u5BB9\u5305\u542B\u4E0D\u7B26\u5408\u793E\u7FA4\u898F\u7BC4\u7684\u7528\u8A5E{words}\uFF0C\u8ACB\u4FEE\u6539\u5F8C\u91CD\u8A66",close:"\u95DC\u9589"},errors:{UNAUTHORIZED:"\u767B\u5165\u5DF2\u5931\u6548\uFF0C\u8ACB\u91CD\u65B0\u767B\u5165",INSUFFICIENT_CREDITS:"\u82B1\u5712\u5E63\u4E0D\u8DB3\uFF0C\u8ACB\u5132\u503C\u5F8C\u518D\u7E7C\u7E8C\u904A\u6232",VIOLATION_WORD_DETECTED:"\u5167\u5BB9\u542B\u6709\u9055\u7981\u8A5E\uFF0C\u8ACB\u4FEE\u6539\u5F8C\u91CD\u8A66",CONTENT_FILTERED:"\u5167\u5BB9\u88AB\u5B89\u5168\u7B56\u7565\u6514\u622A\uFF0C\u8ACB\u8ABF\u6574\u5F8C\u91CD\u8A66",MODEL_REFUSAL:"\u6A21\u578B\u62D2\u7D55\u56DE\u61C9\uFF0C\u63DB\u500B\u8AAA\u6CD5\u8A66\u8A66",STREAM_INTERRUPTED:"\u56DE\u8986\u5DF2\u4E2D\u65B7\uFF0C\u8ACB\u91CD\u8A66",RATE_LIMITED:"\u64CD\u4F5C\u904E\u65BC\u983B\u7E41\uFF0C\u8ACB\u7A0D\u5F8C\u518D\u8A66",GENERATING_IN_PROGRESS:"\u76EE\u524D\u5287\u60C5\u6B63\u5728\u751F\u6210\u4E2D\uFF0C\u8ACB\u7A0D\u5019",CONCURRENT_GENERATION_LIMIT:"\u540C\u6642\u9032\u884C\u7684\u5287\u60C5\u592A\u591A\uFF0C\u8ACB\u7A0D\u5019\u518D\u8A66",INVENTORY_LIMIT:"\u9053\u5177\u6B04\u5DF2\u6EFF\uFF0C\u8ACB\u5148\u6E05\u7406\u518D\u65B0\u589E",CUSTOM_FIELDS_LIMIT:"\u64F4\u5145\u5C6C\u6027\u6B04\u4F4D\u5DF2\u6EFF\uFF0C\u8ACB\u5148\u522A\u9664\u518D\u65B0\u589E",MODEL_NOT_FOUND:"\u6240\u9078\u6A21\u578B\u4E0D\u53EF\u7528\uFF0C\u8ACB\u5207\u63DB\u5176\u4ED6\u6A21\u578B",GAME_NOT_FOUND:"\u627E\u4E0D\u5230\u5C0D\u61C9\u904A\u6232",INVALID_REQUEST:"\u8ACB\u6C42\u7121\u6548\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",INVALID_EXTRACT_RULE:"\u56DE\u8986\u64F7\u53D6\u8A2D\u5B9A\u7121\u6548\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",INTERNAL_ERROR:"\u670D\u52D9\u51FA\u4E86\u9EDE\u5C0F\u554F\u984C\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",NOT_INITIALIZED:"SDK \u5C1A\u672A\u521D\u59CB\u5316",NOT_SUPPORTED_IN_PREVIEW:"\u76EE\u524D\u4ECB\u9762\u5728\u9810\u89BD\u6A21\u5F0F\u4E0B\u4E0D\u53EF\u7528",NETWORK_ERROR:"\u7DB2\u8DEF\u7570\u5E38\uFF0C\u8ACB\u6AA2\u67E5\u9023\u7DDA",REQUEST_TIMEOUT:"\u8ACB\u6C42\u903E\u6642\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",MODEL_LOADING_TIMEOUT:"\u6A21\u578B\u56DE\u61C9\u903E\u6642\uFF0C\u8ACB\u7A0D\u5F8C\u91CD\u8A66",DAISY_CARD_REQUIRED:"\u56DE\u6EAF\u8A0A\u606F\u9700\u8981\u6709\u6548\u7684\u96DB\u83CA\u5361\u8A02\u95B1",MESSAGE_NOT_FOUND:"\u8A0A\u606F\u4E0D\u5B58\u5728\u6216\u7121\u6B0A\u64CD\u4F5C",MESSAGE_TOO_OLD:"\u50C5\u53EF\u56DE\u6EAF 30 \u5929\u5167\u7684\u8A0A\u606F",NO_MESSAGES_TO_DELETE:"\u8A72\u8A0A\u606F\u4E4B\u5F8C\u6C92\u6709\u53EF\u56DE\u6EAF\u7684\u8A0A\u606F",GENERATION_TIMEOUT:"\u751F\u6210\u903E\u6642\uFF0C\u8ACB\u91CD\u8A66",GENERATION_LOST:"\u751F\u6210\u9023\u7DDA\u4E2D\u65B7\uFF0C\u8ACB\u91CD\u8A66\uFF1B\u82E5\u5167\u5BB9\u5DF2\u751F\u6210\uFF0C\u91CD\u65B0\u6574\u7406\u5F8C\u53EF\u898B",REPETITION_LOOP:"\u56DE\u8986\u51FA\u73FE\u91CD\u8907\uFF0C\u8ACB\u91CD\u8A66\u6216\u63DB\u500B\u8AAA\u6CD5",SAVE_FAILED:"\u8A0A\u606F\u5132\u5B58\u5931\u6557\uFF0C\u672C\u6B21\u4E0D\u6263\u8CBB\uFF0C\u8ACB\u91CD\u8A66",FINALIZE_FAILED:"\u56DE\u8986\u8655\u7406\u5931\u6557\uFF0C\u8ACB\u91CD\u8A66",CONVERSATION_NOT_FOUND:"\u627E\u4E0D\u5230\u5C0D\u61C9\u5C0D\u8A71",EMPTY_MESSAGE:"\u8A0A\u606F\u5167\u5BB9\u4E0D\u80FD\u70BA\u7A7A",CONTINUE_MODEL_NOT_AVAILABLE:"\u7E8C\u5BEB\u6A21\u578B\u76EE\u524D\u4E0D\u53EF\u7528",CONTINUE_PROMPT_MISSING:"\u7E8C\u5BEB\u8A2D\u5B9A\u7F3A\u5931",GENERATION_ABORTED:"\u751F\u6210\u5DF2\u505C\u6B62"}},ct={common:{unknownError:"Something went wrong. Please try again.",violationWords:"Your content contains words that violate our community guidelines{words}. Please revise and try again.",close:"Close"},errors:{UNAUTHORIZED:"Your session has expired. Please sign in again.",INSUFFICIENT_CREDITS:"Not enough Garden Coins. Please top up to continue.",VIOLATION_WORD_DETECTED:"Your content contains prohibited words. Please revise and try again.",CONTENT_FILTERED:"Content was blocked by the safety filter. Please adjust and try again.",MODEL_REFUSAL:"The model declined to respond. Try rephrasing.",STREAM_INTERRUPTED:"The reply was interrupted. Please try again.",RATE_LIMITED:"Too many requests. Please wait a moment.",GENERATING_IN_PROGRESS:"A reply is already being generated. Please wait.",CONCURRENT_GENERATION_LIMIT:"Too many replies generating at once. Please wait.",INVENTORY_LIMIT:"Inventory is full. Remove some items first.",CUSTOM_FIELDS_LIMIT:"Custom field limit reached. Delete some fields first.",MODEL_NOT_FOUND:"That model is unavailable. Please pick another one.",GAME_NOT_FOUND:"Game not found.",INVALID_REQUEST:"Invalid request. Please try again.",INVALID_EXTRACT_RULE:"Invalid reply-extraction rule. Please try again.",INTERNAL_ERROR:"Something went wrong on our end. Please try again.",NOT_INITIALIZED:"The SDK is not initialized yet.",NOT_SUPPORTED_IN_PREVIEW:"This action is unavailable in preview mode.",NETWORK_ERROR:"Network error. Please check your connection.",REQUEST_TIMEOUT:"Request timed out. Please try again.",MODEL_LOADING_TIMEOUT:"The model took too long to respond. Please try again.",DAISY_CARD_REQUIRED:"Rolling back messages requires an active Daisy Card subscription.",MESSAGE_NOT_FOUND:"Message not found, or you do not have access to it.",MESSAGE_TOO_OLD:"You can only roll back messages from the last 30 days.",NO_MESSAGES_TO_DELETE:"There are no messages after this one to roll back.",GENERATION_TIMEOUT:"Generation timed out. Please try again.",GENERATION_LOST:"Lost connection while generating. Try again \u2014 if it finished, refresh to see it.",REPETITION_LOOP:"The reply started repeating itself. Try again or rephrase.",SAVE_FAILED:"Failed to save the message. You were not charged. Please try again.",FINALIZE_FAILED:"Failed to finish processing the reply. Please try again.",CONVERSATION_NOT_FOUND:"Conversation not found.",EMPTY_MESSAGE:"Message cannot be empty.",CONTINUE_MODEL_NOT_AVAILABLE:"The continuation model is currently unavailable.",CONTINUE_PROMPT_MISSING:"Continuation settings are missing.",GENERATION_ABORTED:"Generation stopped."}},lt={common:{unknownError:"\u64CD\u4F5C\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",violationWords:"\u30B3\u30DF\u30E5\u30CB\u30C6\u30A3\u30AC\u30A4\u30C9\u30E9\u30A4\u30F3\u306B\u53CD\u3059\u308B\u8A9E\u53E5{words}\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059\u3002\u4FEE\u6B63\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",close:"\u9589\u3058\u308B"},errors:{UNAUTHORIZED:"\u30ED\u30B0\u30A4\u30F3\u306E\u6709\u52B9\u671F\u9650\u304C\u5207\u308C\u307E\u3057\u305F\u3002\u518D\u5EA6\u30ED\u30B0\u30A4\u30F3\u3057\u3066\u304F\u3060\u3055\u3044\u3002",INSUFFICIENT_CREDITS:"\u30AC\u30FC\u30C7\u30F3\u30B3\u30A4\u30F3\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002\u30C1\u30E3\u30FC\u30B8\u3057\u3066\u304B\u3089\u7D9A\u3051\u3066\u304F\u3060\u3055\u3044\u3002",VIOLATION_WORD_DETECTED:"\u7981\u6B62\u8A9E\u53E5\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059\u3002\u4FEE\u6B63\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",CONTENT_FILTERED:"\u5B89\u5168\u30DD\u30EA\u30B7\u30FC\u306B\u3088\u308A\u30D6\u30ED\u30C3\u30AF\u3055\u308C\u307E\u3057\u305F\u3002\u5185\u5BB9\u3092\u8ABF\u6574\u3057\u3066\u304F\u3060\u3055\u3044\u3002",MODEL_REFUSAL:"\u30E2\u30C7\u30EB\u304C\u5FDC\u7B54\u3092\u62D2\u5426\u3057\u307E\u3057\u305F\u3002\u8868\u73FE\u3092\u5909\u3048\u3066\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",STREAM_INTERRUPTED:"\u8FD4\u4FE1\u304C\u4E2D\u65AD\u3055\u308C\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",RATE_LIMITED:"\u64CD\u4F5C\u304C\u983B\u7E41\u3059\u304E\u307E\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",GENERATING_IN_PROGRESS:"\u73FE\u5728\u30B9\u30C8\u30FC\u30EA\u30FC\u3092\u751F\u6210\u4E2D\u3067\u3059\u3002\u304A\u5F85\u3061\u304F\u3060\u3055\u3044\u3002",CONCURRENT_GENERATION_LIMIT:"\u540C\u6642\u306B\u751F\u6210\u4E2D\u306E\u30B9\u30C8\u30FC\u30EA\u30FC\u304C\u591A\u3059\u304E\u307E\u3059\u3002\u304A\u5F85\u3061\u304F\u3060\u3055\u3044\u3002",INVENTORY_LIMIT:"\u6301\u3061\u7269\u304C\u3044\u3063\u3071\u3044\u3067\u3059\u3002\u6574\u7406\u3057\u3066\u304B\u3089\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002",CUSTOM_FIELDS_LIMIT:"\u62E1\u5F35\u5C5E\u6027\u306E\u9805\u76EE\u304C\u4E0A\u9650\u306B\u9054\u3057\u307E\u3057\u305F\u3002\u524A\u9664\u3057\u3066\u304B\u3089\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002",MODEL_NOT_FOUND:"\u9078\u629E\u3057\u305F\u30E2\u30C7\u30EB\u306F\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002\u5225\u306E\u30E2\u30C7\u30EB\u3092\u304A\u9078\u3073\u304F\u3060\u3055\u3044\u3002",GAME_NOT_FOUND:"\u5BFE\u8C61\u306E\u30B2\u30FC\u30E0\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",INVALID_REQUEST:"\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u7121\u52B9\u3067\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",INVALID_EXTRACT_RULE:"\u8FD4\u4FE1\u62BD\u51FA\u306E\u8A2D\u5B9A\u304C\u7121\u52B9\u3067\u3059\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",INTERNAL_ERROR:"\u30B5\u30FC\u30D0\u30FC\u5074\u3067\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u3057\u3070\u3089\u304F\u3057\u3066\u304B\u3089\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",NOT_INITIALIZED:"SDK \u304C\u307E\u3060\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002",NOT_SUPPORTED_IN_PREVIEW:"\u3053\u306E\u6A5F\u80FD\u306F\u30D7\u30EC\u30D3\u30E5\u30FC\u30E2\u30FC\u30C9\u3067\u306F\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002",NETWORK_ERROR:"\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC\u3067\u3059\u3002\u63A5\u7D9A\u3092\u3054\u78BA\u8A8D\u304F\u3060\u3055\u3044\u3002",REQUEST_TIMEOUT:"\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",MODEL_LOADING_TIMEOUT:"\u30E2\u30C7\u30EB\u306E\u5FDC\u7B54\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",DAISY_CARD_REQUIRED:"\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u306B\u306F\u30C7\u30A4\u30B8\u30FC\u30AB\u30FC\u30C9\u306E\u6709\u52B9\u306A\u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u304C\u5FC5\u8981\u3067\u3059\u3002",MESSAGE_NOT_FOUND:"\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u5B58\u5728\u3057\u306A\u3044\u304B\u3001\u64CD\u4F5C\u3059\u308B\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093\u3002",MESSAGE_TOO_OLD:"\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u3067\u304D\u308B\u306E\u306F 30 \u65E5\u4EE5\u5185\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u307F\u3067\u3059\u3002",NO_MESSAGES_TO_DELETE:"\u3053\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u3088\u308A\u5F8C\u306B\u30ED\u30FC\u30EB\u30D0\u30C3\u30AF\u3067\u304D\u308B\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u3042\u308A\u307E\u305B\u3093\u3002",GENERATION_TIMEOUT:"\u751F\u6210\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",GENERATION_LOST:"\u751F\u6210\u4E2D\u306B\u63A5\u7D9A\u304C\u5207\u308C\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002\u751F\u6210\u6E08\u307F\u306E\u5834\u5408\u306F\u518D\u8AAD\u307F\u8FBC\u307F\u3067\u8868\u793A\u3055\u308C\u307E\u3059\u3002",REPETITION_LOOP:"\u8FD4\u4FE1\u304C\u7E70\u308A\u8FD4\u3057\u306B\u306A\u308A\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u3044\u305F\u3060\u304F\u304B\u3001\u8868\u73FE\u3092\u5909\u3048\u3066\u304F\u3060\u3055\u3044\u3002",SAVE_FAILED:"\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u4FDD\u5B58\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u4ECA\u56DE\u306F\u8AB2\u91D1\u3055\u308C\u307E\u305B\u3093\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",FINALIZE_FAILED:"\u8FD4\u4FE1\u306E\u51E6\u7406\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",CONVERSATION_NOT_FOUND:"\u5BFE\u8C61\u306E\u4F1A\u8A71\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",EMPTY_MESSAGE:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u3002",CONTINUE_MODEL_NOT_AVAILABLE:"\u7D9A\u304D\u3092\u66F8\u304F\u30E2\u30C7\u30EB\u304C\u73FE\u5728\u5229\u7528\u3067\u304D\u307E\u305B\u3093\u3002",CONTINUE_PROMPT_MISSING:"\u7D9A\u304D\u3092\u66F8\u304F\u8A2D\u5B9A\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002",GENERATION_ABORTED:"\u751F\u6210\u3092\u505C\u6B62\u3057\u307E\u3057\u305F\u3002"}},ht={common:{unknownError:"\uC791\uC5C5\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",violationWords:"\uCEE4\uBBA4\uB2C8\uD2F0 \uADDC\uC815\uC5D0 \uC5B4\uAE0B\uB098\uB294 \uB2E8\uC5B4{words}\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4. \uC218\uC815 \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",close:"\uB2EB\uAE30"},errors:{UNAUTHORIZED:"\uB85C\uADF8\uC778\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uB85C\uADF8\uC778\uD574 \uC8FC\uC138\uC694.",INSUFFICIENT_CREDITS:"\uAC00\uB4E0 \uCF54\uC778\uC774 \uBD80\uC871\uD569\uB2C8\uB2E4. \uCDA9\uC804 \uD6C4 \uACC4\uC18D\uD574 \uC8FC\uC138\uC694.",VIOLATION_WORD_DETECTED:"\uAE08\uC9C0\uB41C \uB2E8\uC5B4\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4. \uC218\uC815 \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",CONTENT_FILTERED:"\uC548\uC804 \uC815\uCC45\uC5D0 \uC758\uD574 \uCC28\uB2E8\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB0B4\uC6A9\uC744 \uC218\uC815\uD574 \uC8FC\uC138\uC694.",MODEL_REFUSAL:"\uBAA8\uB378\uC774 \uC751\uB2F5\uC744 \uAC70\uBD80\uD588\uC2B5\uB2C8\uB2E4. \uB2E4\uB974\uAC8C \uD45C\uD604\uD574 \uBCF4\uC138\uC694.",STREAM_INTERRUPTED:"\uC751\uB2F5\uC774 \uC911\uB2E8\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",RATE_LIMITED:"\uC694\uCCAD\uC774 \uB108\uBB34 \uC7A6\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",GENERATING_IN_PROGRESS:"\uD604\uC7AC \uC2A4\uD1A0\uB9AC\uB97C \uC0DD\uC131 \uC911\uC785\uB2C8\uB2E4. \uC7A0\uC2DC\uB9CC \uAE30\uB2E4\uB824 \uC8FC\uC138\uC694.",CONCURRENT_GENERATION_LIMIT:"\uB3D9\uC2DC\uC5D0 \uC0DD\uC131 \uC911\uC778 \uC2A4\uD1A0\uB9AC\uAC00 \uB108\uBB34 \uB9CE\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INVENTORY_LIMIT:"\uC18C\uC9C0\uD488\uC774 \uAC00\uB4DD \uCC3C\uC2B5\uB2C8\uB2E4. \uC815\uB9AC \uD6C4 \uCD94\uAC00\uD574 \uC8FC\uC138\uC694.",CUSTOM_FIELDS_LIMIT:"\uD655\uC7A5 \uC18D\uC131 \uD56D\uBAA9\uC774 \uAC00\uB4DD \uCC3C\uC2B5\uB2C8\uB2E4. \uC0AD\uC81C \uD6C4 \uCD94\uAC00\uD574 \uC8FC\uC138\uC694.",MODEL_NOT_FOUND:"\uC120\uD0DD\uD55C \uBAA8\uB378\uC744 \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. \uB2E4\uB978 \uBAA8\uB378\uC744 \uC120\uD0DD\uD574 \uC8FC\uC138\uC694.",GAME_NOT_FOUND:"\uD574\uB2F9 \uAC8C\uC784\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",INVALID_REQUEST:"\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INVALID_EXTRACT_RULE:"\uC751\uB2F5 \uCD94\uCD9C \uC124\uC815\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",INTERNAL_ERROR:"\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",NOT_INITIALIZED:"SDK\uAC00 \uC544\uC9C1 \uCD08\uAE30\uD654\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.",NOT_SUPPORTED_IN_PREVIEW:"\uC774 \uAE30\uB2A5\uC740 \uBBF8\uB9AC\uBCF4\uAE30 \uBAA8\uB4DC\uC5D0\uC11C \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",NETWORK_ERROR:"\uB124\uD2B8\uC6CC\uD06C \uC624\uB958\uC785\uB2C8\uB2E4. \uC5F0\uACB0\uC744 \uD655\uC778\uD574 \uC8FC\uC138\uC694.",REQUEST_TIMEOUT:"\uC694\uCCAD \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",MODEL_LOADING_TIMEOUT:"\uBAA8\uB378 \uC751\uB2F5 \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",DAISY_CARD_REQUIRED:"\uBA54\uC2DC\uC9C0 \uB418\uB3CC\uB9AC\uAE30\uB294 \uB370\uC774\uC9C0 \uCE74\uB4DC \uAD6C\uB3C5\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.",MESSAGE_NOT_FOUND:"\uBA54\uC2DC\uC9C0\uAC00 \uC5C6\uAC70\uB098 \uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.",MESSAGE_TOO_OLD:"30\uC77C \uC774\uB0B4\uC758 \uBA54\uC2DC\uC9C0\uB9CC \uB418\uB3CC\uB9B4 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",NO_MESSAGES_TO_DELETE:"\uC774 \uBA54\uC2DC\uC9C0 \uC774\uD6C4\uC5D0 \uB418\uB3CC\uB9B4 \uBA54\uC2DC\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.",GENERATION_TIMEOUT:"\uC0DD\uC131 \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",GENERATION_LOST:"\uC0DD\uC131 \uC911 \uC5F0\uACB0\uC774 \uB04A\uACBC\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694. \uC774\uBBF8 \uC0DD\uC131\uB418\uC5C8\uB2E4\uBA74 \uC0C8\uB85C\uACE0\uCE68\uD558\uBA74 \uBCF4\uC785\uB2C8\uB2E4.",REPETITION_LOOP:"\uC751\uB2F5\uC774 \uBC18\uBCF5\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD558\uAC70\uB098 \uB2E4\uB974\uAC8C \uD45C\uD604\uD574 \uC8FC\uC138\uC694.",SAVE_FAILED:"\uBA54\uC2DC\uC9C0 \uC800\uC7A5\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uC774\uBC88\uC5D0\uB294 \uCC28\uAC10\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",FINALIZE_FAILED:"\uC751\uB2F5 \uCC98\uB9AC\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574 \uC8FC\uC138\uC694.",CONVERSATION_NOT_FOUND:"\uD574\uB2F9 \uB300\uD654\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",EMPTY_MESSAGE:"\uBA54\uC2DC\uC9C0\uB97C \uC785\uB825\uD574 \uC8FC\uC138\uC694.",CONTINUE_MODEL_NOT_AVAILABLE:"\uC774\uC5B4\uC4F0\uAE30 \uBAA8\uB378\uC744 \uD604\uC7AC \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",CONTINUE_PROMPT_MISSING:"\uC774\uC5B4\uC4F0\uAE30 \uC124\uC815\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.",GENERATION_ABORTED:"\uC0DD\uC131\uC744 \uC911\uC9C0\uD588\uC2B5\uB2C8\uB2E4."}},be={zh:at,"zh-Hant":dt,en:ct,ja:lt,ko:ht},se="zh";function Ne(o){if(!o)return null;let e=o.trim();if(!e)return null;if(st.includes(e))return e;let t=e.toLowerCase();return t.startsWith("zh")?/hant|tw|hk|mo/.test(t)?"zh-Hant":"zh":t.startsWith("ja")?"ja":t.startsWith("ko")?"ko":t.startsWith("en")?"en":null}function Ae(o){let e=Ne(o);e&&(se=e)}function ke(){if(typeof navigator>"u")return;let o=Ne(navigator.language);o&&(se=o)}function De(o){return be[se].errors[o]}function ae(o){return be[se].common[o]}var pe=null;function Le(o){pe=o}var Me="storvia-sdk-toast-style",de="storvia-sdk-toast-stack",ut=`
2
2
  #${de} {
3
3
  position: fixed;
4
4
  top: max(20px, env(safe-area-inset-top, 0px) + 20px);
@@ -114,9 +114,9 @@
114
114
  @media (max-width: 768px) {
115
115
  .storvia-toast { max-width: none; }
116
116
  }
117
- `,ut={success:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',error:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" 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>',warning:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',info:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>'},$e=!0;function Ge(o){$e=o}function pt(){if(typeof document>"u")return null;let o=document.getElementById(de);if(!o){if(!document.getElementById(Me)){let e=document.createElement("style");e.id=Me,e.textContent=ht,document.head.appendChild(e)}o=document.createElement("div"),o.id=de,document.body.appendChild(o)}return o}function ee(o,e="info",t=3500,n){if(!$e)return;let r=pt();if(!r)return;let i=t<=0,s=document.createElement("div");s.className=`storvia-toast ${e}`,s.innerHTML=`
118
- <span class="storvia-toast-icon">${ut[e]}</span>
117
+ `,pt={success:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',error:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" 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>',warning:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',info:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>'},$e=!0;function Ge(o){$e=o}function gt(){if(typeof document>"u")return null;let o=document.getElementById(de);if(!o){if(!document.getElementById(Me)){let e=document.createElement("style");e.id=Me,e.textContent=ut,document.head.appendChild(e)}o=document.createElement("div"),o.id=de,document.body.appendChild(o)}return o}function ee(o,e="info",t=3500,n){if(!$e)return;let r=gt();if(!r)return;let i=t<=0,s=document.createElement("div");s.className=`storvia-toast ${e}`,s.innerHTML=`
118
+ <span class="storvia-toast-icon">${pt[e]}</span>
119
119
  <span class="storvia-toast-msg"></span>
120
- `;let d=s.querySelector(".storvia-toast-msg");d&&(d.textContent=o);let c=()=>{s.isConnected&&(s.classList.add("leaving"),s.classList.remove("show"),setTimeout(()=>s.remove(),320))};if(n){let a=document.createElement("button");a.type="button",a.className="storvia-toast-action",a.textContent=n.label,a.addEventListener("click",()=>{try{n.onClick()}catch(l){console.error("[Storvia toast] action error:",l)}c()}),s.appendChild(a)}if(i){let a=document.createElement("button");a.type="button",a.className="storvia-toast-close",a.setAttribute("aria-label",ae("close")),a.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',a.addEventListener("click",c),s.appendChild(a)}r.appendChild(s),requestAnimationFrame(()=>s.classList.add("show")),i||setTimeout(c,t)}function gt(o){let e=o.filter(t=>t).map(t=>`\u300C${t}\u300D`).join("");return ae("violationWords").replace("{words}",e)}var mt=3e3,xe={};function Ue(o){let e=Date.now();if(!(e-(xe[o]??0)<mt)){if(xe[o]=e,!ue){console.warn(`[Storvia] navigate \u2192 wallet(${o})\uFF1A\u5F53\u524D\u672A\u68C0\u6D4B\u5230\u5BBF\u4E3B\uFF08dev \u6A21\u5F0F\uFF09\uFF0C\u751F\u4EA7\u73AF\u5883\u7531\u5BBF\u4E3B\u5F39\u5145\u503C\u5F15\u5BFC / \u8DF3\u94B1\u5305\u9875\u3002`);return}try{ue(C("navigate",{target:"wallet",reason:o}))}catch(t){console.error("[Storvia] navigate \u2192 wallet \u901A\u8FC7 bus \u53D1\u9001\u5931\u8D25:",t)}}}function S(o,e,t){if(o==="GENERATION_ABORTED")return;if(o==="INSUFFICIENT_CREDITS")return Ue("insufficient_credits");if(o==="DAISY_CARD_REQUIRED")return Ue("daisy_card_required");let n=o==="VIOLATION_WORD_DETECTED"&&t?.length?gt(t):De(o)||e||ae("unknownError");ee(n,o==="RATE_LIMITED"?"warning":"error")}function ft(o,e){let t=e?.tickMs??100,n=e?.baseLagMs??1e3,r=e?.maxLagMs??2500,i=e?.minCharsPerTick??2,s="",d=null,c=0,a=0,l=()=>Math.min(r,Math.max(n,c*1.35)),u=()=>{let y=Math.max(i,Math.ceil(s.length*t/l()));if(y>=s.length)y=s.length;else{let R=s.charCodeAt(y-1);R>=55296&&R<=56319&&y++}let I=s.slice(0,y);s=s.slice(y),I&&o(I)},f=()=>{d=null,u(),s&&(d=setTimeout(f,t))};return{push:y=>{let I=Date.now();if(a>0){let R=Math.min(I-a,r);c=c>0?c*.7+R*.3:R}a=I,s+=y,d===null&&f()},flush:()=>{d!==null&&(clearTimeout(d),d=null),s&&(o(s),s="")},cancel:()=>{d!==null&&(clearTimeout(d),d=null),s=""}}}function pe(o){let e=ft(o.onChunk);return{cbs:{onChunk:n=>e.push(n),onDone:(n,r)=>{e.flush(),o.onDone(n,r)},onAborted:o.onAborted?n=>{e.flush(),o.onAborted(n)}:void 0,onState:o.onState?(n,r)=>{e.flush(),o.onState(n,r)}:void 0,onThinking:o.onThinking?n=>{e.flush(),o.onThinking(n)}:void 0,onCreatedCharacters:o.onCreatedCharacters?n=>{e.flush(),o.onCreatedCharacters(n)}:void 0,onReconnect:o.onReconnect},flush:()=>e.flush()}}var Fe="0.10.4";function G(o,e){if(e.aborted){if(o.onAborted){o.onAborted(e.aborted);return}o.onDone(e.aborted.id,{truncated:!1});return}o.onDone(e.messageId,e.truncated===void 0?void 0:{truncated:e.truncated})}var T=class T{constructor(e,t,n=!1,r=""){this.baseUrl=e,this.token=t,this.debug=n,this.devApiKey=r}setToken(e){this.token=e}setDebug(e){this.debug=e}maybeShowNetworkToast(e){e instanceof g||S("NETWORK_ERROR")}wrapAbortError(e){if(e instanceof DOMException&&e.name==="AbortError"){let t=new g("REQUEST_TIMEOUT","Request timed out");return S("REQUEST_TIMEOUT"),t}return e}createTimeoutController(){let e=new AbortController,t=setTimeout(()=>e.abort(),T.REQUEST_TIMEOUT);return{controller:e,clear:()=>clearTimeout(t)}}buildHeaders(){let e={"Content-Type":"application/json"};return this.token&&(e.Authorization=`Bearer ${this.token}`),this.devApiKey&&(e["x-api-key"]=this.devApiKey),e["x-client-info"]=`storvia-sdk/${Fe}`,e}log(e){if(!this.debug)return;let{method:t,path:n,body:r,status:i,rawResponse:s,parsedData:d,error:c,durationMs:a,modelName:l}=e,u="%c[Storvia SDK]",f="color: #6366f1; font-weight: bold",m=a!==void 0?` (${a}ms)`:"",h=i!==void 0?` [${i}]`:"",w=l?` [model: ${l}]`:"";c?(console.groupCollapsed(`${u} %c${t} ${n}${h}${w}${m} %c\u2717`,f,"color: #e0e0e0","color: #ef4444"),r!==void 0&&console.log("Request:",r),s!==void 0&&console.log("Response (raw):",s),console.error("Error:",c),console.groupEnd()):(console.groupCollapsed(`${u} %c${t} ${n}${h}${w}${m} %c\u2713`,f,"color: #e0e0e0","color: #22c55e"),r!==void 0&&console.log("Request:",r),s!==void 0&&console.log("Response (raw):",s),d!==void 0&&d!==s&&console.log("Response (data):",d),console.groupEnd())}async get(e,t){let n=new URL(`${this.baseUrl}${e}`);t&&Object.entries(t).forEach(([a,l])=>n.searchParams.set(a,l));let r=Date.now(),i,s,{controller:d,clear:c}=this.createTimeoutController();try{let a=await fetch(n.toString(),{method:"GET",headers:this.buildHeaders(),signal:d.signal});c(),i=a.status;let{raw:l,data:u}=await this.handleResponseWithRaw(a);return s=l,this.log({method:"GET",path:e,body:t,status:i,rawResponse:s,parsedData:u,durationMs:Date.now()-r}),u}catch(a){c();let l=this.wrapAbortError(a);throw this.log({method:"GET",path:e,body:t,status:i,rawResponse:s,error:l,durationMs:Date.now()-r}),l===a&&this.maybeShowNetworkToast(a),l}}async post(e,t,n){let r=Date.now(),i,s,{controller:d,clear:c}=this.createTimeoutController();try{let a=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:d.signal});c(),i=a.status;let{raw:l,data:u}=await this.handleResponseWithRaw(a);return s=l,this.log({method:"POST",path:e,body:t,status:i,rawResponse:s,parsedData:u,durationMs:Date.now()-r,modelName:n?.modelName}),u}catch(a){c();let l=this.wrapAbortError(a);throw this.log({method:"POST",path:e,body:t,status:i,rawResponse:s,error:l,durationMs:Date.now()-r,modelName:n?.modelName}),l===a&&this.maybeShowNetworkToast(a),l}}async patch(e,t){let n=Date.now(),r,i,{controller:s,clear:d}=this.createTimeoutController();try{let c=await fetch(`${this.baseUrl}${e}`,{method:"PATCH",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:s.signal});d(),r=c.status;let{raw:a,data:l}=await this.handleResponseWithRaw(c);return i=a,this.log({method:"PATCH",path:e,body:t,status:r,rawResponse:i,parsedData:l,durationMs:Date.now()-n}),l}catch(c){d();let a=this.wrapAbortError(c);throw this.log({method:"PATCH",path:e,body:t,status:r,rawResponse:i,error:a,durationMs:Date.now()-n}),a===c&&this.maybeShowNetworkToast(c),a}}async put(e,t){let n=Date.now(),r,i,{controller:s,clear:d}=this.createTimeoutController();try{let c=await fetch(`${this.baseUrl}${e}`,{method:"PUT",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:s.signal});d(),r=c.status;let{raw:a,data:l}=await this.handleResponseWithRaw(c);return i=a,this.log({method:"PUT",path:e,body:t,status:r,rawResponse:i,parsedData:l,durationMs:Date.now()-n}),l}catch(c){d();let a=this.wrapAbortError(c);throw this.log({method:"PUT",path:e,body:t,status:r,rawResponse:i,error:a,durationMs:Date.now()-n}),a===c&&this.maybeShowNetworkToast(c),a}}async delete(e){let t=Date.now(),n,r,{controller:i,clear:s}=this.createTimeoutController();try{let d=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.buildHeaders(),signal:i.signal});s(),n=d.status;let{raw:c,data:a}=await this.handleResponseWithRaw(d);return r=c,this.log({method:"DELETE",path:e,status:n,rawResponse:r,parsedData:a,durationMs:Date.now()-t}),a}catch(d){s();let c=this.wrapAbortError(d);throw this.log({method:"DELETE",path:e,status:n,rawResponse:r,error:c,durationMs:Date.now()-t}),c===d&&this.maybeShowNetworkToast(d),c}}async stream(e,t,n,r,i,s,d,c,a,l,u,f){let m=Date.now(),h=i?.modelName?` [model: ${i.modelName}]`:"",w=[],y=E=>{this.debug&&w.push({t:Date.now()-m,event:E})},{cbs:I,flush:R}=pe({onChunk:n,onDone:r,onState:s,onThinking:d,onCreatedCharacters:c,onReconnect:l,onAborted:u,onBase:f}),Te=new AbortController,k=null,_=null,N=null,D=()=>{k!==null&&(clearTimeout(k),k=null),_!==null&&(clearTimeout(_),_=null)},we=E=>{N=E,D(),Te.abort()};k=setTimeout(()=>we("REQUEST_TIMEOUT"),T.REQUEST_TIMEOUT);let O;try{O=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t),signal:Te.signal})}catch(E){if(D(),N){let v=new g(N,"Request timed out");throw S(N),this.log({method:"STREAM",path:e,body:t,error:v,durationMs:Date.now()-m,modelName:i?.modelName}),v}throw this.maybeShowNetworkToast(E),E}if(k!==null&&(clearTimeout(k),k=null),!O.ok){D();let E=await O.text().catch(()=>""),v={};try{v=JSON.parse(E)}catch{}let b=v.code||"INTERNAL_ERROR",p=v.message||v.error||v.details,Oe=Array.isArray(v.matched_words)?v.matched_words:void 0,Pe=new g(b,p||`HTTP ${O.status}`,Oe);throw S(b,p,Oe),this.log({method:"STREAM",path:e,body:t,status:O.status,rawResponse:E,error:Pe,durationMs:Date.now()-m,modelName:i?.modelName}),Pe}let Ce=O.body?.getReader();if(!Ce)throw D(),new g("INTERNAL_ERROR","No response body for stream");_=setTimeout(()=>we("MODEL_LOADING_TIMEOUT"),T.INITIAL_TIMEOUT);let Re=new TextDecoder,X="",ce,re,M="",oe,ie,U="",L=!1,P=null,_e=E=>{if(L)return;let v=E.endsWith("\r")?E.slice(0,-1):E;if(v.startsWith("id: ")){ie=v.slice(4);return}if(!v.startsWith("data: "))return;let b=v.slice(6);if(b==="[DONE]"){y("[DONE]"),L=!0;return}try{let p=JSON.parse(b);y(p),p.type==="done"&&p.id?(X=p.id,ce=p.truncated===!0):p.type==="aborted"?(re={id:typeof p.id=="string"?p.id:"",persisted:p.persisted===!0},L=!0):p.type==="error"?(P=new g(p.code||"INTERNAL_ERROR",p.message||"Generation failed",Array.isArray(p.matched_words)?p.matched_words:void 0),L=!0):p.type==="state"?(I.onState?.(p.delta,p.full??null),Array.isArray(p.createdNames)&&p.createdNames.length&&I.onCreatedCharacters?.(p.createdNames)):p.type==="start"?(_!==null&&(clearTimeout(_),_=null),typeof p.base_content=="string"&&f?.(p.base_content)):p.type==="thinking"?(p.status==="start"||p.status==="end")&&I.onThinking?.(p.status):p.content&&(_!==null&&(clearTimeout(_),_=null),M+=p.content,I.onChunk(p.content))}catch{y({raw:b})}ie!==void 0&&(oe=ie,ie=void 0)},Se=()=>{if(D(),P)throw R(),S(P.code,P.message,P.matchedWords),this.log({method:"STREAM",path:e,body:t,error:P,durationMs:Date.now()-m,modelName:i?.modelName}),P;this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2713`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #22c55e"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log("Message ID:",X),re&&console.log("Aborted:",re),console.log(`SSE events (${w.length}):`,w),console.groupEnd()),G(I,{messageId:X,truncated:ce,aborted:re})};try{for(;;){let{done:E,value:v}=await Ce.read();if(E)break;U+=Re.decode(v,{stream:!0});let b=U.split(`
121
- `);U=b.pop()??"";for(let p of b)_e(p);if(L){Se();return}}if(U+=Re.decode(),U&&_e(U),L){Se();return}}catch(E){if(D(),P)throw P;if(N){let v=new g(N,"Stream did not start in time");if(this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2717 ${N}`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #ef4444"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log(`SSE events (${w.length}):`,w),console.error("Timeout:",v),console.groupEnd()),a){await this.resumeLoop(a,oe,I,{finalize:!0});return}throw S(N),R(),v}if(this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2717`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #ef4444"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log(`SSE events (${w.length}):`,w),console.error("Stream error:",E),console.groupEnd()),a){await this.resumeLoop(a,oe,I,{finalize:!0});return}throw R(),E}if(D(),X){G(I,{messageId:X,truncated:ce});return}if(a){await this.resumeLoop(a,oe,I,{finalize:!0});return}R()}async resumeLoop(e,t,n,r){let i=t;for(let d=1;d<=T.RECONNECT_MAX_ATTEMPTS;d++){let c=Math.min(T.RECONNECT_BACKOFF_CAP,1e3*2**(d-1));await new Promise(u=>setTimeout(u,c)),n.onReconnect?.({attempt:d});let a={messageId:"",lastId:i},l;try{l=await this.pumpGetStream(e.conversationId,e.topic,i,a,n)}catch{continue}if(i=a.lastId??i,l==="done"){if(a.errorCode)throw this.terminalError(a);G(n,a);return}if(l==="inactive"){(a.messageId||r?.finalize)&&G(n,a);return}}let s=new g("STREAM_INTERRUPTED","Stream reconnection failed after maximum attempts");throw S("STREAM_INTERRUPTED"),s}async resumeStream(e,t,n){let{cbs:r}=pe(n),i={messageId:""},s;try{s=await this.pumpGetStream(e,t,void 0,i,r)}catch{await this.resumeLoop({conversationId:e,topic:t},i.lastId,r);return}if(s==="done"){if(i.errorCode)throw this.terminalError(i);G(r,i);return}if(s==="inactive"){i.messageId&&G(r,i);return}await this.resumeLoop({conversationId:e,topic:t},i.lastId,r)}terminalError(e){let t=new g(e.errorCode??"INTERNAL_ERROR",e.errorMessage||"Generation failed",e.errorMatchedWords);return S(t.code,t.message,t.matchedWords),t}async pumpGetStream(e,t,n,r,i){let s=new URL(`${this.baseUrl}/conversations/${encodeURIComponent(e)}/stream`);n&&s.searchParams.set("from",n),t&&s.searchParams.set("topic",t);let d=new AbortController,c=setTimeout(()=>d.abort(),T.REQUEST_TIMEOUT),a;try{a=await fetch(s.toString(),{method:"GET",headers:this.buildHeaders(),signal:d.signal})}finally{clearTimeout(c)}if(!a.ok)throw new g("STREAM_INTERRUPTED",`Resume HTTP ${a.status}`);if(!(a.headers.get("content-type")||"").includes("text/event-stream"))return"inactive";let u=a.body?.getReader();return u?await this.pumpReader(u,r,i):"inactive"}async pumpReader(e,t,n){let r=new TextDecoder,i,s=null,d=()=>{s&&clearTimeout(s),s=setTimeout(()=>{e.cancel().catch(()=>{})},T.RESUME_STALL_TIMEOUT)};d();let c="",a=!1,l=u=>{if(a)return;let f=u.endsWith("\r")?u.slice(0,-1):u;if(f.startsWith("id: ")){i=f.slice(4);return}if(!f.startsWith("data: "))return;let m=f.slice(6);if(m==="[DONE]"){a=!0;return}try{let h=JSON.parse(m);h.type==="done"&&h.id?(t.messageId=h.id,t.truncated=h.truncated===!0):h.type==="aborted"?(t.aborted={id:typeof h.id=="string"?h.id:"",persisted:h.persisted===!0},a=!0):h.type==="error"?(t.errorCode=h.code||"INTERNAL_ERROR",t.errorMessage=h.message||"Generation failed",Array.isArray(h.matched_words)&&(t.errorMatchedWords=h.matched_words),a=!0):h.type==="state"?(n.onState?.(h.delta,h.full??null),Array.isArray(h.createdNames)&&h.createdNames.length&&n.onCreatedCharacters?.(h.createdNames)):h.type==="start"?typeof h.base_content=="string"&&n.onBase?.(h.base_content):h.type==="thinking"?(h.status==="start"||h.status==="end")&&n.onThinking?.(h.status):h.content&&n.onChunk(h.content)}catch{}i!==void 0&&(t.lastId=i,i=void 0)};try{for(;;){let{done:u,value:f}=await e.read();if(u)break;d(),c+=r.decode(f,{stream:!0});let m=c.split(`
122
- `);c=m.pop()??"";for(let h of m)l(h);if(a)return s&&clearTimeout(s),"done"}if(c+=r.decode(),c&&l(c),a)return s&&clearTimeout(s),"done"}catch{}finally{s&&clearTimeout(s)}return"eof"}async handleResponseWithRaw(e){let t=await e.text(),n;try{n=t?JSON.parse(t):null}catch{n=t}if(!e.ok){let r=n&&typeof n=="object"?n:{},i={401:"UNAUTHORIZED",402:"INSUFFICIENT_CREDITS",429:"RATE_LIMITED"},s=r.code||i[e.status]||"INTERNAL_ERROR",d=Array.isArray(r.matched_words)?r.matched_words:void 0,c=new g(s,r.message||`HTTP ${e.status}`,d);throw S(s,r.message,d),c}return n&&typeof n=="object"&&"data"in n?{raw:n,data:n.data}:{raw:n,data:n}}};T.REQUEST_TIMEOUT=6e4,T.INITIAL_TIMEOUT=3e4,T.RESUME_STALL_TIMEOUT=6e4,T.RECONNECT_MAX_ATTEMPTS=10,T.RECONNECT_BACKOFF_CAP=15e3;var te=T;function vt(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();let o=new Uint8Array(16);crypto.getRandomValues(o),o[6]=o[6]&15|64,o[8]=o[8]&63|128;let e=Array.from(o,t=>t.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}var Ve=20,We=40,V=class{constructor(e,t,n,r,i=!1,s,d,c){this.http=e;this.getGameId=t;this.getConversationId=n;this.getModelId=r;this.isPreview=i;this.previewHistory=[];this.previewConfig=s,this.getModelName=d,this.getPreset=c}reqMeta(){let e=this.getModelName?.();return e?{modelName:e}:void 0}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.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.(),client_message_uuid:vt()};if(e.stream){await this.http.stream("/chat",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/chat",t,this.reqMeta())}async save(e){return this.isPreview?{id:`preview-${Date.now()}`}:this.http.post("/messages/save",{game_id:this.getGameId(),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,sceneKey:e.sceneKey,stream:e.stream,onChunk:e.onChunk,onDone:e.onDone,onState:e.onState,onThinking:e.onThinking,onCreatedCharacters:e.onCreatedCharacters});let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.()};if(e.stream){await this.http.stream("/generate",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/generate",t,this.reqMeta())}async once(e){if(this.isPreview)return this.oncePreview(e);let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),message:e.message,scene_key:e.sceneKey,stream:e.stream===!0,preset:this.getPreset?.()};if(!e.stream)return this.http.post("/once",t,this.reqMeta());let n="";return await this.http.stream("/once",t,r=>{n+=r,e.onChunk?.(r)},()=>{},this.reqMeta(),void 0,e.onThinking),{content:n}}async oncePreview(e){let t={model_id:this.getModelId(),message:e.message,scene_key:e.sceneKey,history_messages:[],preset:this.getPreset?.()};this.previewConfig?t.prompt_config=this.previewConfig:t.game_id=this.getGameId();let n=this.previewConfig;n?.reply_length&&(t.reply_length=n.reply_length),n?.reply_language&&(t.reply_language=n.reply_language);let r="";return await this.http.stream("/preview",t,i=>{r+=i,e.onChunk?.(i)},()=>{},this.reqMeta(),void 0,e.onThinking),{content:r}}async retry(e={}){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.retry() is not available in preview mode. Publish the game and test on the Storvia platform.");let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.()};if(e.stream){await this.http.stream("/retry",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/retry",t,this.reqMeta())}async continue(e={}){if(this.isPreview)return;let t={conversation_id:this.getConversationId(),topic:e.topic??null,game_id:this.getGameId(),preset:this.getPreset?.(),scene_key:e.sceneKey,extract:e.extract};await this.http.stream("/continue",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted,e.onBase)}async cancel(e={}){if(this.isPreview)return{active:!1};let t=await this.http.post(`/conversations/${encodeURIComponent(this.getConversationId())}/cancel`,{topic:e.topic});return{active:t.active===!0,generationId:t.generation_id}}async messages(e){if(this.isPreview)return{data:[],hasMore:!1,nextCursor:null};let t={conversation_id:this.getConversationId(),order:e.order,limit:String(e.limit??20)};e.topic&&(t.topic=e.topic),e.cursor&&(t.cursor_uuid=e.cursor.uuid,t.cursor_created_at=e.cursor.createdAt);let n=await this.http.get("/messages",t);return{data:n.messages.map(r=>({uuid:r.uuid,role:r.role,content:r.content,topic:r.topic,status:r.status,model:r.model,createdAt:r.created_at,truncated:r.truncated===!0})),hasMore:n.has_more,nextCursor:n.next_cursor?{uuid:n.next_cursor.cursor_uuid,createdAt:n.next_cursor.cursor_created_at}:null}}async edit(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.edit() is not available in preview mode. Publish the game and test on the Storvia platform.");let t=await this.http.patch(`/messages/${encodeURIComponent(e.uuid)}`,{content:e.content});return{uuid:t.uuid,role:t.role,content:t.content,updatedAt:t.updated_at}}async delete(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.delete() is not available in preview mode. Publish the game and test on the Storvia platform.");return{uuid:(await this.http.delete(`/messages/${encodeURIComponent(e.uuid)}`)).uuid}}async rollback(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.rollback() is not available in preview mode. Publish the game and test on the Storvia platform.");let t=await this.http.post(`/messages/${encodeURIComponent(e.uuid)}/rollback`,{});return{deletedCount:t.deleted_count,deletedUuids:t.deleted_uuids,restoredGameState:t.restored_game_state}}async resume(e={}){this.isPreview||await this.http.resumeStream(this.getConversationId(),e.topic,{onChunk:e.onChunk??(()=>{}),onDone:e.onDone??(()=>{}),onState:F(e.onState),onThinking:e.onThinking,onCreatedCharacters:e.onCreatedCharacters,onReconnect:e.onReconnecting,onAborted:e.onAborted})}async sendPreview(e){let t=e.message.trim().length>0,n=this.previewHistory.slice(t?-(Ve-1):-Ve);t&&this.pushPreviewHistory({role:"user",content:e.message});let r={model_id:this.getModelId(),message:e.message,topic:e.topic,scene_key:e.sceneKey,history_messages:n,preset:this.getPreset?.()};this.previewConfig?r.prompt_config=this.previewConfig:r.game_id=this.getGameId();let i=this.previewConfig;if(i?.reply_length&&(r.reply_length=i.reply_length),i?.reply_language&&(r.reply_language=i.reply_language),e.stream){let u="";await this.http.stream("/preview",r,f=>{u+=f,e.onChunk?.(f)},(f,m)=>{u&&this.pushPreviewHistory({role:"assistant",content:u}),e.onDone?.(f,m)},this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters);return}let s="",d=null,c=null,a=[];await this.http.stream("/preview",r,u=>{s+=u},()=>{},this.reqMeta(),(u,f)=>{d=u,c=f,e.onState&&e.onState(d,c)},void 0,u=>{a=u,e.onCreatedCharacters&&e.onCreatedCharacters(u)}),s&&this.pushPreviewHistory({role:"assistant",content:s});let l={id:"",content:s,truncated:!1};return d&&(l.delta=d,c&&(l.full=c)),a.length&&(l.createdNames=a),l}pushPreviewHistory(e){this.previewHistory.push(e),this.previewHistory.length>We&&this.previewHistory.splice(0,this.previewHistory.length-We)}};function F(o){if(o)return(e,t)=>o(e,t)}var ge=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}async get(e,t){if(this.isPreview){let r=this.mem[e]||{};return t?{...r[t]||{}}:{...r}}let n=t?{group:t}:void 0;return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,n)}async update(e,t,n){if(this.isPreview){let r=this.mem[e]||(this.mem[e]={});r[t]={...r[t]||{},...n};return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,values:n})}async remove(e,t,n){if(n.length){if(this.isPreview){let r=this.mem[e]?.[t];if(r)for(let i of n)delete r[i];return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,removeKeys:n})}}async removeGroup(e,t){if(this.isPreview){let n=this.mem[e];n&&delete n[t];return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,removeGroup:!0})}},W=class{constructor(e,t,n=!1,r,i){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];r&&(this.mem=r.map(He)),this.state=new ge(e,t,n,i)}setInitial(e,t){this.mem=e?e.map(He):[],this.state.setInitial(t)}async list(){return this.isPreview?this.mem.map(Be):this.http.get(`/conversations/${this.getConversationId()}/characters`)}async get(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return t?Be(t):{name:e}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async add(e){if(this.isPreview){this.mem.push({...e,isPreset:!1});return}await this.http.post(`/conversations/${this.getConversationId()}/characters`,e)}async update(e,t){if(this.isPreview){let n=this.mem.find(r=>r.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 merge(e,t){if(this.isPreview){if(this.mem.find(r=>r.name===e)?.isPreset)throw new g("INVALID_REQUEST","\u9884\u8BBE\u89D2\u8272\u4E0D\u53EF\u88AB\u5408\u5E76");if(e===t||!this.mem.some(r=>r.name===t))throw new g("INVALID_REQUEST","\u76EE\u6807\u89D2\u8272\u4E0D\u5B58\u5728\u6216\u4E0E\u6765\u6E90\u76F8\u540C");this.mem=this.mem.filter(r=>r.name!==e);return}await this.http.post(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/merge`,{target:t})}async detail(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:e,avatar:t?.avatar,description:t?.description,...t?.introduction!==void 0?{introduction:t.introduction}:{},...t?.visibleAtStart!==void 0?{visibleAtStart:t.visibleAtStart}:{},userDescription:t?.userDescription,...t?.gender?{gender:t.gender}:{},...t?.isPreset!==void 0?{isPreset:t.isPreset}:{},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})}};function He(o){return{name:o.name,description:o.description,avatar:o.avatar,...o.introduction!==void 0?{introduction:o.introduction}:{},...o.visibleAtStart!==void 0?{visibleAtStart:o.visibleAtStart}:{},...o.gender?{gender:o.gender}:{},...o.userDescription!==void 0?{userDescription:o.userDescription}:{},...o.isPreset!==void 0?{isPreset:o.isPreset}:{}}}function Be(o){return{name:o.name,avatar:o.avatar,description:o.description,...o.introduction!==void 0?{introduction:o.introduction}:{},...o.visibleAtStart!==void 0?{visibleAtStart:o.visibleAtStart}:{},...o.userDescription!==void 0?{userDescription:o.userDescription}:{},...o.gender?{gender:o.gender}:{},...o.isPreset!==void 0?{isPreset:o.isPreset}:{}}}var H=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];r&&(this.mem=r.map(i=>({...i})))}setInitial(e){this.mem=e?e.map(t=>({...t})):[]}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(r=>r.from===e&&r.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 r=this.mem.find(i=>i.from===e&&i.to===t);r?Object.assign(r,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)}`)}};function je(o){let e={count:o.count};return o.desc!==void 0&&(e.desc=o.desc),o.icon_url!==void 0&&(e.iconUrl=o.icon_url),e}function me(o){let e={};if(!o)return e;for(let[t,n]of Object.entries(o)){let r={};for(let[i,s]of Object.entries(n))r[i]=je(s);e[t]=r}return e}function It(o){let e={};if(!o)return e;for(let[t,n]of Object.entries(o))e[t]=je(n);return e}var B=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem=me(r))}setInitial(e){this.mem=e?me(e):{}}async list(e){if(this.isPreview){if(e!==void 0)return{...this.mem[e]||{}};let n={};for(let[r,i]of Object.entries(this.mem))n[r]={...i};return n}if(e!==void 0){let n=await this.http.get(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(e)}`);return It(n)}let t=await this.http.get(`/conversations/${this.getConversationId()}/inventory`);return me(t)}async add(e){let{group:t,name:n,count:r=1,desc:i,iconUrl:s}=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 c={count:r};i!==void 0&&(c.desc=i),s!==void 0&&(c.iconUrl=s),this.mem[t][n]=c;return}let d={group:t,name:n,count:r};i!==void 0&&(d.desc=i),s!==void 0&&(d.icon_url=s),await this.http.post(`/conversations/${this.getConversationId()}/inventory`,d)}async update(e){let{group:t,name:n,count:r,desc:i,iconUrl:s}=e;if(this.isPreview){let c=this.mem[t];if(!c||!(n in c))throw new Error(`Item "${t}/${n}" not found`);let a=c[n];r!==void 0&&(a.count=r),i!==void 0&&(a.desc=i),s!==void 0&&(a.iconUrl=s);return}let d={};r!==void 0&&(d.count=r),i!==void 0&&(d.desc=i),s!==void 0&&(d.icon_url=s),await this.http.patch(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,d)}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 removeBatch(e){if(this.isPreview){for(let{group:t,name:n}of e)this.mem[t]&&delete this.mem[t][n];return}e.length!==0&&await this.http.post(`/conversations/${this.getConversationId()}/inventory/batch-delete`,{items:e})}async move(e){let{fromGroup:t,toGroup:n,name:r,newName:i}=e;if(this.isPreview){let s=this.mem[t];if(!s||!(r in s))throw new Error(`Source item "${t}/${r}" not found`);if(!this.mem[n])throw new Error(`Target group "${n}" does not exist`);let d=i||r;if(t===n&&d===r)return;if(d in this.mem[n])throw new Error(`Item "${d}" already exists in target group`);this.mem[n][d]=s[r],delete s[r];return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/move`,{fromGroup:t,toGroup:n,name:r,newName:i})}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 i=this.mem[e];if(i&&Object.keys(i).length>0&&!n)throw new Error(`Group "${e}" is not empty, pass cascade: true to force delete`);delete this.mem[e];return}let r=n?"?cascade=true":"";await this.http.delete(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}${r}`)}};var j=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}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 fe=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}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})}async remove(e,t){if(t.length){if(this.isPreview){let n=this.mem[e];if(n)for(let r of t)delete n[r];return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,removeKeys:t})}}async removeGroup(e){if(this.isPreview){delete this.mem[e];return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,removeGroup:!0})}},K=class{constructor(e,t,n=!1,r,i){this.http=e;this.getConversationId=t;this.isPreview=n;this.memPersona={name:""};r&&(this.memPersona={...r}),this.state=new fe(e,t,n,i)}setInitial(e,t){this.memPersona=e?{...e}:{name:""},this.state.setInitial(t)}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)}};function q(o,e){if(!e)return o;let t=o.includes("?")?"&":"?";return`${o}${t}game_id=${encodeURIComponent(e)}`}var z=class{constructor(e,t,n,r=!1,i,s){this.http=e;this.getConversationId=t;this.getGameId=n;this.isPreview=r;this.mem={};this.memInject={};i&&(this.mem=Ke(i)),s&&(this.memInject={...s})}setInitial(e,t){this.mem=e?Ke(e):{},this.memInject=t?{...t}:{}}async get(e){if(this.isPreview)return e!==void 0?this.mem[e]:{...this.mem};let t=await this.http.get(q(`/conversations/${this.getConversationId()}/custom`,this.getGameId()));return e!==void 0?t[e]:t}async set(e,t){if(this.isPreview){for(let[r,i]of Object.entries(e))typeof i=="object"&&i!==null&&typeof this.mem[r]=="object"&&this.mem[r]!==null?this.mem[r]={...this.mem[r],...i}:this.mem[r]=i,t?.inject!==void 0&&(this.memInject[r]=t.inject);return}let n=t?.inject!==void 0?{data:e,inject:t.inject}:e;await this.http.patch(q(`/conversations/${this.getConversationId()}/custom`,this.getGameId()),n)}async setInject(e,t){if(this.isPreview){this.memInject[e]=t;return}await this.http.patch(q(`/conversations/${this.getConversationId()}/custom/inject/${encodeURIComponent(e)}`,this.getGameId()),{inject:t})}getInject(){return{...this.memInject}}async delete(e){if(this.isPreview){delete this.mem[e],delete this.memInject[e];return}await this.http.delete(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}`,this.getGameId()))}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(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,this.getGameId()),{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(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,this.getGameId()))}};function Ke(o){let e={};for(let[t,n]of Object.entries(o))typeof n=="object"&&n!==null&&!Array.isArray(n)?e[t]={...n}:e[t]=n;return e}function qe(o,e){if(!e)return o;let t=o.includes("?")?"&":"?";return`${o}${t}game_id=${encodeURIComponent(e)}`}var Y=class{constructor(e,t,n,r=!1,i){this.http=e;this.getConversationId=t;this.getGameId=n;this.isPreview=r;this.mem={};i&&(this.mem={...i})}setInitial(e){this.mem=e?{...e}:{}}async get(){return this.isPreview?{...this.mem}:await this.http.get(qe(`/conversations/${this.getConversationId()}/save`,this.getGameId()))}async set(e){if(this.isPreview){this.mem={...e};return}await this.http.put(qe(`/conversations/${this.getConversationId()}/save`,this.getGameId()),e)}};var Q=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n}async get(){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.state.get() is not available in preview mode. Publish the game and test on the Storvia platform. (Use per-module get() like storvia.world.get() if you need to inspect state during preview.)");return this.http.get(`/conversations/${this.getConversationId()}/state`)}};var Z=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=null;this.wb=null;this.worldbook={get:async()=>this.isPreview?this.wb?ze(this.wb):null:(await this.http.get(`/conversations/${this.getConversationId()}/worldbook`)).worldbook,update:async e=>{let t=typeof e=="string"?{content:e}:{...e};if(t.content!==void 0&&(t.content=(t.content??"").trim()),t.entries!==void 0&&(t.entries=Et(t.entries)),this.isPreview){let r={content:t.content??this.wb?.content??"",entries:t.entries??this.wb?.entries??[],updated_at:new Date().toISOString()};return this.wb=r,ze(r)}return(await this.http.patch(`/conversations/${this.getConversationId()}/worldbook`,t)).worldbook}}}async get(){return this.isPreview?this.mem?{...this.mem}:null:(await this.http.get(`/conversations/${this.getConversationId()}/summary`)).ai_summary}async update(e){let t=(e??"").trim();if(this.isPreview){let r={content:t,updated_at:new Date().toISOString()};return this.mem=r,{...r}}return(await this.http.patch(`/conversations/${this.getConversationId()}/summary`,{content:t})).ai_summary}};function ze(o){return{...o,entries:o.entries.map(e=>({...e,keys:[...e.keys]}))}}function Et(o){return(o??[]).flatMap(e=>{let t=(e?.content??"").trim(),n=[...new Set((e?.keys??[]).map(r=>(r??"").trim()).filter(r=>r!==""))];return!t||n.length===0?[]:[{id:e.id||yt(),keys:n,content:t}]})}function yt(){let o=globalThis.crypto;return o?.randomUUID?o.randomUUID():`ewr-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var ve=60,Ie=1e3,Ee=1e4,A=class{constructor(e,t=!1,n=()=>Date.now()){this.send=e;this.isPreview=t;this.now=n;this.lastNotifyAt=0;this.lastRefreshAt=0}notify(e){let t=Tt(e);if(!t)return!1;let n=this.now();return n-this.lastNotifyAt<Ie?!1:(this.lastNotifyAt=n,this.isPreview?(ee(t,"info"),!0):(this.send(C("host-notify",{text:t})),!0))}refreshPanel(e){if(this.isPreview)return!1;let t=this.now();return t-this.lastRefreshAt<Ee?!1:(this.lastRefreshAt=t,this.send(C("host-state-changed",e?.length?{scope:e}:{})),!0)}};function Tt(o){return typeof o!="string"?"":o.replace(/\s+/g," ").trim().slice(0,ve)}var Ye="/functions/v1/world-engine/v1",wt="https://api.storvia.ai";function Ct(){return window.__STORVIA__||{}}function Rt(o,e=3e4){let t=Ct();return t.apiBase?Promise.resolve(t):new Promise((n,r)=>{let i=setTimeout(()=>{s(),d(),r(new g("NOT_INITIALIZED","Timed out waiting for __STORVIA__ config from parent frame."))},e),s=o.on("init",a=>{a.payload?.apiBase&&c({apiBase:a.payload.apiBase,gameId:a.payload.gameId,conversationId:a.payload.conversationId,accessToken:a.payload.accessToken,selectedModelId:a.payload.selectedModelId,lang:a.payload.lang,debug:a.payload.debug})}),d=o.on("preview-init",a=>{a.payload?.apiBase&&c(a.payload)});function c(a){clearTimeout(i),s(),d();let l=window;l.__STORVIA__=a,n(a)}o.send(C("ready",{}))})}var ne=class{constructor(){this.baseUrl="";this.gameId="";this.conversationId="";this.modelId="";this.models=[];this.presetId="";this.accessToken="";this.initialized=!1;this.isPreview=!1;this.previewConfig=void 0}async init(){if(this.initialized)return;let e=window.flutter_inappwebview,t=typeof e?.callHandler=="function";this.bus=new x({incoming:window,outgoing:()=>t?null:window.parent,verifySource:t?l=>l.source===null||l.source===window:l=>l.source===window.parent,customSend:t?l=>e.callHandler("storviaBus",l):void 0}),Le(l=>this.bus.send(l));let n=await Rt(this.bus),r=n.apiBase;if(!r)throw new g("NOT_INITIALIZED","window.__STORVIA__.apiBase is not set. The platform must inject it before SDK init.");if(this.baseUrl=`${r}${Ye}`,this.isPreview=!!n.preview,this.previewConfig=n.previewConfig,!n.gameId)throw new g("GAME_NOT_FOUND","window.__STORVIA__.gameId is not set. The platform must inject it before SDK init.");if(this.gameId=n.gameId,!n.accessToken)throw new g("UNAUTHORIZED","window.__STORVIA__.accessToken is not set. The platform must inject the user token before SDK init.");if(this.accessToken=n.accessToken,Ae(n.lang),this.http=new te(this.baseUrl,this.accessToken,!!n.debug),this.isPreview){this.conversationId="00000000-0000-0000-0000-000000000000",this.models=n.models??[],this.modelId=n.selectedModelId||this.models[0]?.id||"";let[l,u]=await Promise.all([this.fetchPreviewSnapshot(),this.modelId?Promise.resolve(null):this.fetchModels()]);u&&(this.models=u,this.modelId=u[0]?.id||""),this.presetId=n.presetId||"";let f=()=>this.gameId,m=()=>this.conversationId,h=()=>this.modelId,w=()=>this.models.find(I=>I.id===this.modelId)?.name,y=()=>this.presetId||void 0;this.chat=new V(this.http,f,m,h,!0,this.previewConfig,w,y),this.characters=new W(this.http,m,!0,l?.characters,l?.characterStates),this.relationships=new H(this.http,m,!0,l?.relationships),this.inventory=new B(this.http,m,!0,l?.inventory),this.world=new j(this.http,m,!0,l?.world),this.player=new K(this.http,m,!0,l?.player,l?.playerState),this.custom=new z(this.http,m,f,!0,l?.custom,l?.custom_inject),this.save=new Y(this.http,m,f,!0,l?.save_data),this.state=new Q(this.http,m,!0),this.memory=new Z(this.http,m,!0),this.host=new A(I=>this.bus.send(I),!0),this.initialized=!0,this.listenForPreviewMessages(),this.listenForTokenUpdate();return}if(!n.conversationId)throw new g("NOT_INITIALIZED","window.__STORVIA__.conversationId is not set. The platform must inject it before SDK init.");this.conversationId=n.conversationId,this.modelId=n.selectedModelId||"",this.modelId||(this.models=await this.fetchModels(),this.modelId=this.models[0]?.id||""),this.presetId=n.presetId||"";let i=()=>this.gameId,s=()=>this.conversationId,d=()=>this.modelId,c=()=>this.models.find(l=>l.id===this.modelId)?.name,a=()=>this.presetId||void 0;this.chat=new V(this.http,i,s,d,!1,void 0,c,a),this.characters=new W(this.http,s),this.relationships=new H(this.http,s),this.inventory=new B(this.http,s),this.world=new j(this.http,s),this.player=new K(this.http,s),this.custom=new z(this.http,s,i),this.save=new Y(this.http,s,i),this.state=new Q(this.http,s),this.memory=new Z(this.http,s),this.host=new A(l=>this.bus.send(l),!1),this.listenForTokenUpdate(),this.listenForModelChange(),this.initialized=!0}listenForModelChange(){this.bus.on("set-model",e=>{let t=e.payload?.modelId||"";t&&(this.modelId=t)}),this.bus.on("set-preset",e=>{this.presetId=e.payload?.presetId||""})}listenForTokenUpdate(){this.bus.on("token-update",e=>{let t=e.payload?.accessToken;typeof t!="string"||!t||(this.accessToken=t,this.http?.setToken(t))})}listenForPreviewMessages(){this.bus.on("set-model",e=>{this.modelId=e.payload.modelId||""}),this.bus.on("set-preset",e=>{this.presetId=e.payload?.presetId||""}),this.bus.on("config-update",e=>{this.previewConfig=e.payload.previewConfig,this.chat&&this.chat.updatePreviewConfig(this.previewConfig),this.refreshPreviewSnapshot().catch(t=>{console.warn("[Storvia SDK] refreshPreviewSnapshot failed:",t)})})}async fetchPreviewSnapshot(){try{let e={game_id:this.gameId};return this.previewConfig&&("game_config"in this.previewConfig&&(e.game_config=this.previewConfig.game_config),"game_state"in this.previewConfig&&(e.game_state_override=this.previewConfig.game_state)),await this.http.post("/preview/initial-snapshot",e)}catch(e){return console.warn("[Storvia SDK] fetchPreviewSnapshot failed:",e),null}}async refreshPreviewSnapshot(){let e=await this.fetchPreviewSnapshot();e&&(this.characters?.setInitial(e.characters,e.characterStates),this.player?.setInitial(e.player,e.playerState),this.inventory?.setInitial(e.inventory),this.relationships?.setInitial(e.relationships),this.world?.setInitial(e.world),this.custom?.setInitial(e.custom,e.custom_inject),this.save?.setInitial(e.save_data))}async fetchModels(){try{return await this.http.get("/models")}catch{}return[]}async initDev(e){if(this.initialized)return;this.baseUrl=`${wt}${Ye}`,this.gameId=e.gameId,this.isPreview=!0,this.http=new te(this.baseUrl,"",!1,e.apiKey);let[t,n]=await Promise.all([this.fetchModels(),this.fetchPreviewSnapshot()]);this.models=t;let r=e.model?t.find(l=>l.name===e.model)?.id??"":"";this.modelId=r||t[0]?.id||"",this.conversationId="00000000-0000-0000-0000-000000000000";let i=()=>this.gameId,s=()=>this.conversationId,d=()=>this.modelId,c=()=>this.models.find(l=>l.id===this.modelId)?.name;this.presetId=e.preset||"";let a=()=>this.presetId||void 0;this.chat=new V(this.http,i,s,d,!0,void 0,c,a),this.characters=new W(this.http,s,!0,n?.characters,n?.characterStates),this.relationships=new H(this.http,s,!0,n?.relationships),this.inventory=new B(this.http,s,!0,n?.inventory),this.world=new j(this.http,s,!0,n?.world),this.player=new K(this.http,s,!0,n?.player,n?.playerState),this.custom=new z(this.http,s,i,!0,n?.custom,n?.custom_inject),this.save=new Y(this.http,s,i,!0,n?.save_data),this.state=new Q(this.http,s,!0),this.memory=new Z(this.http,s,!0),this.host=new A(()=>{},!0),this.initialized=!0}async getAssets(e,t){let n={asset_type:e};return t&&(n.category=t),(await this.http.get("/assets",n)).map(i=>({id:i.id,name:i.name,url:i.url,assetType:i.asset_type,category:i.category}))}};async function Qe(o){ke();let e=new ne;return o?.dev?await e.initDev(o.dev):await e.init(),e}function ye(o){return typeof o=="object"&&o!==null&&"value"in o&&"type"in o&&(o.type==="number"||o.type==="text")}function Ze(o){return ye(o)?o.value:o}0&&(module.exports={HOST_NOTIFY_MAX_LENGTH,HOST_NOTIFY_MIN_INTERVAL_MS,HOST_PANEL_SCOPES,HOST_REFRESH_MIN_INTERVAL_MS,HostModule,PROTOCOL_VERSION,StorviaBus,StorviaError,StorviaSDK,createStorviaSDK,envelope,extractFieldValue,isProtocolEnvelope,isRichFieldValue,setToastEnabled,showToast});
120
+ `;let d=s.querySelector(".storvia-toast-msg");d&&(d.textContent=o);let c=()=>{s.isConnected&&(s.classList.add("leaving"),s.classList.remove("show"),setTimeout(()=>s.remove(),320))};if(n){let a=document.createElement("button");a.type="button",a.className="storvia-toast-action",a.textContent=n.label,a.addEventListener("click",()=>{try{n.onClick()}catch(l){console.error("[Storvia toast] action error:",l)}c()}),s.appendChild(a)}if(i){let a=document.createElement("button");a.type="button",a.className="storvia-toast-close",a.setAttribute("aria-label",ae("close")),a.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',a.addEventListener("click",c),s.appendChild(a)}r.appendChild(s),requestAnimationFrame(()=>s.classList.add("show")),i||setTimeout(c,t)}function mt(o){let e=o.filter(t=>t).map(t=>`\u300C${t}\u300D`).join("");return ae("violationWords").replace("{words}",e)}var ft=3e3,xe={};function Ue(o){let e=Date.now();if(!(e-(xe[o]??0)<ft)){if(xe[o]=e,!pe){console.warn(`[Storvia] navigate \u2192 wallet(${o})\uFF1A\u5F53\u524D\u672A\u68C0\u6D4B\u5230\u5BBF\u4E3B\uFF08dev \u6A21\u5F0F\uFF09\uFF0C\u751F\u4EA7\u73AF\u5883\u7531\u5BBF\u4E3B\u5F39\u5145\u503C\u5F15\u5BFC / \u8DF3\u94B1\u5305\u9875\u3002`);return}try{pe(T("navigate",{target:"wallet",reason:o}))}catch(t){console.error("[Storvia] navigate \u2192 wallet \u901A\u8FC7 bus \u53D1\u9001\u5931\u8D25:",t)}}}function S(o,e,t){if(o==="GENERATION_ABORTED")return;if(o==="INSUFFICIENT_CREDITS")return Ue("insufficient_credits");if(o==="DAISY_CARD_REQUIRED")return Ue("daisy_card_required");let n=o==="VIOLATION_WORD_DETECTED"&&t?.length?mt(t):De(o)||e||ae("unknownError");ee(n,o==="RATE_LIMITED"?"warning":"error")}function vt(o,e){let t=e?.tickMs??100,n=e?.baseLagMs??1e3,r=e?.maxLagMs??2500,i=e?.minCharsPerTick??2,s="",d=null,c=0,a=0,l=()=>Math.min(r,Math.max(n,c*1.35)),u=()=>{let y=Math.max(i,Math.ceil(s.length*t/l()));if(y>=s.length)y=s.length;else{let R=s.charCodeAt(y-1);R>=55296&&R<=56319&&y++}let I=s.slice(0,y);s=s.slice(y),I&&o(I)},f=()=>{d=null,u(),s&&(d=setTimeout(f,t))};return{push:y=>{let I=Date.now();if(a>0){let R=Math.min(I-a,r);c=c>0?c*.7+R*.3:R}a=I,s+=y,d===null&&f()},flush:()=>{d!==null&&(clearTimeout(d),d=null),s&&(o(s),s="")},cancel:()=>{d!==null&&(clearTimeout(d),d=null),s=""}}}function ge(o){let e=vt(o.onChunk);return{cbs:{onChunk:n=>e.push(n),onDone:(n,r)=>{e.flush(),o.onDone(n,r)},onAborted:o.onAborted?n=>{e.flush(),o.onAborted(n)}:void 0,onState:o.onState?(n,r)=>{e.flush(),o.onState(n,r)}:void 0,onThinking:o.onThinking?n=>{e.flush(),o.onThinking(n)}:void 0,onCreatedCharacters:o.onCreatedCharacters?n=>{e.flush(),o.onCreatedCharacters(n)}:void 0,onReconnect:o.onReconnect},flush:()=>e.flush()}}var Fe="0.10.6";function G(o,e){if(e.aborted){if(o.onAborted){o.onAborted(e.aborted);return}o.onDone(e.aborted.id,{truncated:!1});return}o.onDone(e.messageId,e.truncated===void 0?void 0:{truncated:e.truncated})}var w=class w{constructor(e,t,n=!1,r=""){this.baseUrl=e,this.token=t,this.debug=n,this.devApiKey=r}setToken(e){this.token=e}setDebug(e){this.debug=e}maybeShowNetworkToast(e){e instanceof g||S("NETWORK_ERROR")}wrapAbortError(e){if(e instanceof DOMException&&e.name==="AbortError"){let t=new g("REQUEST_TIMEOUT","Request timed out");return S("REQUEST_TIMEOUT"),t}return e}createTimeoutController(){let e=new AbortController,t=setTimeout(()=>e.abort(),w.REQUEST_TIMEOUT);return{controller:e,clear:()=>clearTimeout(t)}}buildHeaders(){let e={"Content-Type":"application/json"};return this.token&&(e.Authorization=`Bearer ${this.token}`),this.devApiKey&&(e["x-api-key"]=this.devApiKey),e["x-client-info"]=`storvia-sdk/${Fe}`,e}log(e){if(!this.debug)return;let{method:t,path:n,body:r,status:i,rawResponse:s,parsedData:d,error:c,durationMs:a,modelName:l}=e,u="%c[Storvia SDK]",f="color: #6366f1; font-weight: bold",m=a!==void 0?` (${a}ms)`:"",h=i!==void 0?` [${i}]`:"",C=l?` [model: ${l}]`:"";c?(console.groupCollapsed(`${u} %c${t} ${n}${h}${C}${m} %c\u2717`,f,"color: #e0e0e0","color: #ef4444"),r!==void 0&&console.log("Request:",r),s!==void 0&&console.log("Response (raw):",s),console.error("Error:",c),console.groupEnd()):(console.groupCollapsed(`${u} %c${t} ${n}${h}${C}${m} %c\u2713`,f,"color: #e0e0e0","color: #22c55e"),r!==void 0&&console.log("Request:",r),s!==void 0&&console.log("Response (raw):",s),d!==void 0&&d!==s&&console.log("Response (data):",d),console.groupEnd())}async get(e,t){let n=new URL(`${this.baseUrl}${e}`);t&&Object.entries(t).forEach(([a,l])=>n.searchParams.set(a,l));let r=Date.now(),i,s,{controller:d,clear:c}=this.createTimeoutController();try{let a=await fetch(n.toString(),{method:"GET",headers:this.buildHeaders(),signal:d.signal});c(),i=a.status;let{raw:l,data:u}=await this.handleResponseWithRaw(a);return s=l,this.log({method:"GET",path:e,body:t,status:i,rawResponse:s,parsedData:u,durationMs:Date.now()-r}),u}catch(a){c();let l=this.wrapAbortError(a);throw this.log({method:"GET",path:e,body:t,status:i,rawResponse:s,error:l,durationMs:Date.now()-r}),l===a&&this.maybeShowNetworkToast(a),l}}async post(e,t,n){let r=Date.now(),i,s,{controller:d,clear:c}=this.createTimeoutController();try{let a=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:d.signal});c(),i=a.status;let{raw:l,data:u}=await this.handleResponseWithRaw(a);return s=l,this.log({method:"POST",path:e,body:t,status:i,rawResponse:s,parsedData:u,durationMs:Date.now()-r,modelName:n?.modelName}),u}catch(a){c();let l=this.wrapAbortError(a);throw this.log({method:"POST",path:e,body:t,status:i,rawResponse:s,error:l,durationMs:Date.now()-r,modelName:n?.modelName}),l===a&&this.maybeShowNetworkToast(a),l}}async patch(e,t){let n=Date.now(),r,i,{controller:s,clear:d}=this.createTimeoutController();try{let c=await fetch(`${this.baseUrl}${e}`,{method:"PATCH",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:s.signal});d(),r=c.status;let{raw:a,data:l}=await this.handleResponseWithRaw(c);return i=a,this.log({method:"PATCH",path:e,body:t,status:r,rawResponse:i,parsedData:l,durationMs:Date.now()-n}),l}catch(c){d();let a=this.wrapAbortError(c);throw this.log({method:"PATCH",path:e,body:t,status:r,rawResponse:i,error:a,durationMs:Date.now()-n}),a===c&&this.maybeShowNetworkToast(c),a}}async put(e,t){let n=Date.now(),r,i,{controller:s,clear:d}=this.createTimeoutController();try{let c=await fetch(`${this.baseUrl}${e}`,{method:"PUT",headers:this.buildHeaders(),body:t?JSON.stringify(t):void 0,signal:s.signal});d(),r=c.status;let{raw:a,data:l}=await this.handleResponseWithRaw(c);return i=a,this.log({method:"PUT",path:e,body:t,status:r,rawResponse:i,parsedData:l,durationMs:Date.now()-n}),l}catch(c){d();let a=this.wrapAbortError(c);throw this.log({method:"PUT",path:e,body:t,status:r,rawResponse:i,error:a,durationMs:Date.now()-n}),a===c&&this.maybeShowNetworkToast(c),a}}async delete(e){let t=Date.now(),n,r,{controller:i,clear:s}=this.createTimeoutController();try{let d=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.buildHeaders(),signal:i.signal});s(),n=d.status;let{raw:c,data:a}=await this.handleResponseWithRaw(d);return r=c,this.log({method:"DELETE",path:e,status:n,rawResponse:r,parsedData:a,durationMs:Date.now()-t}),a}catch(d){s();let c=this.wrapAbortError(d);throw this.log({method:"DELETE",path:e,status:n,rawResponse:r,error:c,durationMs:Date.now()-t}),c===d&&this.maybeShowNetworkToast(d),c}}async stream(e,t,n,r,i,s,d,c,a,l,u,f){let m=Date.now(),h=i?.modelName?` [model: ${i.modelName}]`:"",C=[],y=E=>{this.debug&&C.push({t:Date.now()-m,event:E})},{cbs:I,flush:R}=ge({onChunk:n,onDone:r,onState:s,onThinking:d,onCreatedCharacters:c,onReconnect:l,onAborted:u,onBase:f}),Te=new AbortController,k=null,_=null,N=null,D=()=>{k!==null&&(clearTimeout(k),k=null),_!==null&&(clearTimeout(_),_=null)},we=E=>{N=E,D(),Te.abort()};k=setTimeout(()=>we("REQUEST_TIMEOUT"),w.REQUEST_TIMEOUT);let O;try{O=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t),signal:Te.signal})}catch(E){if(D(),N){let v=new g(N,"Request timed out");throw S(N),this.log({method:"STREAM",path:e,body:t,error:v,durationMs:Date.now()-m,modelName:i?.modelName}),v}throw this.maybeShowNetworkToast(E),E}if(k!==null&&(clearTimeout(k),k=null),!O.ok){D();let E=await O.text().catch(()=>""),v={};try{v=JSON.parse(E)}catch{}let b=v.code||"INTERNAL_ERROR",p=v.message||v.error||v.details,Oe=Array.isArray(v.matched_words)?v.matched_words:void 0,Pe=new g(b,p||`HTTP ${O.status}`,Oe);throw S(b,p,Oe),this.log({method:"STREAM",path:e,body:t,status:O.status,rawResponse:E,error:Pe,durationMs:Date.now()-m,modelName:i?.modelName}),Pe}let Ce=O.body?.getReader();if(!Ce)throw D(),new g("INTERNAL_ERROR","No response body for stream");_=setTimeout(()=>we("MODEL_LOADING_TIMEOUT"),w.INITIAL_TIMEOUT);let Re=new TextDecoder,X="",le,re,M="",oe,ie,U="",L=!1,P=null,_e=E=>{if(L)return;let v=E.endsWith("\r")?E.slice(0,-1):E;if(v.startsWith("id: ")){ie=v.slice(4);return}if(!v.startsWith("data: "))return;let b=v.slice(6);if(b==="[DONE]"){y("[DONE]"),L=!0;return}try{let p=JSON.parse(b);y(p),p.type==="done"&&p.id?(X=p.id,le=p.truncated===!0):p.type==="aborted"?(re={id:typeof p.id=="string"?p.id:"",persisted:p.persisted===!0},L=!0):p.type==="error"?(P=new g(p.code||"INTERNAL_ERROR",p.message||"Generation failed",Array.isArray(p.matched_words)?p.matched_words:void 0),L=!0):p.type==="state"?(I.onState?.(p.delta,p.full??null),Array.isArray(p.createdNames)&&p.createdNames.length&&I.onCreatedCharacters?.(p.createdNames)):p.type==="start"?(_!==null&&(clearTimeout(_),_=null),typeof p.base_content=="string"&&f?.(p.base_content)):p.type==="thinking"?(p.status==="start"||p.status==="end")&&I.onThinking?.(p.status):p.content&&(_!==null&&(clearTimeout(_),_=null),M+=p.content,I.onChunk(p.content))}catch{y({raw:b})}ie!==void 0&&(oe=ie,ie=void 0)},Se=()=>{if(D(),P)throw R(),S(P.code,P.message,P.matchedWords),this.log({method:"STREAM",path:e,body:t,error:P,durationMs:Date.now()-m,modelName:i?.modelName}),P;this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2713`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #22c55e"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log("Message ID:",X),re&&console.log("Aborted:",re),console.log(`SSE events (${C.length}):`,C),console.groupEnd()),G(I,{messageId:X,truncated:le,aborted:re})};try{for(;;){let{done:E,value:v}=await Ce.read();if(E)break;U+=Re.decode(v,{stream:!0});let b=U.split(`
121
+ `);U=b.pop()??"";for(let p of b)_e(p);if(L){Se();return}}if(U+=Re.decode(),U&&_e(U),L){Se();return}}catch(E){if(D(),P)throw P;if(N){let v=new g(N,"Stream did not start in time");if(this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2717 ${N}`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #ef4444"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log(`SSE events (${C.length}):`,C),console.error("Timeout:",v),console.groupEnd()),a){await this.resumeLoop(a,oe,I,{finalize:!0});return}throw S(N),R(),v}if(this.debug&&(console.groupCollapsed(`%c[Storvia SDK] %cSTREAM ${e} [${O.status}]${h} (${Date.now()-m}ms) %c\u2717`,"color: #6366f1; font-weight: bold","color: #e0e0e0","color: #ef4444"),console.log("Request:",t),console.log(`Accumulated content (${M.length} chars):`,M),console.log(`SSE events (${C.length}):`,C),console.error("Stream error:",E),console.groupEnd()),a){await this.resumeLoop(a,oe,I,{finalize:!0});return}throw R(),E}if(D(),X){G(I,{messageId:X,truncated:le});return}if(a){await this.resumeLoop(a,oe,I,{finalize:!0});return}R()}async resumeLoop(e,t,n,r){let i=t;for(let d=1;d<=w.RECONNECT_MAX_ATTEMPTS;d++){let c=Math.min(w.RECONNECT_BACKOFF_CAP,1e3*2**(d-1));await new Promise(u=>setTimeout(u,c)),n.onReconnect?.({attempt:d});let a={messageId:"",lastId:i},l;try{l=await this.pumpGetStream(e.conversationId,e.topic,i,a,n)}catch{continue}if(i=a.lastId??i,l==="done"){if(a.errorCode)throw this.terminalError(a);G(n,a);return}if(l==="inactive"){(a.messageId||r?.finalize)&&G(n,a);return}}let s=new g("STREAM_INTERRUPTED","Stream reconnection failed after maximum attempts");throw S("STREAM_INTERRUPTED"),s}async resumeStream(e,t,n){let{cbs:r}=ge(n),i={messageId:""},s;try{s=await this.pumpGetStream(e,t,void 0,i,r)}catch{await this.resumeLoop({conversationId:e,topic:t},i.lastId,r);return}if(s==="done"){if(i.errorCode)throw this.terminalError(i);G(r,i);return}if(s==="inactive"){i.messageId&&G(r,i);return}await this.resumeLoop({conversationId:e,topic:t},i.lastId,r)}terminalError(e){let t=new g(e.errorCode??"INTERNAL_ERROR",e.errorMessage||"Generation failed",e.errorMatchedWords);return S(t.code,t.message,t.matchedWords),t}async pumpGetStream(e,t,n,r,i){let s=new URL(`${this.baseUrl}/conversations/${encodeURIComponent(e)}/stream`);n&&s.searchParams.set("from",n),t&&s.searchParams.set("topic",t);let d=new AbortController,c=setTimeout(()=>d.abort(),w.REQUEST_TIMEOUT),a;try{a=await fetch(s.toString(),{method:"GET",headers:this.buildHeaders(),signal:d.signal})}finally{clearTimeout(c)}if(!a.ok)throw new g("STREAM_INTERRUPTED",`Resume HTTP ${a.status}`);if(!(a.headers.get("content-type")||"").includes("text/event-stream"))return"inactive";let u=a.body?.getReader();return u?await this.pumpReader(u,r,i):"inactive"}async pumpReader(e,t,n){let r=new TextDecoder,i,s=null,d=()=>{s&&clearTimeout(s),s=setTimeout(()=>{e.cancel().catch(()=>{})},w.RESUME_STALL_TIMEOUT)};d();let c="",a=!1,l=u=>{if(a)return;let f=u.endsWith("\r")?u.slice(0,-1):u;if(f.startsWith("id: ")){i=f.slice(4);return}if(!f.startsWith("data: "))return;let m=f.slice(6);if(m==="[DONE]"){a=!0;return}try{let h=JSON.parse(m);h.type==="done"&&h.id?(t.messageId=h.id,t.truncated=h.truncated===!0):h.type==="aborted"?(t.aborted={id:typeof h.id=="string"?h.id:"",persisted:h.persisted===!0},a=!0):h.type==="error"?(t.errorCode=h.code||"INTERNAL_ERROR",t.errorMessage=h.message||"Generation failed",Array.isArray(h.matched_words)&&(t.errorMatchedWords=h.matched_words),a=!0):h.type==="state"?(n.onState?.(h.delta,h.full??null),Array.isArray(h.createdNames)&&h.createdNames.length&&n.onCreatedCharacters?.(h.createdNames)):h.type==="start"?typeof h.base_content=="string"&&n.onBase?.(h.base_content):h.type==="thinking"?(h.status==="start"||h.status==="end")&&n.onThinking?.(h.status):h.content&&n.onChunk(h.content)}catch{}i!==void 0&&(t.lastId=i,i=void 0)};try{for(;;){let{done:u,value:f}=await e.read();if(u)break;d(),c+=r.decode(f,{stream:!0});let m=c.split(`
122
+ `);c=m.pop()??"";for(let h of m)l(h);if(a)return s&&clearTimeout(s),"done"}if(c+=r.decode(),c&&l(c),a)return s&&clearTimeout(s),"done"}catch{}finally{s&&clearTimeout(s)}return"eof"}async handleResponseWithRaw(e){let t=await e.text(),n;try{n=t?JSON.parse(t):null}catch{n=t}if(!e.ok){let r=n&&typeof n=="object"?n:{},i={401:"UNAUTHORIZED",402:"INSUFFICIENT_CREDITS",429:"RATE_LIMITED"},s=r.code||i[e.status]||"INTERNAL_ERROR",d=Array.isArray(r.matched_words)?r.matched_words:void 0,c=new g(s,r.message||`HTTP ${e.status}`,d);throw S(s,r.message,d),c}return n&&typeof n=="object"&&"data"in n?{raw:n,data:n.data}:{raw:n,data:n}}};w.REQUEST_TIMEOUT=6e4,w.INITIAL_TIMEOUT=3e4,w.RESUME_STALL_TIMEOUT=6e4,w.RECONNECT_MAX_ATTEMPTS=10,w.RECONNECT_BACKOFF_CAP=15e3;var te=w;var We="storvia_chat_main";function It(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();let o=new Uint8Array(16);crypto.getRandomValues(o),o[6]=o[6]&15|64,o[8]=o[8]&63|128;let e=Array.from(o,t=>t.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}var Ve=20,He=40,V=class{constructor(e,t,n,r,i=!1,s,d,c){this.http=e;this.getGameId=t;this.getConversationId=n;this.getModelId=r;this.isPreview=i;this.previewHistory=[];this.previewConfig=s,this.getModelName=d,this.getPreset=c}reqMeta(){let e=this.getModelName?.();return e?{modelName:e}:void 0}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.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.(),client_message_uuid:It()};if(e.stream){await this.http.stream("/chat",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/chat",t,this.reqMeta())}async save(e){return this.isPreview?{id:`preview-${Date.now()}`}:this.http.post("/messages/save",{game_id:this.getGameId(),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,sceneKey:e.sceneKey,stream:e.stream,onChunk:e.onChunk,onDone:e.onDone,onState:e.onState,onThinking:e.onThinking,onCreatedCharacters:e.onCreatedCharacters});let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.()};if(e.stream){await this.http.stream("/generate",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/generate",t,this.reqMeta())}async once(e){if(this.isPreview)return this.oncePreview(e);let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),message:e.message,scene_key:e.sceneKey,stream:e.stream===!0,preset:this.getPreset?.()};if(!e.stream)return this.http.post("/once",t,this.reqMeta());let n="";return await this.http.stream("/once",t,r=>{n+=r,e.onChunk?.(r)},()=>{},this.reqMeta(),void 0,e.onThinking),{content:n}}async oncePreview(e){let t={model_id:this.getModelId(),message:e.message,scene_key:e.sceneKey,history_messages:[],preset:this.getPreset?.()};this.previewConfig?t.prompt_config=this.previewConfig:t.game_id=this.getGameId();let n=this.previewConfig;n?.reply_length&&(t.reply_length=n.reply_length),n?.reply_language&&(t.reply_language=n.reply_language);let r="";return await this.http.stream("/preview",t,i=>{r+=i,e.onChunk?.(i)},()=>{},this.reqMeta(),void 0,e.onThinking),{content:r}}async retry(e={}){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.retry() is not available in preview mode. Publish the game and test on the Storvia platform.");let t={game_id:this.getGameId(),conversation_id:this.getConversationId(),model_id:this.getModelId(),topic:e.topic,scene_key:e.sceneKey,extract:e.extract,stream:e.stream??!1,preset:this.getPreset?.()};if(e.stream){await this.http.stream("/retry",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted);return}return this.http.post("/retry",t,this.reqMeta())}async continue(e={}){if(this.isPreview)return;let t={conversation_id:this.getConversationId(),topic:e.topic??null,game_id:this.getGameId(),preset:this.getPreset?.(),scene_key:e.sceneKey,extract:e.extract};await this.http.stream("/continue",t,e.onChunk??(()=>{}),e.onDone??(()=>{}),this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters,{conversationId:this.getConversationId(),topic:e.topic},e.onReconnecting,e.onAborted,e.onBase)}async cancel(e={}){if(this.isPreview)return{active:!1};let t=await this.http.post(`/conversations/${encodeURIComponent(this.getConversationId())}/cancel`,{topic:e.topic});return{active:t.active===!0,generationId:t.generation_id}}async messages(e){if(this.isPreview)return{data:[],hasMore:!1,nextCursor:null};let t={conversation_id:this.getConversationId(),order:e.order,limit:String(e.limit??20)};e.topic&&(t.topic=e.topic),e.cursor&&(t.cursor_uuid=e.cursor.uuid,t.cursor_created_at=e.cursor.createdAt);let n=await this.http.get("/messages",t);return{data:n.messages.map(r=>({uuid:r.uuid,role:r.role,content:r.content,topic:r.topic,status:r.status,model:r.model,createdAt:r.created_at,truncated:r.truncated===!0})),hasMore:n.has_more,nextCursor:n.next_cursor?{uuid:n.next_cursor.cursor_uuid,createdAt:n.next_cursor.cursor_created_at}:null}}async edit(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.edit() is not available in preview mode. Publish the game and test on the Storvia platform.");let t=await this.http.patch(`/messages/${encodeURIComponent(e.uuid)}`,{content:e.content});return{uuid:t.uuid,role:t.role,content:t.content,updatedAt:t.updated_at}}async delete(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.delete() is not available in preview mode. Publish the game and test on the Storvia platform.");return{uuid:(await this.http.delete(`/messages/${encodeURIComponent(e.uuid)}`)).uuid}}async rollback(e){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.chat.rollback() is not available in preview mode. Publish the game and test on the Storvia platform.");let t=await this.http.post(`/messages/${encodeURIComponent(e.uuid)}/rollback`,{});return{deletedCount:t.deleted_count,deletedUuids:t.deleted_uuids,restoredGameState:t.restored_game_state}}async resume(e={}){this.isPreview||await this.http.resumeStream(this.getConversationId(),e.topic,{onChunk:e.onChunk??(()=>{}),onDone:e.onDone??(()=>{}),onState:F(e.onState),onThinking:e.onThinking,onCreatedCharacters:e.onCreatedCharacters,onReconnect:e.onReconnecting,onAborted:e.onAborted})}async sendPreview(e){let t=e.message.trim().length>0,n=this.previewHistory.slice(t?-(Ve-1):-Ve);t&&this.pushPreviewHistory({role:"user",content:e.message});let r={model_id:this.getModelId(),message:e.message,topic:e.topic,scene_key:e.sceneKey,history_messages:n,preset:this.getPreset?.()};this.previewConfig?r.prompt_config=this.previewConfig:r.game_id=this.getGameId();let i=this.previewConfig;if(i?.reply_length&&(r.reply_length=i.reply_length),i?.reply_language&&(r.reply_language=i.reply_language),e.stream){let u="";await this.http.stream("/preview",r,f=>{u+=f,e.onChunk?.(f)},(f,m)=>{u&&this.pushPreviewHistory({role:"assistant",content:u}),e.onDone?.(f,m)},this.reqMeta(),F(e.onState),e.onThinking,e.onCreatedCharacters);return}let s="",d=null,c=null,a=[];await this.http.stream("/preview",r,u=>{s+=u},()=>{},this.reqMeta(),(u,f)=>{d=u,c=f,e.onState&&e.onState(d,c)},void 0,u=>{a=u,e.onCreatedCharacters&&e.onCreatedCharacters(u)}),s&&this.pushPreviewHistory({role:"assistant",content:s});let l={id:"",content:s,truncated:!1};return d&&(l.delta=d,c&&(l.full=c)),a.length&&(l.createdNames=a),l}pushPreviewHistory(e){this.previewHistory.push(e),this.previewHistory.length>He&&this.previewHistory.splice(0,this.previewHistory.length-He)}};function F(o){if(o)return(e,t)=>o(e,t)}var me=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}async get(e,t){if(this.isPreview){let r=this.mem[e]||{};return t?{...r[t]||{}}:{...r}}let n=t?{group:t}:void 0;return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,n)}async update(e,t,n){if(this.isPreview){let r=this.mem[e]||(this.mem[e]={});r[t]={...r[t]||{},...n};return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,values:n})}async remove(e,t,n){if(n.length){if(this.isPreview){let r=this.mem[e]?.[t];if(r)for(let i of n)delete r[i];return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,removeKeys:n})}}async removeGroup(e,t){if(this.isPreview){let n=this.mem[e];n&&delete n[t];return}await this.http.patch(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/state`,{group:t,removeGroup:!0})}},H=class{constructor(e,t,n=!1,r,i){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];r&&(this.mem=r.map(Be)),this.state=new me(e,t,n,i)}setInitial(e,t){this.mem=e?e.map(Be):[],this.state.setInitial(t)}async list(){return this.isPreview?this.mem.map(je):this.http.get(`/conversations/${this.getConversationId()}/characters`)}async get(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return t?je(t):{name:e}}return this.http.get(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}`)}async add(e){if(this.isPreview){this.mem.push({...e,isPreset:!1});return}await this.http.post(`/conversations/${this.getConversationId()}/characters`,e)}async update(e,t){if(this.isPreview){let n=this.mem.find(r=>r.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 merge(e,t){if(this.isPreview){if(this.mem.find(r=>r.name===e)?.isPreset)throw new g("INVALID_REQUEST","\u9884\u8BBE\u89D2\u8272\u4E0D\u53EF\u88AB\u5408\u5E76");if(e===t||!this.mem.some(r=>r.name===t))throw new g("INVALID_REQUEST","\u76EE\u6807\u89D2\u8272\u4E0D\u5B58\u5728\u6216\u4E0E\u6765\u6E90\u76F8\u540C");this.mem=this.mem.filter(r=>r.name!==e);return}await this.http.post(`/conversations/${this.getConversationId()}/characters/${encodeURIComponent(e)}/merge`,{target:t})}async detail(e){if(this.isPreview){let t=this.mem.find(n=>n.name===e);return{name:e,avatar:t?.avatar,description:t?.description,...t?.introduction!==void 0?{introduction:t.introduction}:{},...t?.visibleAtStart!==void 0?{visibleAtStart:t.visibleAtStart}:{},userDescription:t?.userDescription,...t?.gender?{gender:t.gender}:{},...t?.isPreset!==void 0?{isPreset:t.isPreset}:{},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})}};function Be(o){return{name:o.name,description:o.description,avatar:o.avatar,...o.introduction!==void 0?{introduction:o.introduction}:{},...o.visibleAtStart!==void 0?{visibleAtStart:o.visibleAtStart}:{},...o.gender?{gender:o.gender}:{},...o.userDescription!==void 0?{userDescription:o.userDescription}:{},...o.isPreset!==void 0?{isPreset:o.isPreset}:{}}}function je(o){return{name:o.name,avatar:o.avatar,description:o.description,...o.introduction!==void 0?{introduction:o.introduction}:{},...o.visibleAtStart!==void 0?{visibleAtStart:o.visibleAtStart}:{},...o.userDescription!==void 0?{userDescription:o.userDescription}:{},...o.gender?{gender:o.gender}:{},...o.isPreset!==void 0?{isPreset:o.isPreset}:{}}}var W=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=[];r&&(this.mem=r.map(i=>({...i})))}setInitial(e){this.mem=e?e.map(t=>({...t})):[]}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(r=>r.from===e&&r.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 r=this.mem.find(i=>i.from===e&&i.to===t);r?Object.assign(r,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)}`)}};function Ke(o){let e={count:o.count};return o.desc!==void 0&&(e.desc=o.desc),o.icon_url!==void 0&&(e.iconUrl=o.icon_url),e}function fe(o){let e={};if(!o)return e;for(let[t,n]of Object.entries(o)){let r={};for(let[i,s]of Object.entries(n))r[i]=Ke(s);e[t]=r}return e}function Et(o){let e={};if(!o)return e;for(let[t,n]of Object.entries(o))e[t]=Ke(n);return e}var B=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem=fe(r))}setInitial(e){this.mem=e?fe(e):{}}async list(e){if(this.isPreview){if(e!==void 0)return{...this.mem[e]||{}};let n={};for(let[r,i]of Object.entries(this.mem))n[r]={...i};return n}if(e!==void 0){let n=await this.http.get(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(e)}`);return Et(n)}let t=await this.http.get(`/conversations/${this.getConversationId()}/inventory`);return fe(t)}async add(e){let{group:t,name:n,count:r=1,desc:i,iconUrl:s}=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 c={count:r};i!==void 0&&(c.desc=i),s!==void 0&&(c.iconUrl=s),this.mem[t][n]=c;return}let d={group:t,name:n,count:r};i!==void 0&&(d.desc=i),s!==void 0&&(d.icon_url=s),await this.http.post(`/conversations/${this.getConversationId()}/inventory`,d)}async update(e){let{group:t,name:n,count:r,desc:i,iconUrl:s}=e;if(this.isPreview){let c=this.mem[t];if(!c||!(n in c))throw new Error(`Item "${t}/${n}" not found`);let a=c[n];r!==void 0&&(a.count=r),i!==void 0&&(a.desc=i),s!==void 0&&(a.iconUrl=s);return}let d={};r!==void 0&&(d.count=r),i!==void 0&&(d.desc=i),s!==void 0&&(d.icon_url=s),await this.http.patch(`/conversations/${this.getConversationId()}/inventory/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,d)}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 removeBatch(e){if(this.isPreview){for(let{group:t,name:n}of e)this.mem[t]&&delete this.mem[t][n];return}e.length!==0&&await this.http.post(`/conversations/${this.getConversationId()}/inventory/batch-delete`,{items:e})}async move(e){let{fromGroup:t,toGroup:n,name:r,newName:i}=e;if(this.isPreview){let s=this.mem[t];if(!s||!(r in s))throw new Error(`Source item "${t}/${r}" not found`);if(!this.mem[n])throw new Error(`Target group "${n}" does not exist`);let d=i||r;if(t===n&&d===r)return;if(d in this.mem[n])throw new Error(`Item "${d}" already exists in target group`);this.mem[n][d]=s[r],delete s[r];return}await this.http.post(`/conversations/${this.getConversationId()}/inventory/move`,{fromGroup:t,toGroup:n,name:r,newName:i})}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 i=this.mem[e];if(i&&Object.keys(i).length>0&&!n)throw new Error(`Group "${e}" is not empty, pass cascade: true to force delete`);delete this.mem[e];return}let r=n?"?cascade=true":"";await this.http.delete(`/conversations/${this.getConversationId()}/inventory/groups/${encodeURIComponent(e)}${r}`)}};var j=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}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 ve=class{constructor(e,t,n=!1,r){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem={};r&&(this.mem={...r})}setInitial(e){this.mem=e?{...e}:{}}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})}async remove(e,t){if(t.length){if(this.isPreview){let n=this.mem[e];if(n)for(let r of t)delete n[r];return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,removeKeys:t})}}async removeGroup(e){if(this.isPreview){delete this.mem[e];return}await this.http.patch(`/conversations/${this.getConversationId()}/player/state`,{group:e,removeGroup:!0})}},K=class{constructor(e,t,n=!1,r,i){this.http=e;this.getConversationId=t;this.isPreview=n;this.memPersona={name:""};r&&(this.memPersona={...r}),this.state=new ve(e,t,n,i)}setInitial(e,t){this.memPersona=e?{...e}:{name:""},this.state.setInitial(t)}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)}};function q(o,e){if(!e)return o;let t=o.includes("?")?"&":"?";return`${o}${t}game_id=${encodeURIComponent(e)}`}var z=class{constructor(e,t,n,r=!1,i,s){this.http=e;this.getConversationId=t;this.getGameId=n;this.isPreview=r;this.mem={};this.memInject={};i&&(this.mem=qe(i)),s&&(this.memInject={...s})}setInitial(e,t){this.mem=e?qe(e):{},this.memInject=t?{...t}:{}}async get(e){if(this.isPreview)return e!==void 0?this.mem[e]:{...this.mem};let t=await this.http.get(q(`/conversations/${this.getConversationId()}/custom`,this.getGameId()));return e!==void 0?t[e]:t}async set(e,t){if(this.isPreview){for(let[r,i]of Object.entries(e))typeof i=="object"&&i!==null&&typeof this.mem[r]=="object"&&this.mem[r]!==null?this.mem[r]={...this.mem[r],...i}:this.mem[r]=i,t?.inject!==void 0&&(this.memInject[r]=t.inject);return}let n=t?.inject!==void 0?{data:e,inject:t.inject}:e;await this.http.patch(q(`/conversations/${this.getConversationId()}/custom`,this.getGameId()),n)}async setInject(e,t){if(this.isPreview){this.memInject[e]=t;return}await this.http.patch(q(`/conversations/${this.getConversationId()}/custom/inject/${encodeURIComponent(e)}`,this.getGameId()),{inject:t})}getInject(){return{...this.memInject}}async delete(e){if(this.isPreview){delete this.mem[e],delete this.memInject[e];return}await this.http.delete(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}`,this.getGameId()))}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(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,this.getGameId()),{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(q(`/conversations/${this.getConversationId()}/custom/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,this.getGameId()))}};function qe(o){let e={};for(let[t,n]of Object.entries(o))typeof n=="object"&&n!==null&&!Array.isArray(n)?e[t]={...n}:e[t]=n;return e}function ze(o,e){if(!e)return o;let t=o.includes("?")?"&":"?";return`${o}${t}game_id=${encodeURIComponent(e)}`}var Y=class{constructor(e,t,n,r=!1,i){this.http=e;this.getConversationId=t;this.getGameId=n;this.isPreview=r;this.mem={};i&&(this.mem={...i})}setInitial(e){this.mem=e?{...e}:{}}async get(){return this.isPreview?{...this.mem}:await this.http.get(ze(`/conversations/${this.getConversationId()}/save`,this.getGameId()))}async set(e){if(this.isPreview){this.mem={...e};return}await this.http.put(ze(`/conversations/${this.getConversationId()}/save`,this.getGameId()),e)}};var Q=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n}async get(){if(this.isPreview)throw new g("NOT_SUPPORTED_IN_PREVIEW","storvia.state.get() is not available in preview mode. Publish the game and test on the Storvia platform. (Use per-module get() like storvia.world.get() if you need to inspect state during preview.)");return this.http.get(`/conversations/${this.getConversationId()}/state`)}};var Z=class{constructor(e,t,n=!1){this.http=e;this.getConversationId=t;this.isPreview=n;this.mem=null;this.wb=null;this.worldbook={get:async()=>this.isPreview?this.wb?Ye(this.wb):null:(await this.http.get(`/conversations/${this.getConversationId()}/worldbook`)).worldbook,update:async e=>{let t=typeof e=="string"?{content:e}:{...e};if(t.content!==void 0&&(t.content=(t.content??"").trim()),t.entries!==void 0&&(t.entries=yt(t.entries)),this.isPreview){let r=this.wb?.presets??[],i=t.enabledPresets?r.map(d=>({...d,enabled:t.enabledPresets.includes(d.id)})):r,s={content:t.content??this.wb?.content??"",entries:t.entries??this.wb?.entries??[],presets:i,updated_at:new Date().toISOString()};return this.wb=s,Ye(s)}return(await this.http.patch(`/conversations/${this.getConversationId()}/worldbook`,t)).worldbook}}}async get(){return this.isPreview?this.mem?{...this.mem}:null:(await this.http.get(`/conversations/${this.getConversationId()}/summary`)).ai_summary}async update(e){let t=(e??"").trim();if(this.isPreview){let r={content:t,updated_at:new Date().toISOString()};return this.mem=r,{...r}}return(await this.http.patch(`/conversations/${this.getConversationId()}/summary`,{content:t})).ai_summary}};function Ye(o){return{...o,entries:o.entries.map(e=>({...e,keys:[...e.keys]})),presets:(o.presets??[]).map(e=>({...e}))}}function yt(o){return(o??[]).flatMap(e=>{let t=(e?.content??"").trim(),n=[...new Set((e?.keys??[]).map(r=>(r??"").trim()).filter(r=>r!==""))];return!t||n.length===0?[]:[{id:e.id||Tt(),keys:n,content:t}]})}function Tt(){let o=globalThis.crypto;return o?.randomUUID?o.randomUUID():`ewr-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var Ie=60,Ee=1e3,ce=1e4,A=class{constructor(e,t=!1,n=()=>Date.now()){this.send=e;this.isPreview=t;this.now=n;this.lastNotifyAt=0;this.lastRefreshAt=0;this.lastRefreshMessagesAt=0}notify(e){let t=wt(e);if(!t)return!1;let n=this.now();return n-this.lastNotifyAt<Ee?!1:(this.lastNotifyAt=n,this.isPreview?(ee(t,"info"),!0):(this.send(T("host-notify",{text:t})),!0))}refreshPanel(e){if(this.isPreview)return!1;let t=this.now();return t-this.lastRefreshAt<ce?!1:(this.lastRefreshAt=t,this.send(T("host-state-changed",e?.length?{scope:e}:{})),!0)}refreshMessages(){if(this.isPreview)return!1;let e=this.now();return e-this.lastRefreshMessagesAt<ce?!1:(this.lastRefreshMessagesAt=e,this.send(T("host-messages-changed",{})),!0)}};function wt(o){return typeof o!="string"?"":o.replace(/\s+/g," ").trim().slice(0,Ie)}var Qe="/functions/v1/world-engine/v1",Ct="https://api.storvia.ai";function Rt(){return window.__STORVIA__||{}}function _t(o,e=3e4){let t=Rt();return t.apiBase?Promise.resolve(t):new Promise((n,r)=>{let i=setTimeout(()=>{s(),d(),r(new g("NOT_INITIALIZED","Timed out waiting for __STORVIA__ config from parent frame."))},e),s=o.on("init",a=>{a.payload?.apiBase&&c({apiBase:a.payload.apiBase,gameId:a.payload.gameId,conversationId:a.payload.conversationId,accessToken:a.payload.accessToken,selectedModelId:a.payload.selectedModelId,lang:a.payload.lang,debug:a.payload.debug})}),d=o.on("preview-init",a=>{a.payload?.apiBase&&c(a.payload)});function c(a){clearTimeout(i),s(),d();let l=window;l.__STORVIA__=a,n(a)}o.send(T("ready",{}))})}var ne=class{constructor(){this.baseUrl="";this.gameId="";this.conversationId="";this.modelId="";this.models=[];this.presetId="";this.accessToken="";this.initialized=!1;this.isPreview=!1;this.previewConfig=void 0}async init(){if(this.initialized)return;let e=window.flutter_inappwebview,t=typeof e?.callHandler=="function";this.bus=new x({incoming:window,outgoing:()=>t?null:window.parent,verifySource:t?l=>l.source===null||l.source===window:l=>l.source===window.parent,customSend:t?l=>e.callHandler("storviaBus",l):void 0}),Le(l=>this.bus.send(l));let n=await _t(this.bus),r=n.apiBase;if(!r)throw new g("NOT_INITIALIZED","window.__STORVIA__.apiBase is not set. The platform must inject it before SDK init.");if(this.baseUrl=`${r}${Qe}`,this.isPreview=!!n.preview,this.previewConfig=n.previewConfig,!n.gameId)throw new g("GAME_NOT_FOUND","window.__STORVIA__.gameId is not set. The platform must inject it before SDK init.");if(this.gameId=n.gameId,!n.accessToken)throw new g("UNAUTHORIZED","window.__STORVIA__.accessToken is not set. The platform must inject the user token before SDK init.");if(this.accessToken=n.accessToken,Ae(n.lang),this.http=new te(this.baseUrl,this.accessToken,!!n.debug),this.isPreview){this.conversationId="00000000-0000-0000-0000-000000000000",this.models=n.models??[],this.modelId=n.selectedModelId||this.models[0]?.id||"";let[l,u]=await Promise.all([this.fetchPreviewSnapshot(),this.modelId?Promise.resolve(null):this.fetchModels()]);u&&(this.models=u,this.modelId=u[0]?.id||""),this.presetId=n.presetId||"";let f=()=>this.gameId,m=()=>this.conversationId,h=()=>this.modelId,C=()=>this.models.find(I=>I.id===this.modelId)?.name,y=()=>this.presetId||void 0;this.chat=new V(this.http,f,m,h,!0,this.previewConfig,C,y),this.characters=new H(this.http,m,!0,l?.characters,l?.characterStates),this.relationships=new W(this.http,m,!0,l?.relationships),this.inventory=new B(this.http,m,!0,l?.inventory),this.world=new j(this.http,m,!0,l?.world),this.player=new K(this.http,m,!0,l?.player,l?.playerState),this.custom=new z(this.http,m,f,!0,l?.custom,l?.custom_inject),this.save=new Y(this.http,m,f,!0,l?.save_data),this.state=new Q(this.http,m,!0),this.memory=new Z(this.http,m,!0),this.host=new A(I=>this.bus.send(I),!0),this.initialized=!0,this.listenForPreviewMessages(),this.listenForTokenUpdate();return}if(!n.conversationId)throw new g("NOT_INITIALIZED","window.__STORVIA__.conversationId is not set. The platform must inject it before SDK init.");this.conversationId=n.conversationId,this.modelId=n.selectedModelId||"",this.modelId||(this.models=await this.fetchModels(),this.modelId=this.models[0]?.id||""),this.presetId=n.presetId||"";let i=()=>this.gameId,s=()=>this.conversationId,d=()=>this.modelId,c=()=>this.models.find(l=>l.id===this.modelId)?.name,a=()=>this.presetId||void 0;this.chat=new V(this.http,i,s,d,!1,void 0,c,a),this.characters=new H(this.http,s),this.relationships=new W(this.http,s),this.inventory=new B(this.http,s),this.world=new j(this.http,s),this.player=new K(this.http,s),this.custom=new z(this.http,s,i),this.save=new Y(this.http,s,i),this.state=new Q(this.http,s),this.memory=new Z(this.http,s),this.host=new A(l=>this.bus.send(l),!1),this.listenForTokenUpdate(),this.listenForModelChange(),this.initialized=!0}listenForModelChange(){this.bus.on("set-model",e=>{let t=e.payload?.modelId||"";t&&(this.modelId=t)}),this.bus.on("set-preset",e=>{this.presetId=e.payload?.presetId||""})}listenForTokenUpdate(){this.bus.on("token-update",e=>{let t=e.payload?.accessToken;typeof t!="string"||!t||(this.accessToken=t,this.http?.setToken(t))})}listenForPreviewMessages(){this.bus.on("set-model",e=>{this.modelId=e.payload.modelId||""}),this.bus.on("set-preset",e=>{this.presetId=e.payload?.presetId||""}),this.bus.on("config-update",e=>{this.previewConfig=e.payload.previewConfig,this.chat&&this.chat.updatePreviewConfig(this.previewConfig),this.refreshPreviewSnapshot().catch(t=>{console.warn("[Storvia SDK] refreshPreviewSnapshot failed:",t)})})}async fetchPreviewSnapshot(){try{let e={game_id:this.gameId};return this.previewConfig&&("game_config"in this.previewConfig&&(e.game_config=this.previewConfig.game_config),"game_state"in this.previewConfig&&(e.game_state_override=this.previewConfig.game_state)),await this.http.post("/preview/initial-snapshot",e)}catch(e){return console.warn("[Storvia SDK] fetchPreviewSnapshot failed:",e),null}}async refreshPreviewSnapshot(){let e=await this.fetchPreviewSnapshot();e&&(this.characters?.setInitial(e.characters,e.characterStates),this.player?.setInitial(e.player,e.playerState),this.inventory?.setInitial(e.inventory),this.relationships?.setInitial(e.relationships),this.world?.setInitial(e.world),this.custom?.setInitial(e.custom,e.custom_inject),this.save?.setInitial(e.save_data))}async fetchModels(){try{return await this.http.get("/models")}catch{}return[]}async initDev(e){if(this.initialized)return;this.baseUrl=`${Ct}${Qe}`,this.gameId=e.gameId,this.isPreview=!0,this.http=new te(this.baseUrl,"",!1,e.apiKey);let[t,n]=await Promise.all([this.fetchModels(),this.fetchPreviewSnapshot()]);this.models=t;let r=e.model?t.find(l=>l.name===e.model)?.id??"":"";this.modelId=r||t[0]?.id||"",this.conversationId="00000000-0000-0000-0000-000000000000";let i=()=>this.gameId,s=()=>this.conversationId,d=()=>this.modelId,c=()=>this.models.find(l=>l.id===this.modelId)?.name;this.presetId=e.preset||"";let a=()=>this.presetId||void 0;this.chat=new V(this.http,i,s,d,!0,void 0,c,a),this.characters=new H(this.http,s,!0,n?.characters,n?.characterStates),this.relationships=new W(this.http,s,!0,n?.relationships),this.inventory=new B(this.http,s,!0,n?.inventory),this.world=new j(this.http,s,!0,n?.world),this.player=new K(this.http,s,!0,n?.player,n?.playerState),this.custom=new z(this.http,s,i,!0,n?.custom,n?.custom_inject),this.save=new Y(this.http,s,i,!0,n?.save_data),this.state=new Q(this.http,s,!0),this.memory=new Z(this.http,s,!0),this.host=new A(()=>{},!0),this.initialized=!0}async getAssets(e,t){let n={asset_type:e};return t&&(n.category=t),(await this.http.get("/assets",n)).map(i=>({id:i.id,name:i.name,url:i.url,assetType:i.asset_type,category:i.category}))}};async function Ze(o){ke();let e=new ne;return o?.dev?await e.initDev(o.dev):await e.init(),e}function ye(o){return typeof o=="object"&&o!==null&&"value"in o&&"type"in o&&(o.type==="number"||o.type==="text")}function Xe(o){return ye(o)?o.value:o}0&&(module.exports={HOST_NOTIFY_MAX_LENGTH,HOST_NOTIFY_MIN_INTERVAL_MS,HOST_PANEL_SCOPES,HOST_REFRESH_MIN_INTERVAL_MS,HostModule,MAIN_CHAT_TOPIC,PROTOCOL_VERSION,StorviaBus,StorviaError,StorviaSDK,createStorviaSDK,envelope,extractFieldValue,isProtocolEnvelope,isRichFieldValue,setToastEnabled,showToast});
package/dist/index.d.mts CHANGED
@@ -11,10 +11,21 @@ interface ExtendWorldRuleEntry {
11
11
  keys: string[];
12
12
  content: string;
13
13
  }
14
- /** 世界书:content 常驻(每轮注入 <CustomRules>)+ entries 关键词触发(命中才注入 <ExtendWorldRules>) */
14
+ /** 预设世界书(创作台「世界书」)在玩家侧的形状:只有标题 / 简介 / 开关,正文永不下发 */
15
+ interface PresetWorldbookView {
16
+ id: string;
17
+ title: string;
18
+ description: string;
19
+ enabled: boolean;
20
+ }
21
+ /**
22
+ * 世界书:content 常驻(每轮注入 <CustomRules>)+ entries 关键词触发(命中才注入 <ExtendWorldRules>)
23
+ * + presets 预设世界书清单(开启的无条件注入 <ExtendWorldRules>)
24
+ */
15
25
  interface Worldbook {
16
26
  content: string;
17
27
  entries: ExtendWorldRuleEntry[];
28
+ presets: PresetWorldbookView[];
18
29
  /** ISO 时间戳;从未设置过为 null */
19
30
  updated_at: string | null;
20
31
  }
@@ -22,6 +33,8 @@ interface Worldbook {
22
33
  interface WorldbookPatch {
23
34
  content?: string;
24
35
  entries?: ExtendWorldRuleEntry[];
36
+ /** 玩家开启的预设世界书 id 列表(整体替换;不在作品清单里的 id 会被服务端丢弃) */
37
+ enabledPresets?: string[];
25
38
  }
26
39
  interface AssetItem {
27
40
  id: number;
@@ -604,6 +617,14 @@ declare class HttpClient {
604
617
  private handleResponseWithRaw;
605
618
  }
606
619
 
620
+ /**
621
+ * 主线(宿主聊天页)消息的 topic。主站 / App 聊天页写的消息全在这个 topic 下。
622
+ *
623
+ * SDK 各方法**不传 topic 时落的是 `topic = NULL`,不是主线**;`messages()` / `send()` 历史
624
+ * 不传 topic 则不过滤(主线 + 所有支线混在一起)。小组件要往主线写 / 读主线消息,
625
+ * 必须显式传 `topic: MAIN_CHAT_TOPIC`。与服务端 `_shared/chat/message-versions.ts` 同值。
626
+ */
627
+ declare const MAIN_CHAT_TOPIC = "storvia_chat_main";
607
628
  declare class ChatModule {
608
629
  private http;
609
630
  private getGameId;
@@ -625,7 +646,7 @@ declare class ChatModule {
625
646
  */
626
647
  send(options: ChatSendOptions): Promise<ChatResponse | void>;
627
648
  /**
628
- * 单独保存一条消息(不调 AI,不扣费)
649
+ * 单独保存一条消息(不调 AI,不扣费,也不计作品互动数——互动只给 send / once 这类真实付费的生成)
629
650
  * 适用于群聊中先保存用户消息,再分别请求各 NPC 回复
630
651
  */
631
652
  save(options: ChatSaveOptions): Promise<{
@@ -634,6 +655,7 @@ declare class ChatModule {
634
655
  /**
635
656
  * 基于 topic 历史 + scene_key 请求 AI 生成回复(无需当前轮用户输入)
636
657
  * 适用于群聊 NPC 回复、NPC 自动发言、弹幕生成等
658
+ * 正常扣费并计一次作品互动(与 `send()` / `once()` 同口径)
637
659
  */
638
660
  generate(options: ChatGenerateOptions): Promise<ChatResponse | void>;
639
661
  /**
@@ -644,7 +666,9 @@ declare class ChatModule {
644
666
  * AI 调用(翻译、格式重写、按模板拼装文本)会污染主线面板。`once()` 是唯一干净的那条。
645
667
  *
646
668
  * - 不占 topic 锁、也不走 beginGeneration:同一会话可以并发发起多个 `once()`,目前无并发上限
647
- * - 正常扣费;结果只返回给调用方,要不要落库由调用方用 `save()` / `edit()` 自行决定
669
+ * - 记忆只注入永久记忆(`storvia.memory` 写的那份);动态 / 长期记忆与世界书不参与
670
+ * - 正常扣费、正常给作者分成,并计入作品互动数(与 `send()` 同口径);
671
+ * 结果只返回给调用方,要不要落库由调用方用 `save()` / `edit()` 自行决定(`save()` 不计互动,不会重复)
648
672
  * - 预览模式下走 `/preview`(不带历史),返回结构一致
649
673
  */
650
674
  once(options: ChatOnceOptions): Promise<ChatOnceResponse>;
@@ -960,6 +984,7 @@ declare class StateModule {
960
984
  * - worldbook.get / worldbook.update:世界书,分两档——
961
985
  * content:常驻,每轮注入 <CustomRules>,当「必须遵循的规则 / 设定」用
962
986
  * entries:关键词触发,任一关键词命中「本轮输入 + 上一轮 AI 回复」才注入 <ExtendWorldRules>
987
+ * presets:预设世界书清单(作品作者写的可选设定,玩家只看到标题 / 简介),用 enabledPresets 按条开启
963
988
  * update 是部分更新:传字符串 = 只改 content;传对象只改传了的键,没传的保留原值
964
989
  *
965
990
  * 预览模式下保存在 SDK 内存中,不打后端。
@@ -1121,12 +1146,18 @@ interface HostNotifyPayload {
1121
1146
  interface HostStateChangedPayload {
1122
1147
  scope?: HostPanelScope[];
1123
1148
  }
1149
+ /**
1150
+ * 子 → 父:小组件往主线写过 / 改过消息(`chat.save` / `chat.edit` / `chat.delete` 带
1151
+ * `topic: MAIN_CHAT_TOPIC`),请求宿主重拉主线消息列表。
1152
+ * 无 payload:宿主恒重拉主线最新一页,已有 uuid 替换内容、新 uuid 追加。
1153
+ */
1154
+ type HostMessagesChangedPayload = Record<string, never>;
1124
1155
  interface AckPayload {
1125
1156
  ok: boolean;
1126
1157
  error?: string;
1127
1158
  }
1128
1159
  type DownstreamMsg = ProtocolEnvelope<'init', InitPayload> | ProtocolEnvelope<'preview-init', PreviewInitPayload> | ProtocolEnvelope<'token-update', TokenUpdatePayload> | ProtocolEnvelope<'config-update', ConfigUpdatePayload> | ProtocolEnvelope<'set-model', SetModelPayload> | ProtocolEnvelope<'set-preset', SetPresetPayload> | ProtocolEnvelope<'orientation', OrientationPayload> | ProtocolEnvelope<'ack', AckPayload>;
1129
- type UpstreamMsg = ProtocolEnvelope<'ready', ReadyPayload> | ProtocolEnvelope<'exit', Record<string, never>> | ProtocolEnvelope<'request-orientation', OrientationPayload> | ProtocolEnvelope<'error', SdkErrorPayload> | ProtocolEnvelope<'navigate', NavigatePayload> | ProtocolEnvelope<'model-change', SetModelPayload> | ProtocolEnvelope<'host-notify', HostNotifyPayload> | ProtocolEnvelope<'host-state-changed', HostStateChangedPayload> | ProtocolEnvelope<'ack', AckPayload>;
1160
+ type UpstreamMsg = ProtocolEnvelope<'ready', ReadyPayload> | ProtocolEnvelope<'exit', Record<string, never>> | ProtocolEnvelope<'request-orientation', OrientationPayload> | ProtocolEnvelope<'error', SdkErrorPayload> | ProtocolEnvelope<'navigate', NavigatePayload> | ProtocolEnvelope<'model-change', SetModelPayload> | ProtocolEnvelope<'host-notify', HostNotifyPayload> | ProtocolEnvelope<'host-state-changed', HostStateChangedPayload> | ProtocolEnvelope<'host-messages-changed', HostMessagesChangedPayload> | ProtocolEnvelope<'ack', AckPayload>;
1130
1161
  declare function isProtocolEnvelope(data: unknown): data is ProtocolEnvelope<string, unknown>;
1131
1162
  declare function envelope<T extends string, P>(type: T, payload: P, opts?: {
1132
1163
  id?: string;
@@ -1203,9 +1234,10 @@ declare class StorviaBus<TIn extends AnyEnvelope, TOut extends AnyEnvelope> {
1203
1234
  /**
1204
1235
  * 小组件 → 主线(宿主聊天页)的联动通道。
1205
1236
  *
1206
- * 两个能力都只发 postMessage 信号,不打后端:
1207
- * - [notify] 主线弹一条 toast(仅小组件**后台运行**时展示,前台时宿主静默丢弃)
1208
- * - [refreshPanel] 主线重拉 game_state 刷新游戏面板
1237
+ * 三个能力都只发 postMessage 信号,不打后端:
1238
+ * - [notify] 主线弹一条 toast(仅小组件**后台运行**时展示,前台时宿主静默丢弃)
1239
+ * - [refreshPanel] 主线重拉 game_state 刷新游戏面板
1240
+ * - [refreshMessages] 主线重拉消息列表(小组件用 `chat.save` / `chat.edit` 动过主线消息后调)
1209
1241
  *
1210
1242
  * 面板能刷出内容的前提:小组件与主线**共享** player / characters / inventory /
1211
1243
  * relationships / world 这几块状态(`sdk.player` / `sdk.characters` / `sdk.inventory` /
@@ -1219,13 +1251,14 @@ declare class StorviaBus<TIn extends AnyEnvelope, TOut extends AnyEnvelope> {
1219
1251
  */
1220
1252
  declare const HOST_NOTIFY_MAX_LENGTH = 60;
1221
1253
  /**
1222
- * 两次 toast / 两次面板刷新的最小间隔。
1254
+ * 两次 toast / 两次面板刷新 / 两次消息列表刷新的最小间隔。
1223
1255
  * 这里只是第一道(省一次 postMessage),宿主侧还会独立再拦一道 —— 作者能绕过 SDK
1224
1256
  * 直接 postMessage,节流的权威判定必须在宿主。
1225
1257
  *
1226
1258
  * 两个值差两个数量级是因为代价不同:notify 纯前端(发一条消息、宿主渲染一条 toast,
1227
1259
  * toast 在宿主侧纵向堆叠不会互相覆盖),卡 1s 只为防刷屏;refreshPanel 每次都会让
1228
- * 宿主重拉一次会话详情,是真实后端请求,必须卡住。
1260
+ * 宿主重拉一次会话详情,是真实后端请求,必须卡住。refreshMessages 同理,与 refreshPanel
1261
+ * 同档但各自独立计时(写状态和写消息常常一起做,共用窗口会让第二个必然被挡)。
1229
1262
  */
1230
1263
  declare const HOST_NOTIFY_MIN_INTERVAL_MS = 1000;
1231
1264
  declare const HOST_REFRESH_MIN_INTERVAL_MS = 10000;
@@ -1236,6 +1269,7 @@ declare class HostModule {
1236
1269
  private now;
1237
1270
  private lastNotifyAt;
1238
1271
  private lastRefreshAt;
1272
+ private lastRefreshMessagesAt;
1239
1273
  constructor(send: (msg: UpstreamMsg) => void, isPreview?: boolean,
1240
1274
  /** 注入时间源,便于测试;生产恒 Date.now */
1241
1275
  now?: () => number);
@@ -1257,6 +1291,15 @@ declare class HostModule {
1257
1291
  * 预览模式下主线面板不存在,直接 no-op 返回 false。
1258
1292
  */
1259
1293
  refreshPanel(scope?: HostPanelScope[]): boolean;
1294
+ /**
1295
+ * 请求主线重拉消息列表(用 `chat.save` / `chat.edit` / `chat.delete` 动过主线消息后调)。
1296
+ *
1297
+ * 只有写进主线 topic(`MAIN_CHAT_TOPIC`)的消息才会出现在主线聊天页;小组件自己支线的
1298
+ * 消息刷了也看不到。宿主重拉主线最新一页:已有 uuid 替换内容、新 uuid 追加。
1299
+ * 返回是否真的发出去了:距上次不足 [HOST_REFRESH_MIN_INTERVAL_MS] 时返回 false。
1300
+ * 预览模式下主线不存在,直接 no-op 返回 false。
1301
+ */
1302
+ refreshMessages(): boolean;
1260
1303
  }
1261
1304
 
1262
1305
  interface DevConfig {
@@ -1353,4 +1396,4 @@ interface ToastAction {
1353
1396
  */
1354
1397
  declare function showToast(message: string, type?: ToastType, duration?: number, action?: ToastAction): void;
1355
1398
 
1356
- export { type AISummary, type AckPayload, type AssetItem, type CharacterAddOptions, type CharacterDetail, type CharacterPersona, type CharacterUpdateOptions, type ChatAbortInfo, type ChatAbortedCallback, type ChatCancelOptions, type ChatCancelResult, type ChatContinueOptions, type ChatDoneCallback, type ChatDoneInfo, type ChatGenerateOptions, type ChatMessage, type ChatMessageCursor, type ChatMessagesOptions, type ChatMessagesResponse, type ChatReconnectingCallback, type ChatResponse, type ChatResumeOptions, type ChatRetryOptions, type ChatSaveOptions, type ChatSendOptions, type ChatStateCallback, type ConfigUpdatePayload, type CurrentState, type DormantState, type DownstreamMsg, type ExtendWorldRuleEntry, type FieldValue, type Gender, HOST_NOTIFY_MAX_LENGTH, HOST_NOTIFY_MIN_INTERVAL_MS, HOST_PANEL_SCOPES, HOST_REFRESH_MIN_INTERVAL_MS, HostModule, type HostNotifyPayload, type HostPanelScope, type HostStateChangedPayload, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, type OrientationPayload, PROTOCOL_VERSION, type PlayerPersona, type PreviewConfig, type PreviewInitPayload, type ProtocolEnvelope, type ReadyPayload, type Relationship, type RichFieldValue, type SdkErrorPayload, type SetModelPayload, type State, type StateChanges, StorviaBus, type StorviaBusOptions, StorviaError, type StorviaErrorCode, StorviaSDK, type TokenUpdatePayload, type UpstreamMsg, type Worldbook, type WorldbookPatch, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };
1399
+ export { type AISummary, type AckPayload, type AssetItem, type CharacterAddOptions, type CharacterDetail, type CharacterPersona, type CharacterUpdateOptions, type ChatAbortInfo, type ChatAbortedCallback, type ChatCancelOptions, type ChatCancelResult, type ChatContinueOptions, type ChatDoneCallback, type ChatDoneInfo, type ChatGenerateOptions, type ChatMessage, type ChatMessageCursor, type ChatMessagesOptions, type ChatMessagesResponse, type ChatReconnectingCallback, type ChatResponse, type ChatResumeOptions, type ChatRetryOptions, type ChatSaveOptions, type ChatSendOptions, type ChatStateCallback, type ConfigUpdatePayload, type CurrentState, type DormantState, type DownstreamMsg, type ExtendWorldRuleEntry, type FieldValue, type Gender, HOST_NOTIFY_MAX_LENGTH, HOST_NOTIFY_MIN_INTERVAL_MS, HOST_PANEL_SCOPES, HOST_REFRESH_MIN_INTERVAL_MS, type HostMessagesChangedPayload, HostModule, type HostNotifyPayload, type HostPanelScope, type HostStateChangedPayload, type InitPayload, type InventoryAddOptions, type InventoryMoveOptions, type InventoryRemoveGroupOptions, type InventoryRemoveOptions, type InventoryState, type InventoryUpdateOptions, type ItemData, MAIN_CHAT_TOPIC, type OrientationPayload, PROTOCOL_VERSION, type PlayerPersona, type PresetWorldbookView, type PreviewConfig, type PreviewInitPayload, type ProtocolEnvelope, type ReadyPayload, type Relationship, type RichFieldValue, type SdkErrorPayload, type SetModelPayload, type State, type StateChanges, StorviaBus, type StorviaBusOptions, StorviaError, type StorviaErrorCode, StorviaSDK, type TokenUpdatePayload, type UpstreamMsg, type Worldbook, type WorldbookPatch, createStorviaSDK, envelope, extractFieldValue, isProtocolEnvelope, isRichFieldValue, setToastEnabled, showToast };