@tbox.cn/tboxcode-dsh-llm 0.1.0-rc.4 → 0.1.0-rc.5
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/lib/echo.js +1 -1
- package/lib/index.d.ts +82 -1
- package/lib/index.js +24 -24
- package/package.json +3 -3
package/lib/echo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{LlmAdapter as e}from"@deepseek-ai/dsh-llm";const t=`tboxcode-llm-echo`,n=[`llm`];function r(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.role!==`user`||!Array.isArray(n.content))continue;let r=n.content.filter(e=>e?.type===`text`&&!e.text.includes(`<system-reminder>`)).map(e=>e.text).join(`
|
|
2
|
-
`).trim();if(r.length>0)return r}}function i(e,t){let n=e.
|
|
2
|
+
`).trim();if(r.length>0)return r}}function i(e,t){let n=e.match(/\S+\s*/g);if(n===null)return[e];let r=[];for(let e=0;e<n.length;e+=t)r.push(n.slice(e,e+t).join(``));return r}async function a(e,t){e<=0||await new Promise((n,r)=>{let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(t.reason)},{once:!0})})}var o=class extends e{#e;#t;constructor(e={}){super(),this.#e=e.delayMs??30,this.#t=Math.max(1,Math.trunc(e.chunkWords??1))}listModels(e){return Promise.resolve([{provider:e,id:`echo`,name:`Echo`,description:`echo driver——确定性回显(测试与流式收口)`,inputModalities:[`text`]}])}async resolveModel(e,t){return{provider:e,id:t,name:t,context:{contextWindow:128e3}}}async*stream(e){let t=r(e.messages)??`echo`,n=i(t,this.#t);yield{type:`block-start`,index:0,blockType:`text`};for(let t of n)await a(this.#e,e.signal),yield{type:`text-delta`,index:0,text:t};yield{type:`block-end`,index:0,block:{type:`text`,text:t}},yield{type:`usage`,usage:{inputTokens:1,outputTokens:n.length}},yield{type:`finish`,reason:{kind:`stop`}}}};function s(e,t={}){let n=new o(t),r=e.llm.registerAdapter([`echo`],n);return()=>{r()}}export{o as EchoAdapter,s as apply,n as inject,t as name};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
2
3
|
|
|
4
|
+
//#region src/core/schema.d.ts
|
|
5
|
+
|
|
6
|
+
declare const ModelTraitsSchema: z.ZodObject<{
|
|
7
|
+
protocol: z.ZodEnum<{
|
|
8
|
+
openai: "openai";
|
|
9
|
+
"openai-compatible": "openai-compatible";
|
|
10
|
+
anthropic: "anthropic";
|
|
11
|
+
}>;
|
|
12
|
+
provider_name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
upstream_model: z.ZodOptional<z.ZodString>;
|
|
14
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
field: z.ZodOptional<z.ZodEnum<{
|
|
16
|
+
reasoning: "reasoning";
|
|
17
|
+
reasoning_content: "reasoning_content";
|
|
18
|
+
reasoning_details: "reasoning_details";
|
|
19
|
+
}>>;
|
|
20
|
+
interleaved: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
summary: z.ZodOptional<z.ZodLiteral<"auto">>;
|
|
22
|
+
include: z.ZodOptional<z.ZodLiteral<"encrypted">>;
|
|
23
|
+
effort: z.ZodOptional<z.ZodObject<{
|
|
24
|
+
default: z.ZodOptional<z.ZodString>;
|
|
25
|
+
levels: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
name: z.ZodOptional<z.ZodString>;
|
|
28
|
+
description: z.ZodOptional<z.ZodString>;
|
|
29
|
+
body: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
30
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
template: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, z.core.$loose>>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
image: z.ZodOptional<z.ZodEnum<{
|
|
36
|
+
url: "url";
|
|
37
|
+
base64: "base64";
|
|
38
|
+
}>>;
|
|
39
|
+
image_max_bytes: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
image_max_images: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
image_byte_quantum: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
image_count_quantum: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
request_max_bytes: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
image_max_pixels: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
image_max_aspect_ratio: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
cache: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"none">, z.ZodLiteral<"anthropic">, z.ZodLiteral<"openai-compatible">, z.ZodLiteral<"bedrock">, z.ZodObject<{
|
|
47
|
+
mode: z.ZodEnum<{
|
|
48
|
+
automatic: "automatic";
|
|
49
|
+
explicit: "explicit";
|
|
50
|
+
}>;
|
|
51
|
+
ttl: z.ZodEnum<{
|
|
52
|
+
"5m": "5m";
|
|
53
|
+
"1h": "1h";
|
|
54
|
+
}>;
|
|
55
|
+
scope: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
56
|
+
system: "system";
|
|
57
|
+
tools: "tools";
|
|
58
|
+
messages: "messages";
|
|
59
|
+
}>>>;
|
|
60
|
+
}, z.core.$strip>]>>;
|
|
61
|
+
limit: z.ZodObject<{
|
|
62
|
+
context: z.ZodNumber;
|
|
63
|
+
output: z.ZodNumber;
|
|
64
|
+
idle_timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
body: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
67
|
+
body_templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
68
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
69
|
+
when: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
reasoning: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
reasoning_keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
72
|
+
}, z.core.$strip>>;
|
|
73
|
+
quirks: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
74
|
+
"ensure-assistant-reasoning": "ensure-assistant-reasoning";
|
|
75
|
+
"scrub-tool-call-id": "scrub-tool-call-id";
|
|
76
|
+
"done-after-tool": "done-after-tool";
|
|
77
|
+
"drop-empty-content": "drop-empty-content";
|
|
78
|
+
}>>>;
|
|
79
|
+
}, z.core.$loose>;
|
|
80
|
+
type ModelTraits = z.infer<typeof ModelTraitsSchema>;
|
|
81
|
+
/** box/模型目录消费名:与 dsh traits 同一形状(单一事实源)。 */
|
|
82
|
+
type TboxcodeDshModelTraits = ModelTraits;
|
|
83
|
+
//#endregion
|
|
3
84
|
//#region src/index.d.ts
|
|
4
85
|
declare const name = "tboxcode-llm";
|
|
5
86
|
declare const inject: string[];
|
|
@@ -10,4 +91,4 @@ declare const inject: string[];
|
|
|
10
91
|
*/
|
|
11
92
|
declare function apply(ctx: Context): () => void;
|
|
12
93
|
//#endregion
|
|
13
|
-
export { apply, inject, name };
|
|
94
|
+
export { type TboxcodeDshModelTraits, apply, inject, name };
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{c as e,l as t,n,u as r}from"./call-log-UkoWWuyZ.js";import{createRequire as i}from"node:module";import{createHash as a,randomBytes as o}from"node:crypto";import{rm as s,writeFile as c}from"node:fs/promises";import{join as l}from"node:path";import{IMAGE_OFFLOAD_REQUIRED_CODE as u,LlmAdapter as d,LlmError as f,ProviderRequestId as p,attributionHeaders as m,contentHasImage as h,offloadedImageText as g,projectOffloadedImages as _,requestImageHandleText as v,requiredImageOffload as y,resolveImageAttachmentAccess as b,resolveRetryPolicy as x}from"@deepseek-ai/dsh-llm";import{existsSync as S,readFileSync as C,statSync as w,watch as T}from"node:fs";import{ZodError as E,z as D}from"zod";import{homedir as
|
|
2
|
-
`)}};a.defaultYaml={explicit:!1,version:`1.2`},a.defaultTags={"!!":`tag:yaml.org,2002:`},e.Directives=a})),
|
|
1
|
+
import{c as e,l as t,n,u as r}from"./call-log-UkoWWuyZ.js";import{createRequire as i}from"node:module";import{createHash as a,randomBytes as o}from"node:crypto";import{rm as s,writeFile as c}from"node:fs/promises";import{join as l}from"node:path";import{IMAGE_OFFLOAD_REQUIRED_CODE as u,LlmAdapter as d,LlmError as f,ProviderRequestId as p,attributionHeaders as m,contentHasImage as h,offloadedImageText as g,projectOffloadedImages as _,requestImageHandleText as v,requiredImageOffload as y,resolveImageAttachmentAccess as b,resolveRetryPolicy as x}from"@deepseek-ai/dsh-llm";import{existsSync as S,readFileSync as C,statSync as w,watch as T}from"node:fs";import{ZodError as E,z as D}from"zod";import{homedir as ee}from"node:os";import{jsonSchema as te,streamText as ne,tool as re}from"ai";import{createAnthropic as ie}from"@ai-sdk/anthropic";import{createOpenAICompatible as O}from"@ai-sdk/openai-compatible";import{createOpenAI as k}from"@ai-sdk/openai";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),j=i(import.meta.url),M=A((e=>{let t=Symbol.for(`yaml.alias`),n=Symbol.for(`yaml.document`),r=Symbol.for(`yaml.map`),i=Symbol.for(`yaml.pair`),a=Symbol.for(`yaml.scalar`),o=Symbol.for(`yaml.seq`),s=Symbol.for(`yaml.node.type`),c=e=>!!e&&typeof e==`object`&&e[s]===t,l=e=>!!e&&typeof e==`object`&&e[s]===n,u=e=>!!e&&typeof e==`object`&&e[s]===r,d=e=>!!e&&typeof e==`object`&&e[s]===i,f=e=>!!e&&typeof e==`object`&&e[s]===a,p=e=>!!e&&typeof e==`object`&&e[s]===o;function m(e){if(e&&typeof e==`object`)switch(e[s]){case r:case o:return!0}return!1}function h(e){if(e&&typeof e==`object`)switch(e[s]){case t:case r:case a:case o:return!0}return!1}e.ALIAS=t,e.DOC=n,e.MAP=r,e.NODE_TYPE=s,e.PAIR=i,e.SCALAR=a,e.SEQ=o,e.hasAnchor=e=>(f(e)||m(e))&&!!e.anchor,e.isAlias=c,e.isCollection=m,e.isDocument=l,e.isMap=u,e.isNode=h,e.isPair=d,e.isScalar=f,e.isSeq=p})),N=A((e=>{var t=M();let n=Symbol(`break visit`),r=Symbol(`skip children`),i=Symbol(`remove node`);function a(e,n){let r=l(n);t.isDocument(e)?o(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):o(null,e,r,Object.freeze([]))}a.BREAK=n,a.SKIP=r,a.REMOVE=i;function o(e,r,a,s){let c=u(e,r,a,s);if(t.isNode(c)||t.isPair(c))return d(e,s,c),o(e,c,a,s);if(typeof c!=`symbol`){if(t.isCollection(r)){s=Object.freeze(s.concat(r));for(let e=0;e<r.items.length;++e){let t=o(e,r.items[e],a,s);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){s=Object.freeze(s.concat(r));let e=o(`key`,r.key,a,s);if(e===n)return n;e===i&&(r.key=null);let t=o(`value`,r.value,a,s);if(t===n)return n;t===i&&(r.value=null)}}return c}async function s(e,n){let r=l(n);t.isDocument(e)?await c(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):await c(null,e,r,Object.freeze([]))}s.BREAK=n,s.SKIP=r,s.REMOVE=i;async function c(e,r,a,o){let s=await u(e,r,a,o);if(t.isNode(s)||t.isPair(s))return d(e,o,s),c(e,s,a,o);if(typeof s!=`symbol`){if(t.isCollection(r)){o=Object.freeze(o.concat(r));for(let e=0;e<r.items.length;++e){let t=await c(e,r.items[e],a,o);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){o=Object.freeze(o.concat(r));let e=await c(`key`,r.key,a,o);if(e===n)return n;e===i&&(r.key=null);let t=await c(`value`,r.value,a,o);if(t===n)return n;t===i&&(r.value=null)}}return s}function l(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function u(e,n,r,i){if(typeof r==`function`)return r(e,n,i);if(t.isMap(n))return r.Map?.(e,n,i);if(t.isSeq(n))return r.Seq?.(e,n,i);if(t.isPair(n))return r.Pair?.(e,n,i);if(t.isScalar(n))return r.Scalar?.(e,n,i);if(t.isAlias(n))return r.Alias?.(e,n,i)}function d(e,n,r){let i=n[n.length-1];if(t.isCollection(i))i.items[e]=r;else if(t.isPair(i))e===`key`?i.key=r:i.value=r;else if(t.isDocument(i))i.contents=r;else{let e=t.isAlias(i)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}e.visit=a,e.visitAsync=s})),P=A((e=>{var t=M(),n=N();let r={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},i=e=>e.replace(/[!,[\]{}]/g,e=>r[e]);var a=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags);break}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+i(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let r=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],i=Object.entries(this.tags),a;if(e&&i.length>0&&t.isNode(e.contents)){let r={};n.visit(e.contents,(e,n)=>{t.isNode(n)&&n.tag&&(r[n.tag]=!0)}),a=Object.keys(r)}else a=[];for(let[t,n]of i)t===`!!`&&n===`tag:yaml.org,2002:`||(!e||a.some(e=>e.startsWith(n)))&&r.push(`%TAG ${t} ${n}`);return r.join(`
|
|
2
|
+
`)}};a.defaultYaml={explicit:!1,version:`1.2`},a.defaultTags={"!!":`tag:yaml.org,2002:`},e.Directives=a})),F=A((e=>{var t=M(),n=N();function r(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function i(e){let t=new Set;return n.visit(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function a(e,t){for(let n=1;;++n){let r=`${e}${n}`;if(!t.has(r))return r}}function o(e,n){let r=[],o=new Map,s=null;return{onAnchor:t=>{r.push(t),s??=i(e);let o=a(n,s);return s.add(o),o},setAnchors:()=>{for(let e of r){let n=o.get(e);if(typeof n==`object`&&n.anchor&&(t.isScalar(n.node)||t.isCollection(n.node)))n.node.anchor=n.anchor;else{let t=Error(`Failed to resolve repeated object (this should not happen)`);throw t.source=e,t}}},sourceObjects:o}}e.anchorIsValid=r,e.anchorNames=i,e.createNodeAnchors=o,e.findNewAnchor=a})),I=A((e=>{function t(e,n,r,i){if(i&&typeof i==`object`)if(Array.isArray(i))for(let n=0,r=i.length;n<r;++n){let r=i[n],a=t(e,i,String(n),r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}else if(i instanceof Map)for(let n of Array.from(i.keys())){let r=i.get(n),a=t(e,i,n,r);a===void 0?i.delete(n):a!==r&&i.set(n,a)}else if(i instanceof Set)for(let n of Array.from(i)){let r=t(e,i,n,n);r===void 0?i.delete(n):r!==n&&(i.delete(n),i.add(r))}else for(let[n,r]of Object.entries(i)){let a=t(e,i,n,r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}return e.call(n,r,i)}e.applyReviver=t})),L=A((e=>{var t=M();function n(e,r,i){if(Array.isArray(e))return e.map((e,t)=>n(e,String(t),i));if(e&&typeof e.toJSON==`function`){if(!i||!t.hasAnchor(e))return e.toJSON(r,i);let n={aliasCount:0,count:1,res:void 0};i.anchors.set(e,n),i.onCreate=e=>{n.res=e,delete i.onCreate};let a=e.toJSON(r,i);return i.onCreate&&i.onCreate(a),a}return typeof e==`bigint`&&!i?.keep?Number(e):e}e.toJS=n})),R=A((e=>{var t=I(),n=M(),r=L();e.NodeBase=class{constructor(e){Object.defineProperty(this,n.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:i,maxAliasCount:a,onAnchor:o,reviver:s}={}){if(!n.isDocument(e))throw TypeError(`A document argument is required`);let c={anchors:new Map,doc:e,keep:!0,mapAsMap:i===!0,mapKeyWarned:!1,maxAliasCount:typeof a==`number`?a:100},l=r.toJS(this,``,c);if(typeof o==`function`)for(let{count:e,res:t}of c.anchors.values())o(t,e);return typeof s==`function`?t.applyReviver(s,{"":l},``,l):l}}})),z=A((e=>{var t=F(),n=N(),r=M(),i=R(),a=L(),o=class extends i.NodeBase{constructor(e){super(r.ALIAS),this.source=e,Object.defineProperty(this,`tag`,{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let i;t?.aliasResolveCache?i=t.aliasResolveCache:(i=[],n.visit(e,{Node:(e,t)=>{(r.isAlias(t)||r.hasAnchor(t))&&i.push(t)}}),t&&(t.aliasResolveCache=i));let o;for(let e of i){if(e===this)break;e.anchor===this.source&&(o=e)}if(o&&t){let{anchors:e,doc:n,maxAliasCount:r}=t,i=e.get(o);if(i||=(a.toJS(o,null,t),e.get(o)),i?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(r>=0&&(i.count+=1,i.aliasCount===0&&(i.aliasCount=s(n,o,e)),i.count*i.aliasCount>r))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return o}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,n,r){let i=`*${this.source}`;if(e){if(t.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${i} `}return i}};function s(e,t,n){if(r.isAlias(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}else if(r.isCollection(t)){let r=0;for(let i of t.items){let t=s(e,i,n);t>r&&(r=t)}return r}else if(r.isPair(t)){let r=s(e,t.key,n),i=s(e,t.value,n);return Math.max(r,i)}return 1}e.Alias=o})),B=A((e=>{var t=M(),n=R(),r=L();let i=e=>!e||typeof e!=`function`&&typeof e!=`object`;var a=class extends n.NodeBase{constructor(e){super(t.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:r.toJS(this.value,e,t)}toString(){return String(this.value)}};a.BLOCK_FOLDED=`BLOCK_FOLDED`,a.BLOCK_LITERAL=`BLOCK_LITERAL`,a.PLAIN=`PLAIN`,a.QUOTE_DOUBLE=`QUOTE_DOUBLE`,a.QUOTE_SINGLE=`QUOTE_SINGLE`,e.Scalar=a,e.isScalarValue=i})),V=A((e=>{var t=z(),n=M(),r=B();function i(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function a(e,a,o){if(n.isDocument(e)&&(e=e.contents),n.isNode(e))return e;if(n.isPair(e)){let t=o.schema[n.MAP].createNode?.(o.schema,null,o);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:s,onAnchor:c,onTagObj:l,schema:u,sourceObjects:d}=o,f;if(s&&e&&typeof e==`object`){if(f=d.get(e),f)return f.anchor??=c(e),new t.Alias(f.anchor);f={anchor:null,node:null},d.set(e,f)}a?.startsWith(`!!`)&&(a=`tag:yaml.org,2002:`+a.slice(2));let p=i(e,a,u.tags);if(!p){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new r.Scalar(e);return f&&(f.node=t),t}p=e instanceof Map?u[n.MAP]:Symbol.iterator in Object(e)?u[n.SEQ]:u[n.MAP]}l&&(l(p),delete o.onTagObj);let m=p?.createNode?p.createNode(o.schema,e,o):typeof p?.nodeClass?.from==`function`?p.nodeClass.from(o.schema,e,o):new r.Scalar(e);return a?m.tag=a:p.default||(m.tag=p.tag),f&&(f.node=m),m}e.createNode=a})),ae=A((e=>{var t=V(),n=M(),r=R();function i(e,n,r){let i=r;for(let e=n.length-1;e>=0;--e){let t=n[e];if(typeof t==`number`&&Number.isInteger(t)&&t>=0){let e=[];e[t]=i,i=e}else i=new Map([[t,i]])}return t.createNode(i,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error(`This should not happen, please report a bug.`)},schema:e,sourceObjects:new Map})}let a=e=>e==null||typeof e==`object`&&!!e[Symbol.iterator]().next().done;e.Collection=class extends r.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,`schema`,{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(t=>n.isNode(t)||n.isPair(t)?t.clone(e):t),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(a(e))this.add(t);else{let[r,...a]=e,o=this.get(r,!0);if(n.isCollection(o))o.addIn(a,t);else if(o===void 0&&this.schema)this.set(r,i(this.schema,a,t));else throw Error(`Expected YAML collection at ${r}. Remaining path: ${a}`)}}deleteIn(e){let[t,...r]=e;if(r.length===0)return this.delete(t);let i=this.get(t,!0);if(n.isCollection(i))return i.deleteIn(r);throw Error(`Expected YAML collection at ${t}. Remaining path: ${r}`)}getIn(e,t){let[r,...i]=e,a=this.get(r,!0);return i.length===0?!t&&n.isScalar(a)?a.value:a:n.isCollection(a)?a.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!n.isPair(t))return!1;let r=t.value;return r==null||e&&n.isScalar(r)&&r.value==null&&!r.commentBefore&&!r.comment&&!r.tag})}hasIn(e){let[t,...r]=e;if(r.length===0)return this.has(t);let i=this.get(t,!0);return n.isCollection(i)?i.hasIn(r):!1}setIn(e,t){let[r,...a]=e;if(a.length===0)this.set(r,t);else{let e=this.get(r,!0);if(n.isCollection(e))e.setIn(a,t);else if(e===void 0&&this.schema)this.set(r,i(this.schema,a,t));else throw Error(`Expected YAML collection at ${r}. Remaining path: ${a}`)}}},e.collectionFromPath=i,e.isEmptyPath=a})),oe=A((e=>{let t=e=>e.replace(/^(?!$)(?: $)?/gm,`#`);function n(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}e.indentComment=n,e.lineComment=(e,t,r)=>e.endsWith(`
|
|
3
3
|
`)?n(r,t):r.includes(`
|
|
4
4
|
`)?`
|
|
5
|
-
`+n(r,t):(e.endsWith(` `)?``:` `)+r,e.stringifyComment=t})),
|
|
5
|
+
`+n(r,t):(e.endsWith(` `)?``:` `)+r,e.stringifyComment=t})),se=A((e=>{let t=`block`,n=`quoted`;function r(e,r,a=`flow`,{indentAtStart:o,lineWidth:s=80,minContentWidth:c=20,onFold:l,onOverflow:u}={}){if(!s||s<0)return e;s<c&&(c=0);let d=Math.max(1+c,1+s-r.length);if(e.length<=d)return e;let f=[],p={},m=s-r.length;typeof o==`number`&&(o>s-Math.max(2,c)?f.push(0):m=s-o);let h,g,_=!1,v=-1,y=-1,b=-1;a===t&&(v=i(e,v,r.length),v!==-1&&(m=v+d));for(let o;o=e[v+=1];){if(a===n&&o===`\\`){switch(y=v,e[v+1]){case`x`:v+=3;break;case`u`:v+=5;break;case`U`:v+=9;break;default:v+=1}b=v}if(o===`
|
|
6
6
|
`)a===t&&(v=i(e,v,r.length)),m=v+r.length+d,h=void 0;else{if(o===` `&&g&&g!==` `&&g!==`
|
|
7
7
|
`&&g!==` `){let t=e[v+1];t&&t!==` `&&t!==`
|
|
8
8
|
`&&t!==` `&&(h=v)}if(v>=m)if(h)f.push(h),m=h+d,h=void 0;else if(a===n){for(;g===` `||g===` `;)g=o,o=e[v+=1],_=!0;let t=v>b+1?v-2:y-1;if(p[t])return e;f.push(t),p[t]=!0,m=t+d,h=void 0}else _=!0}g=o}if(_&&u&&u(),f.length===0)return e;l&&l();let x=e.slice(0,f[0]);for(let t=0;t<f.length;++t){let i=f[t],o=f[t+1]||e.length;i===0?x=`\n${r}${e.slice(0,o)}`:(a===n&&p[i]&&(x+=`${e[i]}\\`),x+=`\n${r}${e.slice(i+1,o)}`)}return x}function i(e,t,n){let r=t,i=t+1,a=e[i];for(;a===` `||a===` `;)if(t<i+n)a=e[++t];else{do a=e[++t];while(a&&a!==`
|
|
9
|
-
`);r=t,i=t+1,a=e[i]}return r}e.FOLD_BLOCK=t,e.FOLD_FLOW=`flow`,e.FOLD_QUOTED=n,e.foldFlowLines=r})),
|
|
9
|
+
`);r=t,i=t+1,a=e[i]}return r}e.FOLD_BLOCK=t,e.FOLD_FLOW=`flow`,e.FOLD_QUOTED=n,e.foldFlowLines=r})),ce=A((e=>{var t=B(),n=se();let r=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),i=e=>/^(%|---|\.\.\.)/m.test(e);function a(e,t,n){if(!t||t<0)return!1;let r=t-n,i=e.length;if(i<=r)return!1;for(let t=0,n=0;t<i;++t)if(e[t]===`
|
|
10
10
|
`){if(t-n>r)return!0;if(n=t+1,i-n<=r)return!1}return!0}function o(e,t){let a=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return a;let{implicitKey:o}=t,s=t.options.doubleQuotedMinMultiLineLength,c=t.indent||(i(e)?` `:``),l=``,u=0;for(let e=0,t=a[e];t;t=a[++e])if(t===` `&&a[e+1]===`\\`&&a[e+2]===`n`&&(l+=a.slice(u,e)+`\\ `,e+=1,u=e,t=`\\`),t===`\\`)switch(a[e+1]){case`u`:{l+=a.slice(u,e);let t=a.substr(e+2,4);switch(t){case`0000`:l+=`\\0`;break;case`0007`:l+=`\\a`;break;case`000b`:l+=`\\v`;break;case`001b`:l+=`\\e`;break;case`0085`:l+=`\\N`;break;case`00a0`:l+=`\\_`;break;case`2028`:l+=`\\L`;break;case`2029`:l+=`\\P`;break;default:t.substr(0,2)===`00`?l+=`\\x`+t.substr(2):l+=a.substr(e,6)}e+=5,u=e+1}break;case`n`:if(o||a[e+2]===`"`||a.length<s)e+=1;else{for(l+=a.slice(u,e)+`
|
|
11
11
|
|
|
12
12
|
`;a[e+2]===`\\`&&a[e+3]===`n`&&a[e+4]!==`"`;)l+=`
|
|
@@ -24,29 +24,29 @@ import{c as e,l as t,n,u as r}from"./call-log-UkoWWuyZ.js";import{createRequire
|
|
|
24
24
|
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\n+/g,`$&${g}`),i=!1,a=r(u,!0);p!==`folded`&&o!==t.Scalar.BLOCK_FOLDED&&(a.onOverflow=()=>{i=!0});let c=n.foldFlowLines(`${T}${e}${b}`,g,n.FOLD_BLOCK,a);if(!i)return`>${E}\n${g}${c}`}return s=s.replace(/\n+/g,`$&${g}`),`|${E}\n${g}${T}${s}${b}`}function d(e,a,o,s){let{type:l,value:d}=e,{actualString:f,implicitKey:p,indent:m,indentStep:h,inFlow:g}=a;if(p&&d.includes(`
|
|
25
25
|
`)||g&&/[[\]{},]/.test(d))return c(d,a);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(d))return p||g||!d.includes(`
|
|
26
26
|
`)?c(d,a):u(e,a,o,s);if(!p&&!g&&l!==t.Scalar.PLAIN&&d.includes(`
|
|
27
|
-
`))return u(e,a,o,s);if(i(d)){if(m===``)return a.forceBlockIndent=!0,u(e,a,o,s);if(p&&m===h)return c(d,a)}let _=d.replace(/\n+/g,`$&\n${m}`);if(f){let e=e=>e.default&&e.tag!==`tag:yaml.org,2002:str`&&e.test?.test(_),{compat:t,tags:n}=a.doc.schema;if(n.some(e)||t?.some(e))return c(d,a)}return p?_:n.foldFlowLines(_,m,n.FOLD_FLOW,r(a,!1))}function f(e,n,r,i){let{implicitKey:a,inFlow:l}=n,f=typeof e.value==`string`?e:Object.assign({},e,{value:String(e.value)}),{type:p}=e;p!==t.Scalar.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(f.value)&&(p=t.Scalar.QUOTE_DOUBLE);let m=e=>{switch(e){case t.Scalar.BLOCK_FOLDED:case t.Scalar.BLOCK_LITERAL:return a||l?c(f.value,n):u(f,n,r,i);case t.Scalar.QUOTE_DOUBLE:return o(f.value,n);case t.Scalar.QUOTE_SINGLE:return s(f.value,n);case t.Scalar.PLAIN:return d(f,n,r,i);default:return null}},h=m(p);if(h===null){let{defaultKeyType:e,defaultStringType:t}=n.options,r=a&&e||t;if(h=m(r),h===null)throw Error(`Unsupported default string type ${r}`)}return h}e.stringifyString=f})),
|
|
27
|
+
`))return u(e,a,o,s);if(i(d)){if(m===``)return a.forceBlockIndent=!0,u(e,a,o,s);if(p&&m===h)return c(d,a)}let _=d.replace(/\n+/g,`$&\n${m}`);if(f){let e=e=>e.default&&e.tag!==`tag:yaml.org,2002:str`&&e.test?.test(_),{compat:t,tags:n}=a.doc.schema;if(n.some(e)||t?.some(e))return c(d,a)}return p?_:n.foldFlowLines(_,m,n.FOLD_FLOW,r(a,!1))}function f(e,n,r,i){let{implicitKey:a,inFlow:l}=n,f=typeof e.value==`string`?e:Object.assign({},e,{value:String(e.value)}),{type:p}=e;p!==t.Scalar.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(f.value)&&(p=t.Scalar.QUOTE_DOUBLE);let m=e=>{switch(e){case t.Scalar.BLOCK_FOLDED:case t.Scalar.BLOCK_LITERAL:return a||l?c(f.value,n):u(f,n,r,i);case t.Scalar.QUOTE_DOUBLE:return o(f.value,n);case t.Scalar.QUOTE_SINGLE:return s(f.value,n);case t.Scalar.PLAIN:return d(f,n,r,i);default:return null}},h=m(p);if(h===null){let{defaultKeyType:e,defaultStringType:t}=n.options,r=a&&e||t;if(h=m(r),h===null)throw Error(`Unsupported default string type ${r}`)}return h}e.stringifyString=f})),le=A((e=>{var t=F(),n=M(),r=oe(),i=ce();function a(e,t){let n=Object.assign({blockQuote:!0,commentString:r.stringifyComment,defaultKeyType:null,defaultStringType:`PLAIN`,directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:`false`,flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:`null`,simpleKeys:!1,singleQuote:null,trailingComma:!1,trueStr:`true`,verifyAliasOrder:!0},e.schema.toStringOptions,t),i;switch(n.collectionStyle){case`block`:i=!1;break;case`flow`:i=!0;break;default:i=null}return{anchors:new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?` `:``,indent:``,indentStep:typeof n.indent==`number`?` `.repeat(n.indent):` `,inFlow:i,options:n}}function o(e,t){if(t.tag){let n=e.filter(e=>e.tag===t.tag);if(n.length>0)return n.find(e=>e.format===t.format)??n[0]}let r,i;if(n.isScalar(t)){i=t.value;let n=e.filter(e=>e.identify?.(i));if(n.length>1){let e=n.filter(e=>e.test);e.length>0&&(n=e)}r=n.find(e=>e.format===t.format)??n.find(e=>!e.format)}else i=t,r=e.find(e=>e.nodeClass&&i instanceof e.nodeClass);if(!r){let e=i?.constructor?.name??(i===null?`null`:typeof i);throw Error(`Tag not resolved for ${e} value`)}return r}function s(e,r,{anchors:i,doc:a}){if(!a.directives)return``;let o=[],s=(n.isScalar(e)||n.isCollection(e))&&e.anchor;s&&t.anchorIsValid(s)&&(i.add(s),o.push(`&${s}`));let c=e.tag??(r.default?null:r.tag);return c&&o.push(a.directives.tagString(c)),o.join(` `)}function c(e,t,r,a){if(n.isPair(e))return e.toString(t,r,a);if(n.isAlias(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw TypeError(`Cannot stringify circular structure without alias nodes`);t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=new Set([e]),e=e.resolve(t.doc)}let c,l=n.isNode(e)?e:t.doc.createNode(e,{onTagObj:e=>c=e});c??=o(t.doc.schema.tags,l);let u=s(l,c,t);u.length>0&&(t.indentAtStart=(t.indentAtStart??0)+u.length+1);let d=typeof c.stringify==`function`?c.stringify(l,t,r,a):n.isScalar(l)?i.stringifyString(l,t,r,a):l.toString(t,r,a);return u?n.isScalar(l)||d[0]===`{`||d[0]===`[`?`${u} ${d}`:`${u}\n${t.indent}${d}`:d}e.createStringifyContext=a,e.stringify=c})),ue=A((e=>{var t=M(),n=B(),r=le(),i=oe();function a({key:e,value:a},o,s,c){let{allNullValues:l,doc:u,indent:d,indentStep:f,options:{commentString:p,indentSeq:m,simpleKeys:h}}=o,g=t.isNode(e)&&e.comment||null;if(h){if(g)throw Error(`With simple keys, key nodes cannot have comments`);if(t.isCollection(e)||!t.isNode(e)&&typeof e==`object`)throw Error(`With simple keys, collection cannot be used as a key value`)}let _=!h&&(!e||g&&a==null&&!o.inFlow||t.isCollection(e)||(t.isScalar(e)?e.type===n.Scalar.BLOCK_FOLDED||e.type===n.Scalar.BLOCK_LITERAL:typeof e==`object`));o=Object.assign({},o,{allNullValues:!1,implicitKey:!_&&(h||!l),indent:d+f});let v=!1,y=!1,b=r.stringify(e,o,()=>v=!0,()=>y=!0);if(!_&&!o.inFlow&&b.length>1024){if(h)throw Error(`With simple keys, single line scalar must not span more than 1024 characters`);_=!0}if(o.inFlow){if(l||a==null)return v&&s&&s(),b===``?`?`:_?`? ${b}`:b}else if(l&&!h||a==null&&_)return b=`? ${b}`,g&&!v?b+=i.lineComment(b,o.indent,p(g)):y&&c&&c(),b;v&&(g=null),_?(g&&(b+=i.lineComment(b,o.indent,p(g))),b=`? ${b}\n${d}:`):(b=`${b}:`,g&&(b+=i.lineComment(b,o.indent,p(g))));let x,S,C;t.isNode(a)?(x=!!a.spaceBefore,S=a.commentBefore,C=a.comment):(x=!1,S=null,C=null,a&&typeof a==`object`&&(a=u.createNode(a))),o.implicitKey=!1,!_&&!g&&t.isScalar(a)&&(o.indentAtStart=b.length+1),y=!1,!m&&f.length>=2&&!o.inFlow&&!_&&t.isSeq(a)&&!a.flow&&!a.tag&&!a.anchor&&(o.indent=o.indent.substring(2));let w=!1,T=r.stringify(a,o,()=>w=!0,()=>y=!0),E=` `;if(g||x||S){if(E=x?`
|
|
28
28
|
`:``,S){let e=p(S);E+=`\n${i.indentComment(e,o.indent)}`}T===``&&!o.inFlow?E===`
|
|
29
29
|
`&&C&&(E=`
|
|
30
30
|
|
|
31
31
|
`):E+=`\n${o.indent}`}else if(!_&&t.isCollection(a)){let e=T[0],t=T.indexOf(`
|
|
32
32
|
`),n=t!==-1,r=o.inFlow??a.flow??a.items.length===0;if(n||!r){let r=!1;if(n&&(e===`&`||e===`!`)){let n=T.indexOf(` `);e===`&`&&n!==-1&&n<t&&T[n+1]===`!`&&(n=T.indexOf(` `,n+1)),(n===-1||t<n)&&(r=!0)}r||(E=`\n${o.indent}`)}}else (T===``||T[0]===`
|
|
33
|
-
`)&&(E=``);return b+=E+T,o.inFlow?w&&s&&s():C&&!w?b+=i.lineComment(b,o.indent,p(C)):y&&c&&c(),b}e.stringifyPair=a})),
|
|
33
|
+
`)&&(E=``);return b+=E+T,o.inFlow?w&&s&&s():C&&!w?b+=i.lineComment(b,o.indent,p(C)):y&&c&&c(),b}e.stringifyPair=a})),de=A((e=>{var t=j(`process`);function n(e,...t){e===`debug`&&console.log(...t)}function r(e,n){(e===`debug`||e===`warn`)&&(typeof t.emitWarning==`function`?t.emitWarning(n):console.warn(n))}e.debug=n,e.warn=r})),fe=A((e=>{var t=M(),n=B();let r={identify:e=>e===`<<`||typeof e==`symbol`&&e.description===`<<`,default:`key`,tag:`tag:yaml.org,2002:merge`,test:/^<<$/,resolve:()=>Object.assign(new n.Scalar(Symbol(`<<`)),{addToJSMap:a}),stringify:()=>`<<`},i=(e,i)=>(r.identify(i)||t.isScalar(i)&&(!i.type||i.type===n.Scalar.PLAIN)&&r.identify(i.value))&&e?.doc.schema.tags.some(e=>e.tag===r.tag&&e.default);function a(e,n,r){let i=s(e,r);if(t.isSeq(i))for(let t of i.items)o(e,n,t);else if(Array.isArray(i))for(let t of i)o(e,n,t);else o(e,n,i)}function o(e,n,r){let i=s(e,r);if(!t.isMap(i))throw Error(`Merge sources must be maps or map aliases`);let a=i.toJSON(null,e,Map);for(let[e,t]of a)n instanceof Map?n.has(e)||n.set(e,t):n instanceof Set?n.add(e):Object.prototype.hasOwnProperty.call(n,e)||Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0});return n}function s(e,n){return e&&t.isAlias(n)?n.resolve(e.doc,e):n}e.addMergeToJSMap=a,e.isMergeKey=i,e.merge=r})),pe=A((e=>{var t=de(),n=fe(),r=le(),i=M(),a=L();function o(e,t,{key:r,value:o}){if(i.isNode(r)&&r.addToJSMap)r.addToJSMap(e,t,o);else if(n.isMergeKey(e,r))n.addMergeToJSMap(e,t,o);else{let n=a.toJS(r,``,e);if(t instanceof Map)t.set(n,a.toJS(o,n,e));else if(t instanceof Set)t.add(n);else{let i=s(r,n,e),c=a.toJS(o,i,e);i in t?Object.defineProperty(t,i,{value:c,writable:!0,enumerable:!0,configurable:!0}):t[i]=c}}return t}function s(e,n,a){if(n===null)return``;if(typeof n!=`object`)return String(n);if(i.isNode(e)&&a?.doc){let n=r.createStringifyContext(a.doc,{});n.anchors=new Set;for(let e of a.anchors.keys())n.anchors.add(e.anchor);n.inFlow=!0,n.inStringifyKey=!0;let i=e.toString(n);if(!a.mapKeyWarned){let e=JSON.stringify(i);e.length>40&&(e=e.substring(0,36)+`..."`),t.warn(a.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${e}. Set mapAsMap: true to use object keys.`),a.mapKeyWarned=!0}return i}return JSON.stringify(n)}e.addPairToJSMap=o})),H=A((e=>{var t=V(),n=ue(),r=pe(),i=M();function a(e,n,r){return new o(t.createNode(e,void 0,r),t.createNode(n,void 0,r))}var o=class e{constructor(e,t=null){Object.defineProperty(this,i.NODE_TYPE,{value:i.PAIR}),this.key=e,this.value=t}clone(t){let{key:n,value:r}=this;return i.isNode(n)&&(n=n.clone(t)),i.isNode(r)&&(r=r.clone(t)),new e(n,r)}toJSON(e,t){let n=t?.mapAsMap?new Map:{};return r.addPairToJSMap(t,n,this)}toString(e,t,r){return e?.doc?n.stringifyPair(this,e,t,r):JSON.stringify(this)}};e.Pair=o,e.createPair=a})),me=A((e=>{var t=M(),n=le(),r=oe();function i(e,t,n){return(t.inFlow??e.flow?o:a)(e,t,n)}function a({comment:e,items:i},a,{blockItemPrefix:o,flowChars:c,itemIndent:l,onChompKeep:u,onComment:d}){let{indent:f,options:{commentString:p}}=a,m=Object.assign({},a,{indent:l,type:null}),h=!1,g=[];for(let e=0;e<i.length;++e){let c=i[e],u=null;if(t.isNode(c))!h&&c.spaceBefore&&g.push(``),s(a,g,c.commentBefore,h),c.comment&&(u=c.comment);else if(t.isPair(c)){let e=t.isNode(c.key)?c.key:null;e&&(!h&&e.spaceBefore&&g.push(``),s(a,g,e.commentBefore,h))}h=!1;let d=n.stringify(c,m,()=>u=null,()=>h=!0);u&&(d+=r.lineComment(d,l,p(u))),h&&u&&(h=!1),g.push(o+d)}let _;if(g.length===0)_=c.start+c.end;else{_=g[0];for(let e=1;e<g.length;++e){let t=g[e];_+=t?`\n${f}${t}`:`
|
|
34
34
|
`}}return e?(_+=`
|
|
35
35
|
`+r.indentComment(p(e),f),d&&d()):h&&u&&u(),_}function o({items:e},i,{flowChars:a,itemIndent:o}){let{indent:c,indentStep:l,flowCollectionPadding:u,options:{commentString:d}}=i;o+=l;let f=Object.assign({},i,{indent:o,inFlow:!0,type:null}),p=!1,m=0,h=[];for(let a=0;a<e.length;++a){let c=e[a],l=null;if(t.isNode(c))c.spaceBefore&&h.push(``),s(i,h,c.commentBefore,!1),c.comment&&(l=c.comment);else if(t.isPair(c)){let e=t.isNode(c.key)?c.key:null;e&&(e.spaceBefore&&h.push(``),s(i,h,e.commentBefore,!1),e.comment&&(p=!0));let n=t.isNode(c.value)?c.value:null;n?(n.comment&&(l=n.comment),n.commentBefore&&(p=!0)):c.value==null&&e?.comment&&(l=e.comment)}l&&(p=!0);let u=n.stringify(c,f,()=>l=null);p||=h.length>m||u.includes(`
|
|
36
36
|
`),a<e.length-1?u+=`,`:i.options.trailingComma&&(i.options.lineWidth>0&&(p||=h.reduce((e,t)=>e+t.length+2,2)+(u.length+2)>i.options.lineWidth),p&&(u+=`,`)),l&&(u+=r.lineComment(u,o,d(l))),h.push(u),m=h.length}let{start:g,end:_}=a;if(h.length===0)return g+_;if(!p){let e=h.reduce((e,t)=>e+t.length+2,2);p=i.options.lineWidth>0&&e>i.options.lineWidth}if(p){let e=g;for(let t of h)e+=t?`\n${l}${c}${t}`:`
|
|
37
|
-
`;return`${e}\n${c}${_}`}else return`${g}${u}${h.join(` `)}${u}${_}`}function s({indent:e,options:{commentString:t}},n,i,a){if(i&&a&&(i=i.replace(/^\n+/,``)),i){let a=r.indentComment(t(i),e);n.push(a.trimStart())}}e.stringifyCollection=i})),
|
|
38
|
-
`:` `)}return r.stringifyString({comment:e,type:i,value:u},o,s,c)}}})),xe=F((e=>{var t=L(),n=W(),r=U(),i=q();function a(e,i){if(t.isSeq(e))for(let a=0;a<e.items.length;++a){let o=e.items[a];if(!t.isPair(o)){if(t.isMap(o)){o.items.length>1&&i(`Each pair must have its own sequence indicator`);let e=o.items[0]||new n.Pair(new r.Scalar(null));if(o.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${o.commentBefore}\n${e.key.commentBefore}`:o.commentBefore),o.comment){let t=e.value??e.key;t.comment=t.comment?`${o.comment}\n${t.comment}`:o.comment}o=e}e.items[a]=t.isPair(o)?o:new n.Pair(o)}}else i(`Expected a sequence for this tag`);return e}function o(e,t,r){let{replacer:a}=r,o=new i.YAMLSeq(e);o.tag=`tag:yaml.org,2002:pairs`;let s=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof a==`function`&&(e=a.call(t,String(s++),e));let i,c;if(Array.isArray(e))if(e.length===2)i=e[0],c=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`);else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)i=t[0],c=e[i];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else i=e;o.items.push(n.createPair(i,c,r))}return o}let s={collection:`seq`,default:!1,tag:`tag:yaml.org,2002:pairs`,resolve:a,createNode:o};e.createPairs=o,e.pairs=s,e.resolvePairs=a})),Se=F((e=>{var t=L(),n=V(),r=G(),i=q(),a=xe(),o=class e extends i.YAMLSeq{constructor(){super(),this.add=r.YAMLMap.prototype.add.bind(this),this.delete=r.YAMLMap.prototype.delete.bind(this),this.get=r.YAMLMap.prototype.get.bind(this),this.has=r.YAMLMap.prototype.has.bind(this),this.set=r.YAMLMap.prototype.set.bind(this),this.tag=e.tag}toJSON(e,r){if(!r)return super.toJSON(e);let i=new Map;r?.onCreate&&r.onCreate(i);for(let e of this.items){let a,o;if(t.isPair(e)?(a=n.toJS(e.key,``,r),o=n.toJS(e.value,a,r)):a=n.toJS(e,``,r),i.has(a))throw Error(`Ordered maps must not include duplicate keys`);i.set(a,o)}return i}static from(e,t,n){let r=a.createPairs(e,t,n),i=new this;return i.items=r.items,i}};o.tag=`tag:yaml.org,2002:omap`;let s={collection:`seq`,identify:e=>e instanceof Map,nodeClass:o,default:!1,tag:`tag:yaml.org,2002:omap`,resolve(e,n){let r=a.resolvePairs(e,n),i=[];for(let{key:e}of r.items)t.isScalar(e)&&(i.includes(e.value)?n(`Ordered maps must not include duplicate keys: ${e.value}`):i.push(e.value));return Object.assign(new o,r)},createNode:(e,t,n)=>o.from(e,t,n)};e.YAMLOMap=o,e.omap=s})),Ce=F((e=>{var t=U();function n({value:e,source:t},n){return t&&(e?r:i).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}let r={identify:e=>e===!0,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new t.Scalar(!0),stringify:n},i={identify:e=>e===!1,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new t.Scalar(!1),stringify:n};e.falseTag=i,e.trueTag=r})),we=F((e=>{var t=U(),n=Y();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){let n=new t.Scalar(parseFloat(e.replace(/_/g,``))),r=e.indexOf(`.`);if(r!==-1){let t=e.substring(r+1).replace(/_/g,``);t[t.length-1]===`0`&&(n.minFractionDigits=t.length)}return n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,``)),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),Te=F((e=>{var t=Y();let n=e=>typeof e==`bigint`||Number.isInteger(e);function r(e,t,n,{intAsBigInt:r}){let i=e[0];if((i===`-`||i===`+`)&&(t+=1),e=e.substring(t).replace(/_/g,``),r){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`;break}let t=BigInt(e);return i===`-`?BigInt(-1)*t:t}let a=parseInt(e,n);return i===`-`?-1*a:a}function i(e,r,i){let{value:a}=e;if(n(a)){let e=a.toString(r);return a<0?`-`+i+e.substr(1):i+e}return t.stringifyNumber(e)}let a={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`BIN`,test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>r(e,2,2,n),stringify:e=>i(e,2,`0b`)},o={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>r(e,1,8,n),stringify:e=>i(e,8,`0`)},s={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},c={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)};e.int=s,e.intBin=a,e.intHex=c,e.intOct=o})),Ee=F((e=>{var t=L(),n=W(),r=G(),i=class e extends r.YAMLMap{constructor(t){super(t),this.tag=e.tag}add(e){let i;i=t.isPair(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new n.Pair(e.key,null):new n.Pair(e,null),r.findPair(this.items,i.key)||this.items.push(i)}get(e,n){let i=r.findPair(this.items,e);return!n&&t.isPair(i)?t.isScalar(i.key)?i.key.value:i.key:i}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let i=r.findPair(this.items,e);i&&!t?this.items.splice(this.items.indexOf(i),1):!i&&t&&this.items.push(new n.Pair(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,r){let{replacer:i}=r,a=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof i==`function`&&(e=i.call(t,e,e)),a.items.push(n.createPair(e,null,r));return a}};i.tag=`tag:yaml.org,2002:set`;let a={collection:`map`,identify:e=>e instanceof Set,nodeClass:i,default:!1,tag:`tag:yaml.org,2002:set`,createNode:(e,t,n)=>i.from(e,t,n),resolve(e,n){if(t.isMap(e)){if(e.hasAllNullValues(!0))return Object.assign(new i,e);n(`Set items must all have null values`)}else n(`Expected a mapping for this tag`);return e}};e.YAMLSet=i,e.set=a})),De=F((e=>{var t=Y();function n(e,t){let n=e[0],r=n===`-`||n===`+`?e.substring(1):e,i=e=>t?BigInt(e):Number(e),a=r.replace(/_/g,``).split(`:`).reduce((e,t)=>e*i(60)+i(t),i(0));return n===`-`?i(-1)*a:a}function r(e){let{value:n}=e,r=e=>e;if(typeof n==`bigint`)r=e=>BigInt(e);else if(isNaN(n)||!isFinite(n))return t.stringifyNumber(e);let i=``;n<0&&(i=`-`,n*=r(-1));let a=r(60),o=[n%a];return n<60?o.unshift(0):(n=(n-o[0])/a,o.unshift(n%a),n>=60&&(n=(n-o[0])/a,o.unshift(n))),i+o.map(e=>String(e).padStart(2,`0`)).join(`:`).replace(/000000\d*$/,``)}let i={identify:e=>typeof e==`bigint`||Number.isInteger(e),default:!0,tag:`tag:yaml.org,2002:int`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:r})=>n(e,r),stringify:r},a={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>n(e,!1),stringify:r},o={identify:e=>e instanceof Date,default:!0,tag:`tag:yaml.org,2002:timestamp`,test:RegExp(`^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$`),resolve(e){let t=e.match(o.test);if(!t)throw Error(`!!timestamp expects a date, starting with yyyy-mm-dd`);let[,r,i,a,s,c,l]=t.map(Number),u=t[7]?Number((t[7]+`00`).substr(1,3)):0,d=Date.UTC(r,i-1,a,s||0,c||0,l||0,u),f=t[8];if(f&&f!==`Z`){let e=n(f,!1);Math.abs(e)<30&&(e*=60),d-=6e4*e}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,``)??``};e.floatTime=a,e.intTime=i,e.timestamp=o})),Oe=F((e=>{var t=K(),n=me(),r=J(),i=pe(),a=be(),o=Ce(),s=we(),c=Te(),l=ue(),u=Se(),d=xe(),f=Ee(),p=De();e.schema=[t.map,r.seq,i.string,n.nullTag,o.trueTag,o.falseTag,c.intBin,c.intOct,c.int,c.intHex,s.floatNaN,s.floatExp,s.float,a.binary,l.merge,u.omap,d.pairs,f.set,p.intTime,p.floatTime,p.timestamp]})),ke=F((e=>{var t=K(),n=me(),r=J(),i=pe(),a=he(),o=ge(),s=_e(),c=ve(),l=ye(),u=be(),d=ue(),f=Se(),p=xe(),m=Oe(),h=Ee(),g=De();let _=new Map([[`core`,c.schema],[`failsafe`,[t.map,r.seq,i.string]],[`json`,l.schema],[`yaml11`,m.schema],[`yaml-1.1`,m.schema]]),v={binary:u.binary,bool:a.boolTag,float:o.float,floatExp:o.floatExp,floatNaN:o.floatNaN,floatTime:g.floatTime,int:s.int,intHex:s.intHex,intOct:s.intOct,intTime:g.intTime,map:t.map,merge:d.merge,null:n.nullTag,omap:f.omap,pairs:p.pairs,seq:r.seq,set:h.set,timestamp:g.timestamp},y={"tag:yaml.org,2002:binary":u.binary,"tag:yaml.org,2002:merge":d.merge,"tag:yaml.org,2002:omap":f.omap,"tag:yaml.org,2002:pairs":p.pairs,"tag:yaml.org,2002:set":h.set,"tag:yaml.org,2002:timestamp":g.timestamp};function b(e,t,n){let r=_.get(t);if(r&&!e)return n&&!r.includes(d.merge)?r.concat(d.merge):r.slice();let i=r;if(!i)if(Array.isArray(e))i=[];else{let e=Array.from(_.keys()).filter(e=>e!==`yaml11`).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}if(Array.isArray(e))for(let t of e)i=i.concat(t);else typeof e==`function`&&(i=e(i.slice()));return n&&(i=i.concat(d.merge)),i.reduce((e,t)=>{let n=typeof t==`string`?v[t]:t;if(!n){let e=JSON.stringify(t),n=Object.keys(v).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e},[])}e.coreKnownTags=y,e.getTags=b})),Ae=F((e=>{var t=L(),n=K(),r=J(),i=pe(),a=ke();let o=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;e.Schema=class e{constructor({compat:e,customTags:s,merge:c,resolveKnownTags:l,schema:u,sortMapEntries:d,toStringDefaults:f}){this.compat=Array.isArray(e)?a.getTags(e,`compat`):e?a.getTags(null,e):null,this.name=typeof u==`string`&&u||`core`,this.knownTags=l?a.coreKnownTags:{},this.tags=a.getTags(s,this.name,c),this.toStringOptions=f??null,Object.defineProperty(this,t.MAP,{value:n.map}),Object.defineProperty(this,t.SCALAR,{value:i.string}),Object.defineProperty(this,t.SEQ,{value:r.seq}),this.sortMapEntries=typeof d==`function`?d:d===!0?o:null}clone(){let t=Object.create(e.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}})),je=F((e=>{var t=L(),n=se(),r=ie();function i(e,i){let a=[],o=i.directives===!0;if(i.directives!==!1&&e.directives){let t=e.directives.toString(e);t?(a.push(t),o=!0):e.directives.docStart&&(o=!0)}o&&a.push(`---`);let s=n.createStringifyContext(e,i),{commentString:c}=s.options;if(e.commentBefore){a.length!==1&&a.unshift(``);let t=c(e.commentBefore);a.unshift(r.indentComment(t,``))}let l=!1,u=null;if(e.contents){if(t.isNode(e.contents)){if(e.contents.spaceBefore&&o&&a.push(``),e.contents.commentBefore){let t=c(e.contents.commentBefore);a.push(r.indentComment(t,``))}s.forceBlockIndent=!!e.comment,u=e.contents.comment}let i=u?void 0:()=>l=!0,d=n.stringify(e.contents,s,()=>u=null,i);u&&(d+=r.lineComment(d,``,c(u))),(d[0]===`|`||d[0]===`>`)&&a[a.length-1]===`---`?a[a.length-1]=`--- ${d}`:a.push(d)}else a.push(n.stringify(e.contents,s));if(e.directives?.docEnd)if(e.comment){let t=c(e.comment);t.includes(`
|
|
37
|
+
`;return`${e}\n${c}${_}`}else return`${g}${u}${h.join(` `)}${u}${_}`}function s({indent:e,options:{commentString:t}},n,i,a){if(i&&a&&(i=i.replace(/^\n+/,``)),i){let a=r.indentComment(t(i),e);n.push(a.trimStart())}}e.stringifyCollection=i})),U=A((e=>{var t=me(),n=pe(),r=ae(),i=M(),a=H(),o=B();function s(e,t){let n=i.isScalar(t)?t.value:t;for(let r of e)if(i.isPair(r)&&(r.key===t||r.key===n||i.isScalar(r.key)&&r.key.value===n))return r}e.YAMLMap=class extends r.Collection{static get tagName(){return`tag:yaml.org,2002:map`}constructor(e){super(i.MAP,e),this.items=[]}static from(e,t,n){let{keepUndefined:r,replacer:i}=n,o=new this(e),s=(e,s)=>{if(typeof i==`function`)s=i.call(t,e,s);else if(Array.isArray(i)&&!i.includes(e))return;(s!==void 0||r)&&o.items.push(a.createPair(e,s,n))};if(t instanceof Map)for(let[e,n]of t)s(e,n);else if(t&&typeof t==`object`)for(let e of Object.keys(t))s(e,t[e]);return typeof e.sortMapEntries==`function`&&o.items.sort(e.sortMapEntries),o}add(e,t){let n;n=i.isPair(e)?e:!e||typeof e!=`object`||!(`key`in e)?new a.Pair(e,e?.value):new a.Pair(e.key,e.value);let r=s(this.items,n.key),c=this.schema?.sortMapEntries;if(r){if(!t)throw Error(`Key ${n.key} already set`);i.isScalar(r.value)&&o.isScalarValue(n.value)?r.value.value=n.value:r.value=n.value}else if(c){let e=this.items.findIndex(e=>c(n,e)<0);e===-1?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){let t=s(this.items,e);return t?this.items.splice(this.items.indexOf(t),1).length>0:!1}get(e,t){let n=s(this.items,e)?.value;return(!t&&i.isScalar(n)?n.value:n)??void 0}has(e){return!!s(this.items,e)}set(e,t){this.add(new a.Pair(e,t),!0)}toJSON(e,t,r){let i=r?new r:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(i);for(let e of this.items)n.addPairToJSMap(t,i,e);return i}toString(e,n,r){if(!e)return JSON.stringify(this);for(let e of this.items)if(!i.isPair(e))throw Error(`Map items must all be pairs; found ${JSON.stringify(e)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),t.stringifyCollection(this,e,{blockItemPrefix:``,flowChars:{start:`{`,end:`}`},itemIndent:e.indent||``,onChompKeep:r,onComment:n})}},e.findPair=s})),W=A((e=>{var t=M(),n=U();e.map={collection:`map`,default:!0,nodeClass:n.YAMLMap,tag:`tag:yaml.org,2002:map`,resolve(e,n){return t.isMap(e)||n(`Expected a mapping for this tag`),e},createNode:(e,t,r)=>n.YAMLMap.from(e,t,r)}})),G=A((e=>{var t=V(),n=me(),r=ae(),i=M(),a=B(),o=L(),s=class extends r.Collection{static get tagName(){return`tag:yaml.org,2002:seq`}constructor(e){super(i.SEQ,e),this.items=[]}add(e){this.items.push(e)}delete(e){let t=c(e);return typeof t==`number`?this.items.splice(t,1).length>0:!1}get(e,t){let n=c(e);if(typeof n!=`number`)return;let r=this.items[n];return!t&&i.isScalar(r)?r.value:r}has(e){let t=c(e);return typeof t==`number`&&t<this.items.length}set(e,t){let n=c(e);if(typeof n!=`number`)throw Error(`Expected a valid index, not ${e}.`);let r=this.items[n];i.isScalar(r)&&a.isScalarValue(t)?r.value=t:this.items[n]=t}toJSON(e,t){let n=[];t?.onCreate&&t.onCreate(n);let r=0;for(let e of this.items)n.push(o.toJS(e,String(r++),t));return n}toString(e,t,r){return e?n.stringifyCollection(this,e,{blockItemPrefix:`- `,flowChars:{start:`[`,end:`]`},itemIndent:(e.indent||``)+` `,onChompKeep:r,onComment:t}):JSON.stringify(this)}static from(e,n,r){let{replacer:i}=r,a=new this(e);if(n&&Symbol.iterator in Object(n)){let e=0;for(let o of n){if(typeof i==`function`){let t=n instanceof Set?o:String(e++);o=i.call(n,t,o)}a.items.push(t.createNode(o,void 0,r))}}return a}};function c(e){let t=i.isScalar(e)?e.value:e;return t&&typeof t==`string`&&(t=Number(t)),typeof t==`number`&&Number.isInteger(t)&&t>=0?t:null}e.YAMLSeq=s})),K=A((e=>{var t=M(),n=G();e.seq={collection:`seq`,default:!0,nodeClass:n.YAMLSeq,tag:`tag:yaml.org,2002:seq`,resolve(e,n){return t.isSeq(e)||n(`Expected a sequence for this tag`),e},createNode:(e,t,r)=>n.YAMLSeq.from(e,t,r)}})),he=A((e=>{var t=ce();e.string={identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify(e,n,r,i){return n=Object.assign({actualString:!0},n),t.stringifyString(e,n,r,i)}}})),ge=A((e=>{var t=B();let n={identify:e=>e==null,createNode:()=>new t.Scalar(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new t.Scalar(null),stringify:({source:e},t)=>typeof e==`string`&&n.test.test(e)?e:t.options.nullStr};e.nullTag=n})),_e=A((e=>{var t=B();let n={identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new t.Scalar(e[0]===`t`||e[0]===`T`),stringify({source:e,value:t},r){return e&&n.test.test(e)&&t===(e[0]===`t`||e[0]===`T`)?e:t?r.options.trueStr:r.options.falseStr}};e.boolTag=n})),q=A((e=>{function t({format:e,minFractionDigits:t,tag:n,value:r}){if(typeof r==`bigint`)return String(r);let i=typeof r==`number`?r:Number(r);if(!isFinite(i))return isNaN(i)?`.nan`:i<0?`-.inf`:`.inf`;let a=Object.is(r,-0)?`-0`:JSON.stringify(r);if(!e&&t&&(!n||n===`tag:yaml.org,2002:float`)&&/^-?\d/.test(a)&&!a.includes(`e`)){let e=a.indexOf(`.`);e<0&&(e=a.length,a+=`.`);let n=t-(a.length-e-1);for(;n-- >0;)a+=`0`}return a}e.stringifyNumber=t})),ve=A((e=>{var t=B(),n=q();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(e){let n=new t.Scalar(parseFloat(e)),r=e.indexOf(`.`);return r!==-1&&e[e.length-1]===`0`&&(n.minFractionDigits=e.length-r-1),n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),ye=A((e=>{var t=q();let n=e=>typeof e==`bigint`||Number.isInteger(e),r=(e,t,n,{intAsBigInt:r})=>r?BigInt(e):parseInt(e.substring(t),n);function i(e,r,i){let{value:a}=e;return n(a)&&a>=0?i+a.toString(r):t.stringifyNumber(e)}e.int={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},e.intHex={identify:e=>n(e)&&e>=0,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)},e.intOct={identify:e=>n(e)&&e>=0,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^0o[0-7]+$/,resolve:(e,t,n)=>r(e,2,8,n),stringify:e=>i(e,8,`0o`)}})),be=A((e=>{var t=W(),n=ge(),r=K(),i=he(),a=_e(),o=ve(),s=ye();e.schema=[t.map,r.seq,i.string,n.nullTag,a.boolTag,s.intOct,s.int,s.intHex,o.floatNaN,o.floatExp,o.float]})),xe=A((e=>{var t=B(),n=W(),r=K();function i(e){return typeof e==`bigint`||Number.isInteger(e)}let a=({value:e})=>JSON.stringify(e),o=[{identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify:a},{identify:e=>e==null,createNode:()=>new t.Scalar(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^null$/,resolve:()=>null,stringify:a},{identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^true$|^false$/,resolve:e=>e===`true`,stringify:a},{identify:i,default:!0,tag:`tag:yaml.org,2002:int`,test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>i(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:a}];e.schema=[n.map,r.seq].concat(o,{default:!0,tag:``,test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}})})),Se=A((e=>{var t=j(`buffer`),n=B(),r=ce();e.binary={identify:e=>e instanceof Uint8Array,default:!1,tag:`tag:yaml.org,2002:binary`,resolve(e,n){if(typeof t.Buffer==`function`)return t.Buffer.from(e,`base64`);if(typeof atob==`function`){let t=atob(e.replace(/[\n\r]/g,``)),n=new Uint8Array(t.length);for(let e=0;e<t.length;++e)n[e]=t.charCodeAt(e);return n}else return n(`This environment does not support reading binary tags; either Buffer or atob is required`),e},stringify({comment:e,type:i,value:a},o,s,c){if(!a)return``;let l=a,u;if(typeof t.Buffer==`function`)u=l instanceof t.Buffer?l.toString(`base64`):t.Buffer.from(l.buffer).toString(`base64`);else if(typeof btoa==`function`){let e=``;for(let t=0;t<l.length;++t)e+=String.fromCharCode(l[t]);u=btoa(e)}else throw Error(`This environment does not support writing binary tags; either Buffer or btoa is required`);if(i??=n.Scalar.BLOCK_LITERAL,i!==n.Scalar.QUOTE_DOUBLE){let e=Math.max(o.options.lineWidth-o.indent.length,o.options.minContentWidth),t=Math.ceil(u.length/e),r=Array(t);for(let n=0,i=0;n<t;++n,i+=e)r[n]=u.substr(i,e);u=r.join(i===n.Scalar.BLOCK_LITERAL?`
|
|
38
|
+
`:` `)}return r.stringifyString({comment:e,type:i,value:u},o,s,c)}}})),Ce=A((e=>{var t=M(),n=H(),r=B(),i=G();function a(e,i){if(t.isSeq(e))for(let a=0;a<e.items.length;++a){let o=e.items[a];if(!t.isPair(o)){if(t.isMap(o)){o.items.length>1&&i(`Each pair must have its own sequence indicator`);let e=o.items[0]||new n.Pair(new r.Scalar(null));if(o.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${o.commentBefore}\n${e.key.commentBefore}`:o.commentBefore),o.comment){let t=e.value??e.key;t.comment=t.comment?`${o.comment}\n${t.comment}`:o.comment}o=e}e.items[a]=t.isPair(o)?o:new n.Pair(o)}}else i(`Expected a sequence for this tag`);return e}function o(e,t,r){let{replacer:a}=r,o=new i.YAMLSeq(e);o.tag=`tag:yaml.org,2002:pairs`;let s=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof a==`function`&&(e=a.call(t,String(s++),e));let i,c;if(Array.isArray(e))if(e.length===2)i=e[0],c=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`);else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)i=t[0],c=e[i];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else i=e;o.items.push(n.createPair(i,c,r))}return o}let s={collection:`seq`,default:!1,tag:`tag:yaml.org,2002:pairs`,resolve:a,createNode:o};e.createPairs=o,e.pairs=s,e.resolvePairs=a})),we=A((e=>{var t=M(),n=L(),r=U(),i=G(),a=Ce(),o=class e extends i.YAMLSeq{constructor(){super(),this.add=r.YAMLMap.prototype.add.bind(this),this.delete=r.YAMLMap.prototype.delete.bind(this),this.get=r.YAMLMap.prototype.get.bind(this),this.has=r.YAMLMap.prototype.has.bind(this),this.set=r.YAMLMap.prototype.set.bind(this),this.tag=e.tag}toJSON(e,r){if(!r)return super.toJSON(e);let i=new Map;r?.onCreate&&r.onCreate(i);for(let e of this.items){let a,o;if(t.isPair(e)?(a=n.toJS(e.key,``,r),o=n.toJS(e.value,a,r)):a=n.toJS(e,``,r),i.has(a))throw Error(`Ordered maps must not include duplicate keys`);i.set(a,o)}return i}static from(e,t,n){let r=a.createPairs(e,t,n),i=new this;return i.items=r.items,i}};o.tag=`tag:yaml.org,2002:omap`;let s={collection:`seq`,identify:e=>e instanceof Map,nodeClass:o,default:!1,tag:`tag:yaml.org,2002:omap`,resolve(e,n){let r=a.resolvePairs(e,n),i=[];for(let{key:e}of r.items)t.isScalar(e)&&(i.includes(e.value)?n(`Ordered maps must not include duplicate keys: ${e.value}`):i.push(e.value));return Object.assign(new o,r)},createNode:(e,t,n)=>o.from(e,t,n)};e.YAMLOMap=o,e.omap=s})),Te=A((e=>{var t=B();function n({value:e,source:t},n){return t&&(e?r:i).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}let r={identify:e=>e===!0,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new t.Scalar(!0),stringify:n},i={identify:e=>e===!1,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new t.Scalar(!1),stringify:n};e.falseTag=i,e.trueTag=r})),Ee=A((e=>{var t=B(),n=q();let r={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()===`nan`?NaN:e[0]===`-`?-1/0:1/0,stringify:n.stringifyNumber};e.float={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){let n=new t.Scalar(parseFloat(e.replace(/_/g,``))),r=e.indexOf(`.`);if(r!==-1){let t=e.substring(r+1).replace(/_/g,``);t[t.length-1]===`0`&&(n.minFractionDigits=t.length)}return n},stringify:n.stringifyNumber},e.floatExp={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`EXP`,test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,``)),stringify(e){let t=Number(e.value);return isFinite(t)?t.toExponential():n.stringifyNumber(e)}},e.floatNaN=r})),De=A((e=>{var t=q();let n=e=>typeof e==`bigint`||Number.isInteger(e);function r(e,t,n,{intAsBigInt:r}){let i=e[0];if((i===`-`||i===`+`)&&(t+=1),e=e.substring(t).replace(/_/g,``),r){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`;break}let t=BigInt(e);return i===`-`?BigInt(-1)*t:t}let a=parseInt(e,n);return i===`-`?-1*a:a}function i(e,r,i){let{value:a}=e;if(n(a)){let e=a.toString(r);return a<0?`-`+i+e.substr(1):i+e}return t.stringifyNumber(e)}let a={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`BIN`,test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>r(e,2,2,n),stringify:e=>i(e,2,`0b`)},o={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`OCT`,test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>r(e,1,8,n),stringify:e=>i(e,8,`0`)},s={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>r(e,0,10,n),stringify:t.stringifyNumber},c={identify:n,default:!0,tag:`tag:yaml.org,2002:int`,format:`HEX`,test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>r(e,2,16,n),stringify:e=>i(e,16,`0x`)};e.int=s,e.intBin=a,e.intHex=c,e.intOct=o})),Oe=A((e=>{var t=M(),n=H(),r=U(),i=class e extends r.YAMLMap{constructor(t){super(t),this.tag=e.tag}add(e){let i;i=t.isPair(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new n.Pair(e.key,null):new n.Pair(e,null),r.findPair(this.items,i.key)||this.items.push(i)}get(e,n){let i=r.findPair(this.items,e);return!n&&t.isPair(i)?t.isScalar(i.key)?i.key.value:i.key:i}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let i=r.findPair(this.items,e);i&&!t?this.items.splice(this.items.indexOf(i),1):!i&&t&&this.items.push(new n.Pair(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,r){let{replacer:i}=r,a=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof i==`function`&&(e=i.call(t,e,e)),a.items.push(n.createPair(e,null,r));return a}};i.tag=`tag:yaml.org,2002:set`;let a={collection:`map`,identify:e=>e instanceof Set,nodeClass:i,default:!1,tag:`tag:yaml.org,2002:set`,createNode:(e,t,n)=>i.from(e,t,n),resolve(e,n){if(t.isMap(e)){if(e.hasAllNullValues(!0))return Object.assign(new i,e);n(`Set items must all have null values`)}else n(`Expected a mapping for this tag`);return e}};e.YAMLSet=i,e.set=a})),ke=A((e=>{var t=q();function n(e,t){let n=e[0],r=n===`-`||n===`+`?e.substring(1):e,i=e=>t?BigInt(e):Number(e),a=r.replace(/_/g,``).split(`:`).reduce((e,t)=>e*i(60)+i(t),i(0));return n===`-`?i(-1)*a:a}function r(e){let{value:n}=e,r=e=>e;if(typeof n==`bigint`)r=e=>BigInt(e);else if(isNaN(n)||!isFinite(n))return t.stringifyNumber(e);let i=``;n<0&&(i=`-`,n*=r(-1));let a=r(60),o=[n%a];return n<60?o.unshift(0):(n=(n-o[0])/a,o.unshift(n%a),n>=60&&(n=(n-o[0])/a,o.unshift(n))),i+o.map(e=>String(e).padStart(2,`0`)).join(`:`).replace(/000000\d*$/,``)}let i={identify:e=>typeof e==`bigint`||Number.isInteger(e),default:!0,tag:`tag:yaml.org,2002:int`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:r})=>n(e,r),stringify:r},a={identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,format:`TIME`,test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>n(e,!1),stringify:r},o={identify:e=>e instanceof Date,default:!0,tag:`tag:yaml.org,2002:timestamp`,test:RegExp(`^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$`),resolve(e){let t=e.match(o.test);if(!t)throw Error(`!!timestamp expects a date, starting with yyyy-mm-dd`);let[,r,i,a,s,c,l]=t.map(Number),u=t[7]?Number((t[7]+`00`).substr(1,3)):0,d=Date.UTC(r,i-1,a,s||0,c||0,l||0,u),f=t[8];if(f&&f!==`Z`){let e=n(f,!1);Math.abs(e)<30&&(e*=60),d-=6e4*e}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,``)??``};e.floatTime=a,e.intTime=i,e.timestamp=o})),Ae=A((e=>{var t=W(),n=ge(),r=K(),i=he(),a=Se(),o=Te(),s=Ee(),c=De(),l=fe(),u=we(),d=Ce(),f=Oe(),p=ke();e.schema=[t.map,r.seq,i.string,n.nullTag,o.trueTag,o.falseTag,c.intBin,c.intOct,c.int,c.intHex,s.floatNaN,s.floatExp,s.float,a.binary,l.merge,u.omap,d.pairs,f.set,p.intTime,p.floatTime,p.timestamp]})),je=A((e=>{var t=W(),n=ge(),r=K(),i=he(),a=_e(),o=ve(),s=ye(),c=be(),l=xe(),u=Se(),d=fe(),f=we(),p=Ce(),m=Ae(),h=Oe(),g=ke();let _=new Map([[`core`,c.schema],[`failsafe`,[t.map,r.seq,i.string]],[`json`,l.schema],[`yaml11`,m.schema],[`yaml-1.1`,m.schema]]),v={binary:u.binary,bool:a.boolTag,float:o.float,floatExp:o.floatExp,floatNaN:o.floatNaN,floatTime:g.floatTime,int:s.int,intHex:s.intHex,intOct:s.intOct,intTime:g.intTime,map:t.map,merge:d.merge,null:n.nullTag,omap:f.omap,pairs:p.pairs,seq:r.seq,set:h.set,timestamp:g.timestamp},y={"tag:yaml.org,2002:binary":u.binary,"tag:yaml.org,2002:merge":d.merge,"tag:yaml.org,2002:omap":f.omap,"tag:yaml.org,2002:pairs":p.pairs,"tag:yaml.org,2002:set":h.set,"tag:yaml.org,2002:timestamp":g.timestamp};function b(e,t,n){let r=_.get(t);if(r&&!e)return n&&!r.includes(d.merge)?r.concat(d.merge):r.slice();let i=r;if(!i)if(Array.isArray(e))i=[];else{let e=Array.from(_.keys()).filter(e=>e!==`yaml11`).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}if(Array.isArray(e))for(let t of e)i=i.concat(t);else typeof e==`function`&&(i=e(i.slice()));return n&&(i=i.concat(d.merge)),i.reduce((e,t)=>{let n=typeof t==`string`?v[t]:t;if(!n){let e=JSON.stringify(t),n=Object.keys(v).map(e=>JSON.stringify(e)).join(`, `);throw Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e},[])}e.coreKnownTags=y,e.getTags=b})),Me=A((e=>{var t=M(),n=W(),r=K(),i=he(),a=je();let o=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;e.Schema=class e{constructor({compat:e,customTags:s,merge:c,resolveKnownTags:l,schema:u,sortMapEntries:d,toStringDefaults:f}){this.compat=Array.isArray(e)?a.getTags(e,`compat`):e?a.getTags(null,e):null,this.name=typeof u==`string`&&u||`core`,this.knownTags=l?a.coreKnownTags:{},this.tags=a.getTags(s,this.name,c),this.toStringOptions=f??null,Object.defineProperty(this,t.MAP,{value:n.map}),Object.defineProperty(this,t.SCALAR,{value:i.string}),Object.defineProperty(this,t.SEQ,{value:r.seq}),this.sortMapEntries=typeof d==`function`?d:d===!0?o:null}clone(){let t=Object.create(e.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}})),Ne=A((e=>{var t=M(),n=le(),r=oe();function i(e,i){let a=[],o=i.directives===!0;if(i.directives!==!1&&e.directives){let t=e.directives.toString(e);t?(a.push(t),o=!0):e.directives.docStart&&(o=!0)}o&&a.push(`---`);let s=n.createStringifyContext(e,i),{commentString:c}=s.options;if(e.commentBefore){a.length!==1&&a.unshift(``);let t=c(e.commentBefore);a.unshift(r.indentComment(t,``))}let l=!1,u=null;if(e.contents){if(t.isNode(e.contents)){if(e.contents.spaceBefore&&o&&a.push(``),e.contents.commentBefore){let t=c(e.contents.commentBefore);a.push(r.indentComment(t,``))}s.forceBlockIndent=!!e.comment,u=e.contents.comment}let i=u?void 0:()=>l=!0,d=n.stringify(e.contents,s,()=>u=null,i);u&&(d+=r.lineComment(d,``,c(u))),(d[0]===`|`||d[0]===`>`)&&a[a.length-1]===`---`?a[a.length-1]=`--- ${d}`:a.push(d)}else a.push(n.stringify(e.contents,s));if(e.directives?.docEnd)if(e.comment){let t=c(e.comment);t.includes(`
|
|
39
39
|
`)?(a.push(`...`),a.push(r.indentComment(t,``))):a.push(`... ${t}`)}else a.push(`...`);else{let t=e.comment;t&&l&&(t=t.replace(/^\n+/,``)),t&&((!l||u)&&a[a.length-1]!==``&&a.push(``),a.push(r.indentComment(c(t),``)))}return a.join(`
|
|
40
40
|
`)+`
|
|
41
|
-
`}e.stringifyDocument=i})),
|
|
42
|
-
`),o=n+o}if(/[^ ]/.test(o)){let e=1,t=n.linePos[1];t?.line===r&&t.col>i&&(e=Math.max(1,Math.min(t.col-i,80-a)));let s=` `.repeat(a)+`^`.repeat(e);n.message+=`:\n\n${o}\n${s}\n`}}})),
|
|
43
|
-
`))return!0;if(e.end){for(let t of e.end)if(t.type===`newline`)return!0}return!1;case`flow-collection`:for(let n of e.items){for(let e of n.start)if(e.type===`newline`)return!0;if(n.sep){for(let e of n.sep)if(e.type===`newline`)return!0}if(t(n.key)||t(n.value))return!0}return!1;default:return!0}}e.containsNewline=t})),
|
|
41
|
+
`}e.stringifyDocument=i})),Pe=A((e=>{var t=z(),n=ae(),r=M(),i=H(),a=L(),o=Me(),s=Ne(),c=F(),l=I(),u=V(),d=P(),f=class e{constructor(e,t,n){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,r.NODE_TYPE,{value:r.DOC});let i=null;typeof t==`function`||Array.isArray(t)?i=t:n===void 0&&t&&(n=t,t=void 0);let a=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:`warn`,prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:`1.2`},n);this.options=a;let{version:o}=a;n?._directives?(this.directives=n._directives.atDocument(),this.directives.yaml.explicit&&(o=this.directives.yaml.version)):this.directives=new d.Directives({version:o}),this.setSchema(o,n),this.contents=e===void 0?null:this.createNode(e,i,n)}clone(){let t=Object.create(e.prototype,{[r.NODE_TYPE]:{value:r.DOC}});return t.commentBefore=this.commentBefore,t.comment=this.comment,t.errors=this.errors.slice(),t.warnings=this.warnings.slice(),t.options=Object.assign({},this.options),this.directives&&(t.directives=this.directives.clone()),t.schema=this.schema.clone(),t.contents=r.isNode(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(e){p(this.contents)&&this.contents.add(e)}addIn(e,t){p(this.contents)&&this.contents.addIn(e,t)}createAlias(e,n){if(!e.anchor){let t=c.anchorNames(this);e.anchor=!n||t.has(n)?c.findNewAnchor(n||`a`,t):n}return new t.Alias(e.anchor)}createNode(e,t,n){let i;if(typeof t==`function`)e=t.call({"":e},``,e),i=t;else if(Array.isArray(t)){let e=t.filter(e=>typeof e==`number`||e instanceof String||e instanceof Number).map(String);e.length>0&&(t=t.concat(e)),i=t}else n===void 0&&t&&(n=t,t=void 0);let{aliasDuplicateObjects:a,anchorPrefix:o,flow:s,keepUndefined:l,onTagObj:d,tag:f}=n??{},{onAnchor:p,setAnchors:m,sourceObjects:h}=c.createNodeAnchors(this,o||`a`),g={aliasDuplicateObjects:a??!0,keepUndefined:l??!1,onAnchor:p,onTagObj:d,replacer:i,schema:this.schema,sourceObjects:h},_=u.createNode(e,f,g);return s&&r.isCollection(_)&&(_.flow=!0),m(),_}createPair(e,t,n={}){let r=this.createNode(e,null,n),a=this.createNode(t,null,n);return new i.Pair(r,a)}delete(e){return p(this.contents)?this.contents.delete(e):!1}deleteIn(e){return n.isEmptyPath(e)?this.contents==null?!1:(this.contents=null,!0):p(this.contents)?this.contents.deleteIn(e):!1}get(e,t){return r.isCollection(this.contents)?this.contents.get(e,t):void 0}getIn(e,t){return n.isEmptyPath(e)?!t&&r.isScalar(this.contents)?this.contents.value:this.contents:r.isCollection(this.contents)?this.contents.getIn(e,t):void 0}has(e){return r.isCollection(this.contents)?this.contents.has(e):!1}hasIn(e){return n.isEmptyPath(e)?this.contents!==void 0:r.isCollection(this.contents)?this.contents.hasIn(e):!1}set(e,t){this.contents==null?this.contents=n.collectionFromPath(this.schema,[e],t):p(this.contents)&&this.contents.set(e,t)}setIn(e,t){n.isEmptyPath(e)?this.contents=t:this.contents==null?this.contents=n.collectionFromPath(this.schema,Array.from(e),t):p(this.contents)&&this.contents.setIn(e,t)}setSchema(e,t={}){typeof e==`number`&&(e=String(e));let n;switch(e){case`1.1`:this.directives?this.directives.yaml.version=`1.1`:this.directives=new d.Directives({version:`1.1`}),n={resolveKnownTags:!1,schema:`yaml-1.1`};break;case`1.2`:case`next`:this.directives?this.directives.yaml.version=e:this.directives=new d.Directives({version:e}),n={resolveKnownTags:!0,schema:`core`};break;case null:this.directives&&delete this.directives,n=null;break;default:{let t=JSON.stringify(e);throw Error(`Expected '1.1', '1.2' or null as first argument, but found: ${t}`)}}if(t.schema instanceof Object)this.schema=t.schema;else if(n)this.schema=new o.Schema(Object.assign(n,t));else throw Error(`With a null YAML version, the { schema: Schema } option is required`)}toJS({json:e,jsonArg:t,mapAsMap:n,maxAliasCount:r,onAnchor:i,reviver:o}={}){let s={anchors:new Map,doc:this,keep:!e,mapAsMap:n===!0,mapKeyWarned:!1,maxAliasCount:typeof r==`number`?r:100},c=a.toJS(this.contents,t??``,s);if(typeof i==`function`)for(let{count:e,res:t}of s.anchors.values())i(t,e);return typeof o==`function`?l.applyReviver(o,{"":c},``,c):c}toJSON(e,t){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:t})}toString(e={}){if(this.errors.length>0)throw Error(`Document with errors cannot be stringified`);if(`indent`in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){let t=JSON.stringify(e.indent);throw Error(`"indent" option must be a positive integer, not ${t}`)}return s.stringifyDocument(this,e)}};function p(e){if(r.isCollection(e))return!0;throw Error(`Expected a YAML collection as document contents`)}e.Document=f})),Fe=A((e=>{var t=class extends Error{constructor(e,t,n,r){super(),this.name=e,this.code=n,this.message=r,this.pos=t}},n=class extends t{constructor(e,t,n){super(`YAMLParseError`,e,t,n)}},r=class extends t{constructor(e,t,n){super(`YAMLWarning`,e,t,n)}};e.YAMLError=t,e.YAMLParseError=n,e.YAMLWarning=r,e.prettifyError=(e,t)=>n=>{if(n.pos[0]===-1)return;n.linePos=n.pos.map(e=>t.linePos(e));let{line:r,col:i}=n.linePos[0];n.message+=` at line ${r}, column ${i}`;let a=i-1,o=e.substring(t.lineStarts[r-1],t.lineStarts[r]).replace(/[\n\r]+$/,``);if(a>=60&&o.length>80){let e=Math.min(a-39,o.length-79);o=`…`+o.substring(e),a-=e-1}if(o.length>80&&(o=o.substring(0,79)+`…`),r>1&&/^ *$/.test(o.substring(0,a))){let n=e.substring(t.lineStarts[r-2],t.lineStarts[r-1]);n.length>80&&(n=n.substring(0,79)+`…
|
|
42
|
+
`),o=n+o}if(/[^ ]/.test(o)){let e=1,t=n.linePos[1];t?.line===r&&t.col>i&&(e=Math.max(1,Math.min(t.col-i,80-a)));let s=` `.repeat(a)+`^`.repeat(e);n.message+=`:\n\n${o}\n${s}\n`}}})),Ie=A((e=>{function t(e,{flow:t,indicator:n,next:r,offset:i,onError:a,parentIndent:o,startOnNewline:s}){let c=!1,l=s,u=s,d=``,f=``,p=!1,m=!1,h=null,g=null,_=null,v=null,y=null,b=null,x=null;for(let i of e)switch(m&&=(i.type!==`space`&&i.type!==`newline`&&i.type!==`comma`&&a(i.offset,`MISSING_CHAR`,`Tags and anchors must be separated from the next token by white space`),!1),h&&=(l&&i.type!==`comment`&&i.type!==`newline`&&a(h,`TAB_AS_INDENT`,`Tabs are not allowed as indentation`),null),i.type){case`space`:!t&&(n!==`doc-start`||r?.type!==`flow-collection`)&&i.source.includes(` `)&&(h=i),u=!0;break;case`comment`:{u||a(i,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`);let e=i.source.substring(1)||` `;d?d+=f+e:d=e,f=``,l=!1;break}case`newline`:l?d?d+=i.source:(!b||n!==`seq-item-ind`)&&(c=!0):f+=i.source,l=!0,p=!0,(g||_)&&(v=i),u=!0;break;case`anchor`:g&&a(i,`MULTIPLE_ANCHORS`,`A node can have at most one anchor`),i.source.endsWith(`:`)&&a(i.offset+i.source.length-1,`BAD_ALIAS`,`Anchor ending in : is ambiguous`,!0),g=i,x??=i.offset,l=!1,u=!1,m=!0;break;case`tag`:_&&a(i,`MULTIPLE_TAGS`,`A node can have at most one tag`),_=i,x??=i.offset,l=!1,u=!1,m=!0;break;case n:(g||_)&&a(i,`BAD_PROP_ORDER`,`Anchors and tags must be after the ${i.source} indicator`),b&&a(i,`UNEXPECTED_TOKEN`,`Unexpected ${i.source} in ${t??`collection`}`),b=i,l=n===`seq-item-ind`||n===`explicit-key-ind`,u=!1;break;case`comma`:if(t){y&&a(i,`UNEXPECTED_TOKEN`,`Unexpected , in ${t}`),y=i,l=!1,u=!1;break}default:a(i,`UNEXPECTED_TOKEN`,`Unexpected ${i.type} token`),l=!1,u=!1}let S=e[e.length-1],C=S?S.offset+S.source.length:i;return m&&r&&r.type!==`space`&&r.type!==`newline`&&r.type!==`comma`&&(r.type!==`scalar`||r.source!==``)&&a(r.offset,`MISSING_CHAR`,`Tags and anchors must be separated from the next token by white space`),h&&(l&&h.indent<=o||r?.type===`block-map`||r?.type===`block-seq`)&&a(h,`TAB_AS_INDENT`,`Tabs are not allowed as indentation`),{comma:y,found:b,spaceBefore:c,comment:d,hasNewline:p,anchor:g,tag:_,newlineAfterProp:v,end:C,start:x??C}}e.resolveProps=t})),Le=A((e=>{function t(e){if(!e)return null;switch(e.type){case`alias`:case`scalar`:case`double-quoted-scalar`:case`single-quoted-scalar`:if(e.source.includes(`
|
|
43
|
+
`))return!0;if(e.end){for(let t of e.end)if(t.type===`newline`)return!0}return!1;case`flow-collection`:for(let n of e.items){for(let e of n.start)if(e.type===`newline`)return!0;if(n.sep){for(let e of n.sep)if(e.type===`newline`)return!0}if(t(n.key)||t(n.value))return!0}return!1;default:return!0}}e.containsNewline=t})),Re=A((e=>{var t=Le();function n(e,n,r){if(n?.type===`flow-collection`){let i=n.end[0];i.indent===e&&(i.source===`]`||i.source===`}`)&&t.containsNewline(n)&&r(i,`BAD_INDENT`,`Flow end indicator should be more indented than parent`,!0)}}e.flowIndentCheck=n})),ze=A((e=>{var t=M();function n(e,n,r){let{uniqueKeys:i}=e.options;if(i===!1)return!1;let a=typeof i==`function`?i:(e,n)=>e===n||t.isScalar(e)&&t.isScalar(n)&&e.value===n.value;return n.some(e=>a(e.key,r))}e.mapIncludes=n})),Be=A((e=>{var t=H(),n=U(),r=Ie(),i=Le(),a=Re(),o=ze();let s=`All mapping items must start at the same column`;function c({composeNode:e,composeEmptyNode:c},l,u,d,f){let p=new(f?.nodeClass??n.YAMLMap)(l.schema);l.atRoot&&=!1;let m=u.offset,h=null;for(let n of u.items){let{start:f,key:g,sep:_,value:v}=n,y=r.resolveProps(f,{indicator:`explicit-key-ind`,next:g??_?.[0],offset:m,onError:d,parentIndent:u.indent,startOnNewline:!0}),b=!y.found;if(b){if(g&&(g.type===`block-seq`?d(m,`BLOCK_AS_IMPLICIT_KEY`,`A block sequence may not be used as an implicit map key`):`indent`in g&&g.indent!==u.indent&&d(m,`BAD_INDENT`,s)),!y.anchor&&!y.tag&&!_){h=y.end,y.comment&&(p.comment?p.comment+=`
|
|
44
44
|
`+y.comment:p.comment=y.comment);continue}(y.newlineAfterProp||i.containsNewline(g))&&d(g??f[f.length-1],`MULTILINE_IMPLICIT_KEY`,`Implicit keys need to be on a single line`)}else y.found?.indent!==u.indent&&d(m,`BAD_INDENT`,s);l.atKey=!0;let x=y.end,S=g?e(l,g,y,d):c(l,x,f,null,y,d);l.schema.compat&&a.flowIndentCheck(u.indent,g,d),l.atKey=!1,o.mapIncludes(l,p.items,S)&&d(x,`DUPLICATE_KEY`,`Map keys must be unique`);let C=r.resolveProps(_??[],{indicator:`map-value-ind`,next:v,offset:S.range[2],onError:d,parentIndent:u.indent,startOnNewline:!g||g.type===`block-scalar`});if(m=C.end,C.found){b&&(v?.type===`block-map`&&!C.hasNewline&&d(m,`BLOCK_AS_IMPLICIT_KEY`,`Nested mappings are not allowed in compact mappings`),l.options.strict&&y.start<C.found.offset-1024&&d(S.range,`KEY_OVER_1024_CHARS`,`The : indicator must be at most 1024 chars after the start of an implicit block mapping key`));let r=v?e(l,v,C,d):c(l,m,_,null,C,d);l.schema.compat&&a.flowIndentCheck(u.indent,v,d),m=r.range[2];let i=new t.Pair(S,r);l.options.keepSourceTokens&&(i.srcToken=n),p.items.push(i)}else{b&&d(S.range,`MISSING_CHAR`,`Implicit map keys need to be followed by map values`),C.comment&&(S.comment?S.comment+=`
|
|
45
|
-
`+C.comment:S.comment=C.comment);let e=new t.Pair(S);l.options.keepSourceTokens&&(e.srcToken=n),p.items.push(e)}}return h&&h<m&&d(h,`IMPOSSIBLE`,`Map comment with trailing content`),p.range=[u.offset,m,h??m],p}e.resolveBlockMap=c})),
|
|
45
|
+
`+C.comment:S.comment=C.comment);let e=new t.Pair(S);l.options.keepSourceTokens&&(e.srcToken=n),p.items.push(e)}}return h&&h<m&&d(h,`IMPOSSIBLE`,`Map comment with trailing content`),p.range=[u.offset,m,h??m],p}e.resolveBlockMap=c})),Ve=A((e=>{var t=G(),n=Ie(),r=Re();function i({composeNode:e,composeEmptyNode:i},a,o,s,c){let l=new(c?.nodeClass??t.YAMLSeq)(a.schema);a.atRoot&&=!1,a.atKey&&=!1;let u=o.offset,d=null;for(let{start:t,value:c}of o.items){let f=n.resolveProps(t,{indicator:`seq-item-ind`,next:c,offset:u,onError:s,parentIndent:o.indent,startOnNewline:!0});if(!f.found)if(f.anchor||f.tag||c)c?.type===`block-seq`?s(f.end,`BAD_INDENT`,`All sequence items must start at the same column`):s(u,`MISSING_CHAR`,`Sequence item without - indicator`);else{d=f.end,f.comment&&(l.comment=f.comment);continue}let p=c?e(a,c,f,s):i(a,f.end,t,null,f,s);a.schema.compat&&r.flowIndentCheck(o.indent,c,s),u=p.range[2],l.items.push(p)}return l.range=[o.offset,u,d??u],l}e.resolveBlockSeq=i})),J=A((e=>{function t(e,t,n,r){let i=``;if(e){let a=!1,o=``;for(let s of e){let{source:e,type:c}=s;switch(c){case`space`:a=!0;break;case`comment`:{n&&!a&&r(s,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`);let t=e.substring(1)||` `;i?i+=o+t:i=t,o=``;break}case`newline`:i&&(o+=e),a=!0;break;default:r(s,`UNEXPECTED_TOKEN`,`Unexpected ${c} at node end`)}t+=e.length}}return{comment:i,offset:t}}e.resolveEnd=t})),He=A((e=>{var t=M(),n=H(),r=U(),i=G(),a=J(),o=Ie(),s=Le(),c=ze();let l=`Block collections are not allowed within flow collections`,u=e=>e&&(e.type===`block-map`||e.type===`block-seq`);function d({composeNode:e,composeEmptyNode:d},f,p,m,h){let g=p.start.source===`{`,_=g?`flow map`:`flow sequence`,v=new(h?.nodeClass??(g?r.YAMLMap:i.YAMLSeq))(f.schema);v.flow=!0;let y=f.atRoot;y&&(f.atRoot=!1),f.atKey&&=!1;let b=p.offset+p.start.source.length;for(let i=0;i<p.items.length;++i){let a=p.items[i],{start:h,key:y,sep:x,value:S}=a,C=o.resolveProps(h,{flow:_,indicator:`explicit-key-ind`,next:y??x?.[0],offset:b,onError:m,parentIndent:p.indent,startOnNewline:!1});if(!C.found){if(!C.anchor&&!C.tag&&!x&&!S){i===0&&C.comma?m(C.comma,`UNEXPECTED_TOKEN`,`Unexpected , in ${_}`):i<p.items.length-1&&m(C.start,`UNEXPECTED_TOKEN`,`Unexpected empty item in ${_}`),C.comment&&(v.comment?v.comment+=`
|
|
46
46
|
`+C.comment:v.comment=C.comment),b=C.end;continue}!g&&f.options.strict&&s.containsNewline(y)&&m(y,`MULTILINE_IMPLICIT_KEY`,`Implicit keys of flow sequence pairs need to be on a single line`)}if(i===0)C.comma&&m(C.comma,`UNEXPECTED_TOKEN`,`Unexpected , in ${_}`);else if(C.comma||m(C.start,`MISSING_CHAR`,`Missing , between ${_} items`),C.comment){let e=``;loop:for(let t of h)switch(t.type){case`comma`:case`space`:break;case`comment`:e=t.source.substring(1);break loop;default:break loop}if(e){let n=v.items[v.items.length-1];t.isPair(n)&&(n=n.value??n.key),n.comment?n.comment+=`
|
|
47
47
|
`+e:n.comment=e,C.comment=C.comment.substring(e.length+1)}}if(!g&&!x&&!C.found){let t=S?e(f,S,C,m):d(f,C.end,x,null,C,m);v.items.push(t),b=t.range[2],u(S)&&m(t.range,`BLOCK_IN_FLOW`,l)}else{f.atKey=!0;let t=C.end,i=y?e(f,y,C,m):d(f,t,h,null,C,m);u(y)&&m(i.range,`BLOCK_IN_FLOW`,l),f.atKey=!1;let s=o.resolveProps(x??[],{flow:_,indicator:`map-value-ind`,next:S,offset:i.range[2],onError:m,parentIndent:p.indent,startOnNewline:!1});if(s.found){if(!g&&!C.found&&f.options.strict){if(x)for(let e of x){if(e===s.found)break;if(e.type===`newline`){m(e,`MULTILINE_IMPLICIT_KEY`,`Implicit keys of flow sequence pairs need to be on a single line`);break}}C.start<s.found.offset-1024&&m(s.found,`KEY_OVER_1024_CHARS`,`The : indicator must be at most 1024 chars after the start of an implicit flow sequence key`)}}else S&&(`source`in S&&S.source?.[0]===`:`?m(S,`MISSING_CHAR`,`Missing space after : in ${_}`):m(s.start,`MISSING_CHAR`,`Missing , or : between ${_} items`));let w=S?e(f,S,s,m):s.found?d(f,s.end,x,null,s,m):null;w?u(S)&&m(w.range,`BLOCK_IN_FLOW`,l):s.comment&&(i.comment?i.comment+=`
|
|
48
48
|
`+s.comment:i.comment=s.comment);let T=new n.Pair(i,w);if(f.options.keepSourceTokens&&(T.srcToken=a),g){let e=v;c.mapIncludes(f,e.items,i)&&m(t,`DUPLICATE_KEY`,`Map keys must be unique`),e.items.push(T)}else{let e=new r.YAMLMap(f.schema);e.flow=!0,e.items.push(T);let t=(w??i).range;e.range=[i.range[0],t[1],t[2]],v.items.push(e)}b=w?w.range[2]:s.end}}let x=g?`}`:`]`,[S,...C]=p.end,w=b;if(S?.source===x)w=S.offset+S.source.length;else{let e=_[0].toUpperCase()+_.substring(1),t=y?`${e} must end with a ${x}`:`${e} in block collection must be sufficiently indented and end with a ${x}`;m(b,y?`MISSING_CHAR`:`BAD_INDENT`,t),S&&S.source.length!==1&&C.unshift(S)}if(C.length>0){let e=a.resolveEnd(C,w,f.options.strict,m);e.comment&&(v.comment?v.comment+=`
|
|
49
|
-
`+e.comment:v.comment=e.comment),v.range=[p.offset,w,e.offset]}else v.range=[p.offset,w,w];return v}e.resolveFlowCollection=d})),
|
|
49
|
+
`+e.comment:v.comment=e.comment),v.range=[p.offset,w,e.offset]}else v.range=[p.offset,w,w];return v}e.resolveFlowCollection=d})),Ue=A((e=>{var t=M(),n=B(),r=U(),i=G(),a=Be(),o=Ve(),s=He();function c(e,t,n,r,i,c){let l=n.type===`block-map`?a.resolveBlockMap(e,t,n,r,c):n.type===`block-seq`?o.resolveBlockSeq(e,t,n,r,c):s.resolveFlowCollection(e,t,n,r,c),u=l.constructor;return i===`!`||i===u.tagName?(l.tag=u.tagName,l):(i&&(l.tag=i),l)}function l(e,a,o,s,l){let u=s.tag,d=u?a.directives.tagName(u.source,e=>l(u,`TAG_RESOLVE_FAILED`,e)):null;if(o.type===`block-seq`){let{anchor:e,newlineAfterProp:t}=s,n=e&&u?e.offset>u.offset?e:u:e??u;n&&(!t||t.offset<n.offset)&&l(n,`MISSING_CHAR`,`Missing newline after block sequence props`)}let f=o.type===`block-map`?`map`:o.type===`block-seq`?`seq`:o.start.source===`{`?`map`:`seq`;if(!u||!d||d===`!`||d===r.YAMLMap.tagName&&f===`map`||d===i.YAMLSeq.tagName&&f===`seq`)return c(e,a,o,l,d);let p=a.schema.tags.find(e=>e.tag===d&&e.collection===f);if(!p){let t=a.schema.knownTags[d];if(t?.collection===f)a.schema.tags.push(Object.assign({},t,{default:!1})),p=t;else return t?l(u,`BAD_COLLECTION_TYPE`,`${t.tag} used for ${f} collection, but expects ${t.collection??`scalar`}`,!0):l(u,`TAG_RESOLVE_FAILED`,`Unresolved tag: ${d}`,!0),c(e,a,o,l,d)}let m=c(e,a,o,l,d,p),h=p.resolve?.(m,e=>l(u,`TAG_RESOLVE_FAILED`,e),a.options)??m,g=t.isNode(h)?h:new n.Scalar(h);return g.range=m.range,g.tag=d,p?.format&&(g.format=p.format),g}e.composeCollection=l})),We=A((e=>{var t=B();function n(e,n,a){let o=n.offset,s=r(n,e.options.strict,a);if(!s)return{value:``,type:null,comment:``,range:[o,o,o]};let c=s.mode===`>`?t.Scalar.BLOCK_FOLDED:t.Scalar.BLOCK_LITERAL,l=n.source?i(n.source):[],u=l.length;for(let e=l.length-1;e>=0;--e){let t=l[e][1];if(t===``||t===`\r`)u=e;else break}if(u===0){let e=s.chomp===`+`&&l.length>0?`
|
|
50
50
|
`.repeat(Math.max(1,l.length-1)):``,t=o+s.length;return n.source&&(t+=n.source.length),{value:e,type:c,comment:s.comment,range:[o,t,t]}}let d=n.indent+s.indent,f=n.offset+s.length,p=0;for(let t=0;t<u;++t){let[n,r]=l[t];if(r===``||r===`\r`)s.indent===0&&n.length>d&&(d=n.length);else{n.length<d&&a(f+n.length,`MISSING_CHAR`,`Block scalars with more-indented leading empty lines must use an explicit indentation indicator`),s.indent===0&&(d=n.length),p=t,d===0&&!e.atRoot&&a(f,`BAD_INDENT`,`Block scalar values in collections must be indented`);break}f+=n.length+r.length+1}for(let e=l.length-1;e>=u;--e)l[e][0].length>d&&(u=e+1);let m=``,h=``,g=!1;for(let e=0;e<p;++e)m+=l[e][0].slice(d)+`
|
|
51
51
|
`;for(let e=p;e<u;++e){let[n,r]=l[e];f+=n.length+r.length+1;let i=r[r.length-1]===`\r`;if(i&&(r=r.slice(0,-1)),r&&n.length<d){let e=`Block scalar lines must not be less indented than their ${s.indent?`explicit indentation indicator`:`first line`}`;a(f-r.length-(i?2:1),`BAD_INDENT`,e),n=``}c===t.Scalar.BLOCK_LITERAL?(m+=h+n.slice(d)+r,h=`
|
|
52
52
|
`):n.length>d||r[0]===` `?(h===` `?h=`
|
|
@@ -61,7 +61,7 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
61
61
|
`+l[e][0].slice(d);m[m.length-1]!==`
|
|
62
62
|
`&&(m+=`
|
|
63
63
|
`);break;default:m+=`
|
|
64
|
-
`}let _=o+s.length+n.source.length;return{value:m,type:c,comment:s.comment,range:[o,_,_]}}function r({offset:e,props:t},n,r){if(t[0].type!==`block-scalar-header`)return r(t[0],`IMPOSSIBLE`,`Block scalar header not found`),null;let{source:i}=t[0],a=i[0],o=0,s=``,c=-1;for(let t=1;t<i.length;++t){let n=i[t];if(!s&&(n===`-`||n===`+`))s=n;else{let r=Number(n);!o&&r?o=r:c===-1&&(c=e+t)}}c!==-1&&r(c,`UNEXPECTED_TOKEN`,`Block scalar header includes extra characters: ${i}`);let l=!1,u=``,d=i.length;for(let e=1;e<t.length;++e){let i=t[e];switch(i.type){case`space`:l=!0;case`newline`:d+=i.source.length;break;case`comment`:n&&!l&&r(i,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`),d+=i.source.length,u=i.source.substring(1);break;case`error`:r(i,`UNEXPECTED_TOKEN`,i.message),d+=i.source.length;break;default:{r(i,`UNEXPECTED_TOKEN`,`Unexpected token in block scalar header: ${i.type}`);let e=i.source;e&&typeof e==`string`&&(d+=e.length)}}}return{mode:a,indent:o,chomp:s,comment:u,length:d}}function i(e){let t=e.split(/\n( *)/),n=t[0],r=n.match(/^( *)/),i=[r?.[1]?[r[1],n.slice(r[1].length)]:[``,n]];for(let e=1;e<t.length;e+=2)i.push([t[e],t[e+1]]);return i}e.resolveBlockScalar=n})),
|
|
64
|
+
`}let _=o+s.length+n.source.length;return{value:m,type:c,comment:s.comment,range:[o,_,_]}}function r({offset:e,props:t},n,r){if(t[0].type!==`block-scalar-header`)return r(t[0],`IMPOSSIBLE`,`Block scalar header not found`),null;let{source:i}=t[0],a=i[0],o=0,s=``,c=-1;for(let t=1;t<i.length;++t){let n=i[t];if(!s&&(n===`-`||n===`+`))s=n;else{let r=Number(n);!o&&r?o=r:c===-1&&(c=e+t)}}c!==-1&&r(c,`UNEXPECTED_TOKEN`,`Block scalar header includes extra characters: ${i}`);let l=!1,u=``,d=i.length;for(let e=1;e<t.length;++e){let i=t[e];switch(i.type){case`space`:l=!0;case`newline`:d+=i.source.length;break;case`comment`:n&&!l&&r(i,`MISSING_CHAR`,`Comments must be separated from other tokens by white space characters`),d+=i.source.length,u=i.source.substring(1);break;case`error`:r(i,`UNEXPECTED_TOKEN`,i.message),d+=i.source.length;break;default:{r(i,`UNEXPECTED_TOKEN`,`Unexpected token in block scalar header: ${i.type}`);let e=i.source;e&&typeof e==`string`&&(d+=e.length)}}}return{mode:a,indent:o,chomp:s,comment:u,length:d}}function i(e){let t=e.split(/\n( *)/),n=t[0],r=n.match(/^( *)/),i=[r?.[1]?[r[1],n.slice(r[1].length)]:[``,n]];for(let e=1;e<t.length;e+=2)i.push([t[e],t[e+1]]);return i}e.resolveBlockScalar=n})),Ge=A((e=>{var t=B(),n=J();function r(e,r,o){let{offset:c,type:l,source:u,end:d}=e,f,p,m=(e,t,n)=>o(c+e,t,n);switch(l){case`scalar`:f=t.Scalar.PLAIN,p=i(u,m);break;case`single-quoted-scalar`:f=t.Scalar.QUOTE_SINGLE,p=a(u,m);break;case`double-quoted-scalar`:f=t.Scalar.QUOTE_DOUBLE,p=s(u,m);break;default:return o(e,`UNEXPECTED_TOKEN`,`Expected a flow scalar value, but found: ${l}`),{value:``,type:null,comment:``,range:[c,c+u.length,c+u.length]}}let h=c+u.length,g=n.resolveEnd(d,h,r,o);return{value:p,type:f,comment:g.comment,range:[c,h,g.offset]}}function i(e,t){let n=``;switch(e[0]){case` `:n=`a tab character`;break;case`,`:n=`flow indicator character ,`;break;case`%`:n=`directive indicator character %`;break;case`|`:case`>`:n=`block scalar indicator ${e[0]}`;break;case`@`:case"`":n=`reserved character ${e[0]}`;break}return n&&t(0,`BAD_SCALAR_START`,`Plain value cannot start with ${n}`),o(e)}function a(e,t){return(e[e.length-1]!==`'`||e.length===1)&&t(e.length,`MISSING_CHAR`,`Missing closing 'quote`),o(e.slice(1,-1)).replace(/''/g,`'`)}function o(e){let t=/(.*?)\r?\n/sy,n=t.exec(e);if(!n)return e;let r,i;try{r=RegExp(`(?<![ ])[ ]+$`),i=RegExp(`^[ ]+|(?<![ ])[ ]+$`,`g`)}catch{r=/[ \t]+$/,i=/^[ \t]+|[ \t]+$/g}let a=n[1].replace(r,``),o=` `,s=t.lastIndex;for(;n=t.exec(e);){let e=n[1].replace(i,``);e===``?o===`
|
|
65
65
|
`?a+=o:o=`
|
|
66
66
|
`:(a+=o+e,o=` `),s=t.lastIndex}let c=/[ \t]*(.*)/sy;return c.lastIndex=s,n=c.exec(e),a+o+(n?.[1]??``)}function s(e,t){let n=``;for(let r=1;r<e.length-1;++r){let i=e[r];if(!(i===`\r`&&e[r+1]===`
|
|
67
67
|
`))if(i===`
|
|
@@ -74,10 +74,10 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
74
74
|
`);)r===`
|
|
75
75
|
`&&(n+=`
|
|
76
76
|
`),t+=1,r=e[t+1];return n||=` `,{fold:n,offset:t}}let l={0:`\0`,a:`\x07`,b:`\b`,e:`\x1B`,f:`\f`,n:`
|
|
77
|
-
`,r:`\r`,t:` `,v:`\v`,N:`
`,_:`\xA0`,L:`\u2028`,P:`\u2029`," ":` `,'"':`"`,"/":`/`,"\\":`\\`," ":` `};function u(e,t,n,r){let i=e.substr(t,n),a=i.length===n&&/^[0-9a-fA-F]+$/.test(i)?parseInt(i,16):NaN;try{return String.fromCodePoint(a)}catch{let i=e.substr(t-2,n+2);return r(t-2,`BAD_DQ_ESCAPE`,`Invalid escape sequence ${i}`),i}}e.resolveFlowScalar=r})),
|
|
77
|
+
`,r:`\r`,t:` `,v:`\v`,N:`
`,_:`\xA0`,L:`\u2028`,P:`\u2029`," ":` `,'"':`"`,"/":`/`,"\\":`\\`," ":` `};function u(e,t,n,r){let i=e.substr(t,n),a=i.length===n&&/^[0-9a-fA-F]+$/.test(i)?parseInt(i,16):NaN;try{return String.fromCodePoint(a)}catch{let i=e.substr(t-2,n+2);return r(t-2,`BAD_DQ_ESCAPE`,`Invalid escape sequence ${i}`),i}}e.resolveFlowScalar=r})),Ke=A((e=>{var t=M(),n=B(),r=We(),i=Ge();function a(e,a,c,l){let{value:u,type:d,comment:f,range:p}=a.type===`block-scalar`?r.resolveBlockScalar(e,a,l):i.resolveFlowScalar(a,e.options.strict,l),m=c?e.directives.tagName(c.source,e=>l(c,`TAG_RESOLVE_FAILED`,e)):null,h;h=e.options.stringKeys&&e.atKey?e.schema[t.SCALAR]:m?o(e.schema,u,m,c,l):a.type===`scalar`?s(e,u,a,l):e.schema[t.SCALAR];let g;try{let r=h.resolve(u,e=>l(c??a,`TAG_RESOLVE_FAILED`,e),e.options);g=t.isScalar(r)?r:new n.Scalar(r)}catch(e){let t=e instanceof Error?e.message:String(e);l(c??a,`TAG_RESOLVE_FAILED`,t),g=new n.Scalar(u)}return g.range=p,g.source=u,d&&(g.type=d),m&&(g.tag=m),h.format&&(g.format=h.format),f&&(g.comment=f),g}function o(e,n,r,i,a){if(r===`!`)return e[t.SCALAR];let o=[];for(let t of e.tags)if(!t.collection&&t.tag===r)if(t.default&&t.test)o.push(t);else return t;for(let e of o)if(e.test?.test(n))return e;let s=e.knownTags[r];return s&&!s.collection?(e.tags.push(Object.assign({},s,{default:!1,test:void 0})),s):(a(i,`TAG_RESOLVE_FAILED`,`Unresolved tag: ${r}`,r!==`tag:yaml.org,2002:str`),e[t.SCALAR])}function s({atKey:e,directives:n,schema:r},i,a,o){let s=r.tags.find(t=>(t.default===!0||e&&t.default===`key`)&&t.test?.test(i))||r[t.SCALAR];if(r.compat){let e=r.compat.find(e=>e.default&&e.test?.test(i))??r[t.SCALAR];s.tag!==e.tag&&o(a,`TAG_RESOLVE_FAILED`,`Value may be parsed as either ${n.tagString(s.tag)} or ${n.tagString(e.tag)}`,!0)}return s}e.composeScalar=a})),qe=A((e=>{function t(e,t,n){if(t){n??=t.length;for(let r=n-1;r>=0;--r){let n=t[r];switch(n.type){case`space`:case`comment`:case`newline`:e-=n.source.length;continue}for(n=t[++r];n?.type===`space`;)e+=n.source.length,n=t[++r];break}}return e}e.emptyScalarPosition=t})),Je=A((e=>{var t=z(),n=M(),r=Ue(),i=Ke(),a=J(),o=qe();let s={composeNode:c,composeEmptyNode:l};function c(e,t,a,o){let c=e.atKey,{spaceBefore:d,comment:f,anchor:p,tag:m}=a,h,g=!0;switch(t.type){case`alias`:h=u(e,t,o),(p||m)&&o(t,`ALIAS_PROPS`,`An alias node must not specify any properties`);break;case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:case`block-scalar`:h=i.composeScalar(e,t,m,o),p&&(h.anchor=p.source.substring(1));break;case`block-map`:case`block-seq`:case`flow-collection`:try{h=r.composeCollection(s,e,t,a,o),p&&(h.anchor=p.source.substring(1))}catch(e){o(t,`RESOURCE_EXHAUSTION`,e instanceof Error?e.message:String(e))}break;default:o(t,`UNEXPECTED_TOKEN`,t.type===`error`?t.message:`Unsupported token (type: ${t.type})`),g=!1}return h??=l(e,t.offset,void 0,null,a,o),p&&h.anchor===``&&o(p,`BAD_ALIAS`,`Anchor cannot be an empty string`),c&&e.options.stringKeys&&(!n.isScalar(h)||typeof h.value!=`string`||h.tag&&h.tag!==`tag:yaml.org,2002:str`)&&o(m??t,`NON_STRING_KEY`,`With stringKeys, all keys must be strings`),d&&(h.spaceBefore=!0),f&&(t.type===`scalar`&&t.source===``?h.comment=f:h.commentBefore=f),e.options.keepSourceTokens&&g&&(h.srcToken=t),h}function l(e,t,n,r,{spaceBefore:a,comment:s,anchor:c,tag:l,end:u},d){let f={type:`scalar`,offset:o.emptyScalarPosition(t,n,r),indent:-1,source:``},p=i.composeScalar(e,f,l,d);return c&&(p.anchor=c.source.substring(1),p.anchor===``&&d(c,`BAD_ALIAS`,`Anchor cannot be an empty string`)),a&&(p.spaceBefore=!0),s&&(p.comment=s,p.range[2]=u),p}function u({options:e},{offset:n,source:r,end:i},o){let s=new t.Alias(r.substring(1));s.source===``&&o(n,`BAD_ALIAS`,`Alias cannot be an empty string`),s.source.endsWith(`:`)&&o(n+r.length-1,`BAD_ALIAS`,`Alias ending in : is ambiguous`,!0);let c=n+r.length,l=a.resolveEnd(i,c,e.strict,o);return s.range=[n,c,l.offset],l.comment&&(s.comment=l.comment),s}e.composeEmptyNode=l,e.composeNode=c})),Ye=A((e=>{var t=Pe(),n=Je(),r=J(),i=Ie();function a(e,a,{offset:o,start:s,value:c,end:l},u){let d=Object.assign({_directives:a},e),f=new t.Document(void 0,d),p={atKey:!1,atRoot:!0,directives:f.directives,options:f.options,schema:f.schema},m=i.resolveProps(s,{indicator:`doc-start`,next:c??l?.[0],offset:o,onError:u,parentIndent:0,startOnNewline:!0});m.found&&(f.directives.docStart=!0,c&&(c.type===`block-map`||c.type===`block-seq`)&&!m.hasNewline&&u(m.end,`MISSING_CHAR`,`Block collection cannot start on same line with directives-end marker`)),f.contents=c?n.composeNode(p,c,m,u):n.composeEmptyNode(p,m.end,s,null,m,u);let h=f.contents.range[2],g=r.resolveEnd(l,h,!1,u);return g.comment&&(f.comment=g.comment),f.range=[o,h,g.offset],f}e.composeDoc=a})),Xe=A((e=>{var t=j(`process`),n=P(),r=Pe(),i=Fe(),a=M(),o=Ye(),s=J();function c(e){if(typeof e==`number`)return[e,e+1];if(Array.isArray(e))return e.length===2?e:[e[0],e[1]];let{offset:t,source:n}=e;return[t,t+(typeof n==`string`?n.length:1)]}function l(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;++i){let a=e[i];switch(a[0]){case`#`:t+=(t===``?``:r?`
|
|
78
78
|
|
|
79
79
|
`:`
|
|
80
|
-
`)+(a.substring(1)||` `),n=!0,r=!1;break;case`%`:e[i+1]?.[0]!==`#`&&(i+=1),n=!1;break;default:n||(r=!0),n=!1}}return{comment:t,afterEmptyLine:r}}e.Composer=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,r)=>{let a=c(e);r?this.warnings.push(new i.YAMLWarning(a,t,n)):this.errors.push(new i.YAMLParseError(a,t,n))},this.directives=new n.Directives({version:e.version||`1.2`}),this.options=e}decorate(e,t){let{comment:n,afterEmptyLine:r}=l(this.prelude);if(n){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(r||e.directives.docStart||!i)e.commentBefore=n;else if(a.isCollection(i)&&!i.flow&&i.items.length>0){let e=i.items[0];a.isPair(e)&&(e=e.key);let t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{let e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}if(t){for(let t=0;t<this.errors.length;++t)e.errors.push(this.errors[t]);for(let t=0;t<this.warnings.length;++t)e.warnings.push(this.warnings[t])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:l(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(let t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(t.env.LOG_STREAM&&console.dir(e,{depth:null}),e.type){case`directive`:this.directives.add(e.source,(t,n,r)=>{let i=c(e);i[0]+=t,this.onError(i,`BAD_DIRECTIVE`,n,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case`document`:{let t=o.composeDoc(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,`MISSING_CHAR`,`Missing directives-end/doc-start indicator line`),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case`byte-order-mark`:case`space`:break;case`comment`:case`newline`:this.prelude.push(e.source);break;case`error`:{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case`doc-end`:{if(!this.doc){this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unexpected doc-end without preceding document`));break}this.doc.directives.docEnd=!0;let t=s.resolveEnd(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let e=Object.assign({_directives:this.directives},this.options),n=new r.Document(void 0,e);this.atDirectives&&this.onError(t,`MISSING_CHAR`,`Missing directives-end indicator line`),n.range=[0,t,t],this.decorate(n,!1),yield n}}}})),
|
|
80
|
+
`)+(a.substring(1)||` `),n=!0,r=!1;break;case`%`:e[i+1]?.[0]!==`#`&&(i+=1),n=!1;break;default:n||(r=!0),n=!1}}return{comment:t,afterEmptyLine:r}}e.Composer=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,r)=>{let a=c(e);r?this.warnings.push(new i.YAMLWarning(a,t,n)):this.errors.push(new i.YAMLParseError(a,t,n))},this.directives=new n.Directives({version:e.version||`1.2`}),this.options=e}decorate(e,t){let{comment:n,afterEmptyLine:r}=l(this.prelude);if(n){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(r||e.directives.docStart||!i)e.commentBefore=n;else if(a.isCollection(i)&&!i.flow&&i.items.length>0){let e=i.items[0];a.isPair(e)&&(e=e.key);let t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{let e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}if(t){for(let t=0;t<this.errors.length;++t)e.errors.push(this.errors[t]);for(let t=0;t<this.warnings.length;++t)e.warnings.push(this.warnings[t])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:l(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(let t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(t.env.LOG_STREAM&&console.dir(e,{depth:null}),e.type){case`directive`:this.directives.add(e.source,(t,n,r)=>{let i=c(e);i[0]+=t,this.onError(i,`BAD_DIRECTIVE`,n,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case`document`:{let t=o.composeDoc(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,`MISSING_CHAR`,`Missing directives-end/doc-start indicator line`),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case`byte-order-mark`:case`space`:break;case`comment`:case`newline`:this.prelude.push(e.source);break;case`error`:{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case`doc-end`:{if(!this.doc){this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unexpected doc-end without preceding document`));break}this.doc.directives.docEnd=!0;let t=s.resolveEnd(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new i.YAMLParseError(c(e),`UNEXPECTED_TOKEN`,`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let e=Object.assign({_directives:this.directives},this.options),n=new r.Document(void 0,e);this.atDirectives&&this.onError(t,`MISSING_CHAR`,`Missing directives-end indicator line`),n.range=[0,t,t],this.decorate(n,!1),yield n}}}})),Ze=A((e=>{var t=We(),n=Ge(),r=Fe(),i=ce();function a(e,i=!0,a){if(e){let o=(e,t,n)=>{let i=typeof e==`number`?e:Array.isArray(e)?e[0]:e.offset;if(a)a(i,t,n);else throw new r.YAMLParseError([i,i+1],t,n)};switch(e.type){case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return n.resolveFlowScalar(e,i,o);case`block-scalar`:return t.resolveBlockScalar({options:{strict:i}},e,o)}}return null}function o(e,t){let{implicitKey:n=!1,indent:r,inFlow:a=!1,offset:o=-1,type:s=`PLAIN`}=t,c=i.stringifyString({type:s,value:e},{implicitKey:n,indent:r>0?` `.repeat(r):``,inFlow:a,options:{blockQuote:!0,lineWidth:-1}}),u=t.end??[{type:`newline`,offset:-1,indent:r,source:`
|
|
81
81
|
`}];switch(c[0]){case`|`:case`>`:{let e=c.indexOf(`
|
|
82
82
|
`),t=c.substring(0,e),n=c.substring(e+1)+`
|
|
83
83
|
`,i=[{type:`block-scalar-header`,offset:o,indent:r,source:t}];return l(i,u)||i.push({type:`newline`,offset:-1,indent:r,source:`
|
|
@@ -85,9 +85,9 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
85
85
|
`),r=t.substring(0,n),i=t.substring(n+1)+`
|
|
86
86
|
`;if(e.type===`block-scalar`){let t=e.props[0];if(t.type!==`block-scalar-header`)throw Error(`Invalid block scalar header`);t.source=r,e.source=i}else{let{offset:t}=e,n=`indent`in e?e.indent:-1,a=[{type:`block-scalar-header`,offset:t,indent:n,source:r}];l(a,`end`in e?e.end:void 0)||a.push({type:`newline`,offset:-1,indent:n,source:`
|
|
87
87
|
`});for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:`block-scalar`,indent:n,props:a,source:i})}}function l(e,t){if(t)for(let n of t)switch(n.type){case`space`:case`comment`:e.push(n);break;case`newline`:return e.push(n),!0}return!1}function u(e,t,n){switch(e.type){case`scalar`:case`double-quoted-scalar`:case`single-quoted-scalar`:e.type=n,e.source=t;break;case`block-scalar`:{let r=e.props.slice(1),i=t.length;e.props[0].type===`block-scalar-header`&&(i-=e.props[0].source.length);for(let e of r)e.offset+=i;delete e.props,Object.assign(e,{type:n,source:t,end:r});break}case`block-map`:case`block-seq`:{let r={type:`newline`,offset:e.offset+t.length,indent:e.indent,source:`
|
|
88
|
-
`};delete e.items,Object.assign(e,{type:n,source:t,end:[r]});break}default:{let r=`indent`in e?e.indent:-1,i=`end`in e&&Array.isArray(e.end)?e.end.filter(e=>e.type===`space`||e.type===`comment`||e.type===`newline`):[];for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:n,indent:r,source:t,end:i})}}}e.createScalarToken=o,e.resolveAsScalar=a,e.setScalarValue=s})),
|
|
88
|
+
`};delete e.items,Object.assign(e,{type:n,source:t,end:[r]});break}default:{let r=`indent`in e?e.indent:-1,i=`end`in e&&Array.isArray(e.end)?e.end.filter(e=>e.type===`space`||e.type===`comment`||e.type===`newline`):[];for(let t of Object.keys(e))t!==`type`&&t!==`offset`&&delete e[t];Object.assign(e,{type:n,indent:r,source:t,end:i})}}}e.createScalarToken=o,e.resolveAsScalar=a,e.setScalarValue=s})),Qe=A((e=>{let t=e=>`type`in e?n(e):r(e);function n(e){switch(e.type){case`block-scalar`:{let t=``;for(let r of e.props)t+=n(r);return t+e.source}case`block-map`:case`block-seq`:{let t=``;for(let n of e.items)t+=r(n);return t}case`flow-collection`:{let t=e.start.source;for(let n of e.items)t+=r(n);for(let n of e.end)t+=n.source;return t}case`document`:{let t=r(e);if(e.end)for(let n of e.end)t+=n.source;return t}default:{let t=e.source;if(`end`in e&&e.end)for(let n of e.end)t+=n.source;return t}}}function r({start:e,key:t,sep:r,value:i}){let a=``;for(let t of e)a+=t.source;if(t&&(a+=n(t)),r)for(let e of r)a+=e.source;return i&&(a+=n(i)),a}e.stringify=t})),$e=A((e=>{let t=Symbol(`break visit`),n=Symbol(`skip children`),r=Symbol(`remove item`);function i(e,t){`type`in e&&e.type===`document`&&(e={start:e.start,value:e.value}),a(Object.freeze([]),e,t)}i.BREAK=t,i.SKIP=n,i.REMOVE=r,i.itemAtPath=(e,t)=>{let n=e;for(let[e,r]of t){let t=n?.[e];if(t&&`items`in t)n=t.items[r];else return}return n},i.parentCollection=(e,t)=>{let n=i.itemAtPath(e,t.slice(0,-1)),r=t[t.length-1][0],a=n?.[r];if(a&&`items`in a)return a;throw Error(`Parent collection not found`)};function a(e,n,i){let o=i(n,e);if(typeof o==`symbol`)return o;for(let s of[`key`,`value`]){let c=n[s];if(c&&`items`in c){for(let n=0;n<c.items.length;++n){let o=a(Object.freeze(e.concat([[s,n]])),c.items[n],i);if(typeof o==`number`)n=o-1;else if(o===t)return t;else o===r&&(c.items.splice(n,1),--n)}typeof o==`function`&&s===`key`&&(o=o(n,e))}}return typeof o==`function`?o(n,e):o}e.visit=i})),et=A((e=>{var t=Ze(),n=Qe(),r=$e();let i=e=>!!e&&`items`in e,a=e=>!!e&&(e.type===`scalar`||e.type===`single-quoted-scalar`||e.type===`double-quoted-scalar`||e.type===`block-scalar`);function o(e){switch(e){case``:return`<BOM>`;case``:return`<DOC>`;case``:return`<FLOW_END>`;case``:return`<SCALAR>`;default:return JSON.stringify(e)}}function s(e){switch(e){case``:return`byte-order-mark`;case``:return`doc-mode`;case``:return`flow-error-end`;case``:return`scalar`;case`---`:return`doc-start`;case`...`:return`doc-end`;case``:case`
|
|
89
89
|
`:case`\r
|
|
90
|
-
`:return`newline`;case`-`:return`seq-item-ind`;case`?`:return`explicit-key-ind`;case`:`:return`map-value-ind`;case`{`:return`flow-map-start`;case`}`:return`flow-map-end`;case`[`:return`flow-seq-start`;case`]`:return`flow-seq-end`;case`,`:return`comma`}switch(e[0]){case` `:case` `:return`space`;case`#`:return`comment`;case`%`:return`directive-line`;case`*`:return`alias`;case`&`:return`anchor`;case`!`:return`tag`;case`'`:return`single-quoted-scalar`;case`"`:return`double-quoted-scalar`;case`|`:case`>`:return`block-scalar-header`}return null}e.createScalarToken=t.createScalarToken,e.resolveAsScalar=t.resolveAsScalar,e.setScalarValue=t.setScalarValue,e.stringify=n.stringify,e.visit=r.visit,e.BOM=``,e.DOCUMENT=``,e.FLOW_END=``,e.SCALAR=``,e.isCollection=i,e.isScalar=a,e.prettyToken=o,e.tokenType=s}))
|
|
90
|
+
`:return`newline`;case`-`:return`seq-item-ind`;case`?`:return`explicit-key-ind`;case`:`:return`map-value-ind`;case`{`:return`flow-map-start`;case`}`:return`flow-map-end`;case`[`:return`flow-seq-start`;case`]`:return`flow-seq-end`;case`,`:return`comma`}switch(e[0]){case` `:case` `:return`space`;case`#`:return`comment`;case`%`:return`directive-line`;case`*`:return`alias`;case`&`:return`anchor`;case`!`:return`tag`;case`'`:return`single-quoted-scalar`;case`"`:return`double-quoted-scalar`;case`|`:case`>`:return`block-scalar-header`}return null}e.createScalarToken=t.createScalarToken,e.resolveAsScalar=t.resolveAsScalar,e.setScalarValue=t.setScalarValue,e.stringify=n.stringify,e.visit=r.visit,e.BOM=``,e.DOCUMENT=``,e.FLOW_END=``,e.SCALAR=``,e.isCollection=i,e.isScalar=a,e.prettyToken=o,e.tokenType=s})),tt=A((e=>{var t=et();function n(e){switch(e){case void 0:case` `:case`
|
|
91
91
|
`:case`\r`:case` `:return!0;default:return!1}}let r=new Set(`0123456789ABCDEFabcdef`),i=new Set(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()`),a=new Set(`,[]{}`),o=new Set(` ,[]{}
|
|
92
92
|
\r `),s=e=>!e||o.has(e);e.Lexer=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer=``,this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if(typeof e!=`string`)throw TypeError(`source is not a string`);this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let n=this.next??`stream`;for(;n&&(t||this.hasChars(1));)n=yield*this.parseNext(n)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;t===` `||t===` `;)t=this.buffer[++e];return!t||t===`#`||t===`
|
|
93
93
|
`?!0:t===`\r`?this.buffer[e+1]===`
|
|
@@ -106,14 +106,14 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
106
106
|
`,t=this.buffer[i+1]):r=i),t===`#`||e&&a.has(t))break;if(o===`
|
|
107
107
|
`){let e=this.continueScalar(i+1);if(e===-1)break;i=Math.max(i,e-2)}}else{if(e&&a.has(o))break;r=i}return!o&&!this.atEnd?this.setNext(`plain-scalar`):(yield t.SCALAR,yield*this.pushToIndex(r+1,!0),e?`flow`:`doc`)}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){let n=this.buffer.slice(this.pos,e);return n?(yield n,this.pos+=n.length,n.length):(t&&(yield``),0)}*pushIndicators(){let e=0;loop:for(;;){switch(this.charAt(0)){case`!`:e+=yield*this.pushTag(),e+=yield*this.pushSpaces(!0);continue loop;case`&`:e+=yield*this.pushUntil(s),e+=yield*this.pushSpaces(!0);continue loop;case`-`:case`?`:case`:`:{let t=this.flowLevel>0,r=this.charAt(1);if(n(r)||t&&a.has(r)){t?this.flowKey&&=!1:this.indentNext=this.indentValue+1,e+=yield*this.pushCount(1),e+=yield*this.pushSpaces(!0);continue loop}}}break loop}return e}*pushTag(){if(this.charAt(1)===`<`){let e=this.pos+2,t=this.buffer[e];for(;!n(t)&&t!==`>`;)t=this.buffer[++e];return yield*this.pushToIndex(t===`>`?e+1:e,!1)}else{let e=this.pos+1,t=this.buffer[e];for(;t;)if(i.has(t))t=this.buffer[++e];else if(t===`%`&&r.has(this.buffer[e+1])&&r.has(this.buffer[e+2]))t=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
|
|
108
108
|
`?yield*this.pushCount(1):e===`\r`&&this.charAt(1)===`
|
|
109
|
-
`?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,n;do n=this.buffer[++t];while(n===` `||e&&n===` `);let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}}})),
|
|
109
|
+
`?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,n;do n=this.buffer[++t];while(n===` `||e&&n===` `);let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}}})),nt=A((e=>{e.LineCounter=class{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let t=0,n=this.lineStarts.length;for(;t<n;){let r=t+n>>1;this.lineStarts[r]<e?t=r+1:n=r}if(this.lineStarts[t]===e)return{line:t+1,col:1};if(t===0)return{line:0,col:e};let r=this.lineStarts[t-1];return{line:t,col:e-r+1}}}}})),rt=A((e=>{var t=j(`process`),n=et(),r=tt();function i(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function a(e){for(let t=0;t<e.length;++t)switch(e[t].type){case`space`:case`comment`:case`newline`:break;default:return t}return-1}function o(e){switch(e?.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:case`flow-collection`:return!0;default:return!1}}function s(e){switch(e.type){case`document`:return e.start;case`block-map`:{let t=e.items[e.items.length-1];return t.sep??t.start}case`block-seq`:return e.items[e.items.length-1].start;default:return[]}}function c(e){if(e.length===0)return[];let t=e.length;loop:for(;--t>=0;)switch(e[t].type){case`doc-start`:case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:case`newline`:break loop}for(;e[++t]?.type===`space`;);return e.splice(t,e.length)}function l(e,t){if(t.length<1e5)Array.prototype.push.apply(e,t);else for(let n=0;n<t.length;++n)e.push(t[n])}function u(e){if(e.start.type===`flow-seq-start`)for(let t of e.items)t.sep&&!t.value&&!i(t.start,`explicit-key-ind`)&&!i(t.sep,`map-value-ind`)&&(t.key&&(t.value=t.key),delete t.key,o(t.value)?t.value.end?l(t.value.end,t.sep):t.value.end=t.sep:l(t.start,t.sep),delete t.sep)}e.Parser=class{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source=``,this.type=``,this.lexer=new r.Lexer,this.onNewLine=e}*parse(e,t=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(let n of this.lexer.lex(e,t))yield*this.next(n);t||(yield*this.end())}*next(e){if(this.source=e,t.env.LOG_TOKENS&&console.log(`|`,n.prettyToken(e)),this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=e.length;return}let r=n.tokenType(e);if(r)if(r===`scalar`)this.atNewLine=!1,this.atScalar=!0,this.type=`scalar`;else{switch(this.type=r,yield*this.step(),r){case`newline`:this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case`space`:this.atNewLine&&e[0]===` `&&(this.indent+=e.length);break;case`explicit-key-ind`:case`map-value-ind`:case`seq-item-ind`:this.atNewLine&&(this.indent+=e.length);break;case`doc-mode`:case`flow-error-end`:return;default:this.atNewLine=!1}this.offset+=e.length}else{let t=`Not a YAML token: ${e}`;yield*this.pop({type:`error`,offset:this.offset,message:t,source:e}),this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){let e=this.peek(1);if(this.type===`doc-end`&&e?.type!==`doc-end`){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:`doc-end`,offset:this.offset,source:this.source});return}if(!e)return yield*this.stream();switch(e.type){case`document`:return yield*this.document(e);case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return yield*this.scalar(e);case`block-scalar`:return yield*this.blockScalar(e);case`block-map`:return yield*this.blockMap(e);case`block-seq`:return yield*this.blockSequence(e);case`flow-collection`:return yield*this.flowCollection(e);case`doc-end`:return yield*this.documentEnd(e)}yield*this.pop()}peek(e){return this.stack[this.stack.length-e]}*pop(e){let t=e??this.stack.pop();if(!t)yield{type:`error`,offset:this.offset,source:``,message:`Tried to pop an empty stack`};else if(this.stack.length===0)yield t;else{let e=this.peek(1);switch(t.type===`block-scalar`?t.indent=`indent`in e?e.indent:0:t.type===`flow-collection`&&e.type===`document`&&(t.indent=0),t.type===`flow-collection`&&u(t),e.type){case`document`:e.value=t;break;case`block-scalar`:e.props.push(t);break;case`block-map`:{let n=e.items[e.items.length-1];if(n.value){e.items.push({start:[],key:t,sep:[]}),this.onKeyLine=!0;return}else if(n.sep)n.value=t;else{Object.assign(n,{key:t,sep:[]}),this.onKeyLine=!n.explicitKey;return}break}case`block-seq`:{let n=e.items[e.items.length-1];n.value?e.items.push({start:[],value:t}):n.value=t;break}case`flow-collection`:{let n=e.items[e.items.length-1];!n||n.value?e.items.push({start:[],key:t,sep:[]}):n.sep?n.value=t:Object.assign(n,{key:t,sep:[]});return}default:yield*this.pop(),yield*this.pop(t)}if((e.type===`document`||e.type===`block-map`||e.type===`block-seq`)&&(t.type===`block-map`||t.type===`block-seq`)){let n=t.items[t.items.length-1];n&&!n.sep&&!n.value&&n.start.length>0&&a(n.start)===-1&&(t.indent===0||n.start.every(e=>e.type!==`comment`||e.indent<t.indent))&&(e.type===`document`?e.end=n.start:e.items.push({start:n.start}),t.items.splice(-1,1))}}}*stream(){switch(this.type){case`directive-line`:yield{type:`directive`,offset:this.offset,source:this.source};return;case`byte-order-mark`:case`space`:case`comment`:case`newline`:yield this.sourceToken;return;case`doc-mode`:case`doc-start`:{let e={type:`document`,offset:this.offset,start:[]};this.type===`doc-start`&&e.start.push(this.sourceToken),this.stack.push(e);return}}yield{type:`error`,offset:this.offset,message:`Unexpected ${this.type} token in YAML stream`,source:this.source}}*document(e){if(e.value)return yield*this.lineEnd(e);switch(this.type){case`doc-start`:a(e.start)===-1?e.start.push(this.sourceToken):(yield*this.pop(),yield*this.step());return;case`anchor`:case`tag`:case`space`:case`comment`:case`newline`:e.start.push(this.sourceToken);return}let t=this.startBlockValue(e);t?this.stack.push(t):yield{type:`error`,offset:this.offset,message:`Unexpected ${this.type} token in YAML document`,source:this.source}}*scalar(e){if(this.type===`map-value-ind`){let t=c(s(this.peek(2))),n;e.end?(n=e.end,n.push(this.sourceToken),delete e.end):n=[this.sourceToken];let r={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:t,key:e,sep:n}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=r}else yield*this.lineEnd(e)}*blockScalar(e){switch(this.type){case`space`:case`comment`:case`newline`:e.props.push(this.sourceToken);return;case`scalar`:if(e.source=this.source,this.atNewLine=!0,this.indent=0,this.onNewLine){let e=this.source.indexOf(`
|
|
110
110
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
111
111
|
`,e)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(this.onKeyLine=!1,t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){l(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let n=!this.onKeyLine&&this.indent===e.indent,r=n&&(t.sep||t.explicitKey)&&this.type!==`seq-item-ind`,a=[];if(r&&t.sep&&!t.value){let n=[];for(let r=0;r<t.sep.length;++r){let i=t.sep[r];switch(i.type){case`newline`:n.push(r);break;case`space`:break;case`comment`:i.indent>e.indent&&(n.length=0);break;default:n.length=0}}n.length>=2&&(a=t.sep.splice(n[1]))}switch(this.type){case`anchor`:case`tag`:r||t.value?(a.push(this.sourceToken),e.items.push({start:a}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`explicit-key-ind`:!t.sep&&!t.explicitKey?(t.start.push(this.sourceToken),t.explicitKey=!0):r||t.value?(a.push(this.sourceToken),e.items.push({start:a,explicitKey:!0})):this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case`map-value-ind`:if(t.explicitKey)if(t.sep)if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(i(t.sep,`map-value-ind`))this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:a,key:null,sep:[this.sourceToken]}]});else if(o(t.key)&&!i(t.sep,`newline`)){let e=c(t.start),n=t.key,r=t.sep;r.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:n,sep:r}]})}else a.length>0?t.sep=t.sep.concat(a,this.sourceToken):t.sep.push(this.sourceToken);else if(i(t.start,`newline`))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let e=c(t.start);this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:null,sep:[this.sourceToken]}]})}else t.sep?t.value||r?e.items.push({start:a,key:null,sep:[this.sourceToken]}):i(t.sep,`map-value-ind`)?this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);r||t.value?(e.items.push({start:a,key:n,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(n):(Object.assign(t,{key:n,sep:[]}),this.onKeyLine=!0);return}default:{let r=this.startBlockValue(e);if(r){if(r.type===`block-seq`){if(!t.explicitKey&&t.sep&&!i(t.sep,`newline`)){yield*this.pop({type:`error`,offset:this.offset,message:`Unexpected block-seq-ind on same line with key`,source:this.source});return}}else n&&e.items.push({start:a});this.stack.push(r);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){l(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case`anchor`:case`tag`:if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case`seq-item-ind`:if(this.indent!==e.indent)break;t.value||i(t.start,`seq-item-ind`)?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return}if(this.indent>e.indent){let t=this.startBlockValue(e);if(t){this.stack.push(t);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type===`flow-error-end`){let e;do yield*this.pop(),e=this.peek(1);while(e?.type===`flow-collection`)}else if(e.end.length===0){switch(this.type){case`comma`:case`explicit-key-ind`:!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return;case`map-value-ind`:!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return;case`space`:case`comment`:case`newline`:case`anchor`:case`tag`:!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);!t||t.value?e.items.push({start:[],key:n,sep:[]}):t.sep?this.stack.push(n):Object.assign(t,{key:n,sep:[]});return}case`flow-map-end`:case`flow-seq-end`:e.end.push(this.sourceToken);return}let n=this.startBlockValue(e);n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=c(s(t));u(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
|
|
112
112
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
113
|
-
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;case`space`:case`comment`:default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),
|
|
114
|
-
`;)n++;continue}if(a===`/`&&e[n+1]===`*`){for(n+=2;n<r&&!(e[n]===`*`&&e[n+1]===`/`);)n++;n+=2;continue}t+=a,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function ot(e,t=new WeakSet){if(typeof e==`string`)return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>{let n=process.env[t];return n===void 0?e:n});if(Array.isArray(e))return e.map(e=>ot(e,t));if(typeof e==`object`&&e){let n=e;if(t.has(n))return e;t.add(n);let r={};for(let[e,i]of Object.entries(n))r[e]=ot(i,t);return t.delete(n),r}return e}function st(e=rt()){let t=it(e);if(t===null)return{path:null,config:{}};let n=C(t,`utf-8`);try{let e=JSON.parse(at(n));if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`config 顶层必须是对象`);return{path:t,config:ot(e)}}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`config 解析失败(${t}):${n}`)}}function ct(e,t,n,r=500){let i=new Set(t),a,o=!1,s=()=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>{o||n()},r)},c;try{c=T(e,{persistent:!1},(e,t)=>{t!==null&&!i.has(t)||s()})}catch{return{dispose:()=>{o=!0}}}return c.on(`error`,()=>{}),{dispose:()=>{o=!0,a!==void 0&&clearTimeout(a),c.close()}}}function lt(e,t){return t.image===void 0?e.map(e=>{if(!Array.isArray(e.content))return e;let t=[];for(let n of e.content){let e=n;if(e.type!==`image`){t.push(n);continue}let r=e.mimeType??(typeof e.image==`object`&&e.image?e.image.mediaType:void 0),i=r===void 0?`[image]`:`[image: ${r}]`,a=t.length-1,o=t[a];o?.type===`text`?t[a]={...o,text:o.text+i}:t.push({type:`text`,text:i})}return{...e,content:t}}):e}var ut=class extends Error{constructor(e){super(`Model not configured: ${e}`),this.modelId=e,this.name=`ModelNotConfiguredError`}},Z=class extends Error{constructor(e,t){super(`Provider not configured: ${e}${t?` (${t})`:``}`),this.ref=e,this.detail=t,this.name=`ProviderNotConfiguredError`}},dt=class extends Error{constructor(e){super(`Effort template not found: "${e}"`),this.templateName=e,this.name=`EffortTemplateNotFoundError`}},ft=class extends Error{constructor(e,t){super(`Effort default "${t}" not in resolved levels (model ${e})`),this.ref=e,this.defaultId=t,this.name=`EffortDefaultNotInLevelsError`}};function pt(e,t){let n=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=n.get(e.id);n.set(e.id,t===void 0?e:{...t,...e})}return[...n.values()]}function mt(e,t,n){let r=e?.levels;if(!(r===void 0||r.length===0))return n!==void 0&&r.some(e=>e.id===n)?n:t!==void 0&&r.some(e=>e.id===t)?t:e?.default??r[0]?.id}function ht(e,t,n){if(!e)return;if(!e.effort)return e;let r=e.effort,i;if(r.template!==void 0){let n=t?.[r.template];if(n===void 0)throw new dt(r.template);let a=pt(n.levels,r.levels??[]);if(a.length===0)return{...e,effort:void 0};i={...n,default:r.default??n.default??a[0].id,levels:a}}else if(r.levels!==void 0&&r.levels.length>0)i={...r,default:r.default??r.levels[0].id,levels:r.levels};else return{...e,effort:void 0};let a=i.default;if(!i.levels.some(e=>e.id===a))throw new ft(n??`(unknown)`,a);return{...e,effort:i}}const gt=e=>Array.isArray(e);function _t(e){return e.map(e=>{if(e.role!==`assistant`)return e;if(gt(e.content))return e.content.some(e=>e.type===`reasoning`)?e:{...e,content:[...e.content,{type:`reasoning`,text:``}]};let t=typeof e.content==`string`?e.content:``;return{...e,content:[...t?[{type:`text`,text:t}]:[],{type:`reasoning`,text:``}]}})}function vt(e){let t=e=>e.replace(/[^a-zA-Z0-9_-]/g,`_`);return e.map(e=>gt(e.content)?{...e,content:e.content.map(e=>{let n=e;return(n.type===`tool-call`||n.type===`tool-result`)&&n.toolCallId!==void 0?{...n,toolCallId:t(n.toolCallId)}:n})}:e)}function yt(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&t.push(r);let i=e[n+1];r?.role===`tool`&&i?.role===`user`&&t.push({role:`assistant`,content:[{type:`text`,text:`Done.`}]})}return t}function bt(e){return e.filter(e=>!(gt(e.content)&&e.content.length===0))}const xt={"ensure-assistant-reasoning":_t,"scrub-tool-call-id":vt,"done-after-tool":yt,"drop-empty-content":bt};function St(e,t=[]){return t.reduce((e,t)=>xt[t](e),e)}function Ct(e){switch(e){case`openai`:return`openai`;case`anthropic`:return`anthropic`;case`openai-compatible`:return`openaiCompatible`}}function wt(e){return e===void 0||e===`none`?`none`:typeof e==`string`?{mode:`automatic`,ttl:`5m`}:{...e}}function Tt(e){let t=Et(e);return a(`sha256`).update(t).digest(`hex`).slice(0,16)}function Et(e){return JSON.stringify(Dt(e))}function Dt(e){if(Array.isArray(e))return e.map(Dt);if(typeof e==`object`&&e){let t=e;return Object.fromEntries(Object.keys(t).sort().map(e=>[e,Dt(t[e])]))}return e}function Ot(e,t){return e===`openai-compatible`?t:Ct(e)}const kt=/\$\{(\w+(?:\.\w+)?)\}/g;function At(e,t,n){let r=e.replace(kt,(e,r)=>{switch(r){case`sessionId`:return t.sessionId;case`effort`:return n??t.effort??``;case`model.output`:return String(t.model.output);case`model.context`:return String(t.model.context);default:return``}});return r=jt(r),r}function jt(e){let t=e;return t=t.replace(/min\(([^)]+)\)/g,(e,t)=>{let n=t.split(`,`).map(e=>Number.parseFloat(e.trim()));return String(Math.min(...n))}),t=t.replace(/max\(([^)]+)\)/g,(e,t)=>{let n=t.split(`,`).map(e=>Number.parseFloat(e.trim()));return String(Math.max(...n))}),t=t.replace(/floor\(([^)]+)\)/g,(e,t)=>String(Math.floor(Number.parseFloat(t.trim())))),t}function Mt(e,t,n,r,i,a){let o=Ct(t.protocol),s=t.protocol===`anthropic`?`anthropic`:o,c=mt(t.reasoning?.effort,void 0,n.effort),l=St(e,t.quirks);l=lt(l,t);let u=t.reasoning;if(u?.interleaved===!0&&u.field!==void 0){let e=u.field;l=l.map(t=>{if(t.role!==`assistant`||!Array.isArray(t.content))return t;let n=t.content.filter(e=>e.type===`reasoning`).map(e=>e.text??``).join(``),r=t.content.filter(e=>e.type!==`reasoning`),i=t.providerOptions,a=i?.[o]??{};return{...t,content:r,providerOptions:{...i,[o]:{...a,[e]:n}}}})}let d=wt(t.cache),f=r,p=null,m=null;if(d!==`none`){let e=d.ttl,n=d.mode===`explicit`?d.scope??[`system`,`tools`]:[`system`,`messages`],i={type:`ephemeral`,ttl:e},o=n.includes(`system`);if(o&&(f={role:`system`,content:r,providerOptions:{[s]:{cacheControl:i}}}),n.includes(`tools`)&&(p=i,m=s),n.includes(`messages`)&&(a?.messageBreakpoints??!0)){let e=t.protocol===`anthropic`?Math.max(0,4-(o?1:0)-(p===null?0:1)):1;if(e>0){let n=l.slice(-e);for(let e of n)Nt(e,i,s,t.protocol)}}}let h={...t.body??{}};for(let[e,r]of Object.entries(t.body_templates??{}))h[e]=At(r,n,c);let g=t.reasoning?.effort?.levels;if(c!==void 0&&g!==void 0){let e=g.find(e=>e.id===c);e?.body!==void 0&&Object.assign(h,e.body)}let _=h;if(t.when?.reasoning===!0&&!n.reasoningEnabled){let e=t.when?.reasoning_keys??[`enable_thinking`,`thinking`];_=Object.fromEntries(Object.entries(h).filter(([t])=>!e.includes(t)))}let v=Ot(t.protocol,i),y={};if(Object.keys(_).length>0){let e={..._};t.protocol===`openai-compatible`&&typeof e.reasoning_effort==`string`&&e.reasoningEffort===void 0&&(e.reasoningEffort=e.reasoning_effort),y[v]=e}return{messages:l,system:f,providerOptions:y,extraBody:_,toolsCacheControl:p,toolsCacheControlKey:m}}function Nt(e,t,n,r){if(r!==`anthropic`&&Array.isArray(e.content)&&e.content.length>0){let r=e.content[e.content.length-1],i=r.providerOptions?.[n]??{};r.providerOptions={...r.providerOptions,[n]:{...i,cacheControl:t}}}else{let r=e,i=r.providerOptions?.[n]??{};r.providerOptions={...r.providerOptions,[n]:{...i,cacheControl:t}}}}function Pt(e){return M({apiKey:e.apiKey,baseURL:e.baseURL,headers:e.headers,fetch:e.fetch})(e.upstream_model)}function Ft(){return{extractMetadata:async({parsedBody:e})=>{let t=e?.usage;return t===void 0?void 0:{usage:t}},createStreamExtractor:()=>{let e;return{processChunk(t){let n=t?.usage;n!==void 0&&(e=n)},buildMetadata(){return e===void 0?void 0:{usage:e}}}}}}function It(e){return N({name:e.provider_name,apiKey:e.apiKey,baseURL:e.baseURL??`http://offline.invalid/v1`,headers:e.headers,fetch:e.fetch,includeUsage:!0,metadataExtractor:Ft(),supportedUrls:()=>({"image/*":[/^https?:\/\//]})}).chatModel(e.upstream_model)}function Lt(e){return P({apiKey:e.apiKey,baseURL:e.baseURL,headers:e.headers,fetch:e.fetch})(e.upstream_model)}function Rt(e,t){let{provider_name:n,upstream_model:r,traits:i,credentials:a}=e,o=t?.drain,s=t?.headers===void 0&&a.headers===void 0?void 0:{...a.headers??{},...t?.headers??{}},c;switch(i.protocol){case`openai`:c=Lt({upstream_model:r,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break;case`openai-compatible`:c=It({upstream_model:r,provider_name:n,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break;case`anthropic`:c=Pt({upstream_model:r,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break}return{streamText(e){return A({model:c,system:e.system,messages:e.messages,providerOptions:e.providerOptions,tools:e.tools,toolChoice:e.toolChoice,abortSignal:e.signal,maxRetries:e.maxRetries??0,...e.params})},dispose(){return o?.()}}}const zt=D.enum([`openai`,`openai-compatible`,`anthropic`]),Bt=D.enum([`5m`,`1h`]),Vt=D.object({mode:D.enum([`automatic`,`explicit`]),ttl:Bt,scope:D.array(D.enum([`system`,`tools`,`messages`])).optional()}),Ht=D.enum([`ensure-assistant-reasoning`,`scrub-tool-call-id`,`done-after-tool`,`drop-empty-content`]),Ut=D.object({id:D.string().min(1).max(80),name:D.string().max(80).optional(),description:D.string().optional(),body:D.record(D.string(),D.unknown()).optional(),headers:D.record(D.string(),D.string()).optional()}),Wt=D.object({default:D.string().min(1).max(80).optional(),levels:D.array(Ut).optional()}).passthrough().extend({template:D.string().min(1).max(120).optional()}).refine(e=>e.template||e.levels!==void 0&&e.levels.length>0,`effort requires either template or levels`),Gt=D.object({default:D.string().min(1).max(80).optional(),levels:D.array(Ut).min(1)}).passthrough(),Kt=D.object({field:D.enum([`reasoning`,`reasoning_content`,`reasoning_details`]).optional(),interleaved:D.boolean().optional(),summary:D.literal(`auto`).optional(),include:D.literal(`encrypted`).optional(),effort:Wt.optional()}),qt=D.object({protocol:zt,provider_name:D.string().optional(),upstream_model:D.string().min(1).optional(),reasoning:Kt.optional(),image:D.enum([`url`,`base64`]).optional(),image_max_bytes:D.number().int().positive().optional(),image_max_images:D.number().int().nonnegative().optional(),image_byte_quantum:D.number().int().positive().optional(),image_count_quantum:D.number().int().positive().optional(),cache:D.union([D.literal(`none`),D.literal(`anthropic`),D.literal(`openai-compatible`),D.literal(`bedrock`),Vt]).optional(),limit:D.object({context:D.number().positive(),output:D.number().positive(),idle_timeout_ms:D.number().int().positive().optional()}),body:D.record(D.string(),D.unknown()).optional(),body_templates:D.record(D.string(),D.string()).optional(),headers:D.record(D.string(),D.string()).optional(),when:D.object({reasoning:D.boolean().optional(),reasoning_keys:D.array(D.string()).optional()}).optional(),quirks:D.array(Ht).optional()}).passthrough(),Jt=D.object({apiKey:D.string().optional(),baseURL:D.string().optional(),headers:D.record(D.string(),D.string()).optional()}).passthrough(),Yt=D.object({mode:D.enum([`normal`,`always`]),maxRetries:D.number().int().min(0).optional(),retryableCodes:D.array(D.string()).optional(),backoff:D.object({initialDelayMs:D.number().int().positive().optional(),maxDelayMs:D.number().int().positive().optional(),jitterRatio:D.number().min(0).max(1).optional()}).strict().optional()}).strict(),Xt=qt.extend({protocol:zt.optional()}),Zt=D.object({protocol:zt.optional(),name:D.string().optional(),npm:D.string().optional(),api:D.string().optional(),options:Jt.optional(),retry:Yt.optional(),models:D.record(D.string(),Xt)}).passthrough(),Qt=D.object({match:D.object({provider:D.string().optional(),protocol:D.enum([`openai`,`openai-compatible`,`anthropic`]).optional(),model:D.string().optional()}),traits:qt.partial().omit({protocol:!0,upstream_model:!0}).refine(e=>!(`protocol`in e)&&!(`upstream_model`in e),{message:`trait presets must not set protocol or upstream_model (F6/F7)`})}),$t=D.object({enabled:D.boolean().default(!0),max_file_bytes:D.number().int().nonnegative().default(512*1024*1024),sanitize_headers:D.boolean().default(!0),retention_days:D.number().int().nonnegative().default(14)}).optional(),en=D.object({model:D.string().optional(),provider:D.record(D.string(),Zt).optional(),enabled_providers:D.array(D.string()).optional(),disabled_providers:D.array(D.string()).optional(),effort:D.string().optional(),effort_templates:D.record(D.string(),Gt).optional(),trait_presets:D.array(Qt).optional(),llm_log:$t}).passthrough(),tn=D.object({type:D.literal(`api`).default(`api`),key:D.string().refine(e=>e.trim().length>0,{message:`auth entry key must not be empty`})}),nn=D.record(D.string().min(1),tn),rn=Object.freeze({});function an(e){return{enabled:e?.enabled!==!1&&process.env.TBOXCODE_LLM_LOG!==`0`&&process.env.TBOXCODE_LLM_LOG!==`false`,max_file_bytes:e?.max_file_bytes??512*1024*1024,sanitize_headers:e?.sanitize_headers!==!1,retention_days:e?.retention_days??14}}function on(e){let t=e.indexOf(`/`);if(t===-1)throw new Z(e,`model reference must use provider/model format`);let n=e.slice(0,t),r=e.slice(t+1);if(n.length===0||r.length===0)throw new Z(e,`empty provider or model segment`);return{providerId:n,modelId:r}}function sn(t,n,r=rn){let{providerId:i,modelId:a}=on(t),o=n.provider?.[i];if(o===void 0)throw new Z(t,`provider not found`);if(n.disabled_providers?.includes(i)===!0)throw new Z(t,`provider disabled`);if(n.enabled_providers!==void 0&&n.enabled_providers.length>0&&!n.enabled_providers.includes(i))throw new Z(t,`provider not enabled`);let s=o.models[a];if(s===void 0)throw new ut(t);let c=s.protocol??o.protocol;if(c===void 0)throw new Z(t,`protocol unresolved`);let l={};for(let e of n.trait_presets??[]){let t=e.match.provider===void 0||new RegExp(e.match.provider).test(i),n=e.match.protocol===void 0||c===e.match.protocol,r=e.match.model===void 0||new RegExp(e.match.model).test(a);t&&n&&r&&(l={...l,...e.traits})}let u={...l,...s,protocol:c},d=ht(u.reasoning,n.effort_templates,t);d!==void 0&&(u={...u,reasoning:d});let f=e(s.headers),p={...o.options?.headers,...f},m=u.reasoning?.effort,h={};for(let t of m?.levels??[]){let n=e(t.headers);n!==void 0&&(h[t.id]=n)}let g=mt(m,n.effort,void 0),_={...p,...g===void 0?{}:h[g]},v={apiKey:r[i]?.key??o.options?.apiKey??``,baseURL:o.options?.baseURL??o.api,headers:Object.keys(_).length>0?_:void 0},y=s.provider_name??o.name??i;return{providerId:i,modelId:a,upstream_model:u.upstream_model??a,traits:u,credentials:v,provider_name:y,...Object.keys(p).length>0?{baseHeaders:p}:{},...Object.keys(h).length>0?{effortHeaders:h}:{},...g===void 0?{}:{defaultEffortId:g}}}function cn(e){let t=e.toLowerCase();return/rate[_ ]?limit/.test(t)||t.includes(`速率限制`)||/too[_ ]?many[_ ]?requests/.test(t)||/quota/.test(t)||/exceeded.*requests/.test(t)||/rate.*increased/.test(t)}function ln(e){let t=String(e.code??``),n=String(e.type??``);return t===`1302`||t===`429`||t===`insufficient_quota`||n===`too_many_requests`||n===`insufficient_quota`||/rate[_-]?limit/i.test(t)||/exhausted/i.test(t)?!0:cn(String(e.message??``))}function un(e){if(typeof e!=`object`||!e)return;let t=e;if(typeof t.retry_after==`number`&&t.retry_after>0)return Math.ceil(t.retry_after);if(typeof t.retry_after_secs==`number`&&t.retry_after_secs>0)return Math.ceil(t.retry_after_secs)}function dn(e){return async(t,n)=>{let r=await e(t,n);if(r.status!==200||r.body===null||!(r.headers.get(`content-type`)??``).includes(`text/event-stream`))return r;let i=r.body.getReader(),a=new TextDecoder,o=[],s=``;try{for(;;){let{done:e,value:t}=await i.read();if(e)break;o.push(t),s+=a.decode(t,{stream:!0});let n=s.indexOf(`
|
|
113
|
+
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=c(s(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=c(s(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;case`space`:case`comment`:default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),it=A((e=>{var t=Xe(),n=Pe(),r=Fe(),i=de(),a=M(),o=nt(),s=rt();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f}));A((e=>{var t=Xe(),n=Pe(),r=Me(),i=Fe(),a=z(),o=M(),s=H(),c=B(),l=U(),u=G();et();var d=tt(),f=nt(),p=rt(),m=it(),h=N();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync}))();function at(){return process.env.TBOXCODE_DSH_CONFIG_DIR??l(ee(),`.config`,`tboxcode-dsh`)}function ot(e=at()){for(let t of[`config.jsonc`,`config.json`]){let n=l(e,t);if(S(n))return n}return null}function st(e){let t=``,n=0,r=e.length,i=!1;for(;n<r;){let a=e[n];if(i){if(t+=a,a===`\\`){n+1<r&&(t+=e[n+1]),n+=2;continue}a===`"`&&(i=!1),n++;continue}if(a===`"`){i=!0,t+=a,n++;continue}if(a===`/`&&e[n+1]===`/`){for(;n<r&&e[n]!==`
|
|
114
|
+
`;)n++;continue}if(a===`/`&&e[n+1]===`*`){for(n+=2;n<r&&!(e[n]===`*`&&e[n+1]===`/`);)n++;n+=2;continue}t+=a,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function ct(e,t=new WeakSet){if(typeof e==`string`)return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>{let n=process.env[t];return n===void 0?e:n});if(Array.isArray(e))return e.map(e=>ct(e,t));if(typeof e==`object`&&e){let n=e;if(t.has(n))return e;t.add(n);let r={};for(let[e,i]of Object.entries(n))r[e]=ct(i,t);return t.delete(n),r}return e}function lt(e=at()){let t=ot(e);if(t===null)return{path:null,config:{}};let n=C(t,`utf-8`);try{let e=JSON.parse(st(n));if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`config 顶层必须是对象`);return{path:t,config:ct(e)}}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`config 解析失败(${t}):${n}`)}}function ut(e,t,n,r=500){let i=new Set(t),a,o=!1,s=()=>{a!==void 0&&clearTimeout(a),a=setTimeout(()=>{o||n()},r)},c=()=>{let t=[];for(let n of i)try{let r=w(l(e,n));t.push(`${n}:${r.mtimeMs}:${r.size}:${r.ino}`)}catch{t.push(`${n}:-`)}return t.join(`|`)},u=c(),d=setInterval(()=>{if(o)return;let e=c();e!==u&&(u=e,s())},1e3);d.unref?.();let f;try{f=T(e,{persistent:!1},(e,t)=>{t!==null&&!i.has(t)||s()})}catch{return clearInterval(d),{dispose:()=>{o=!0,clearInterval(d)}}}return f.on(`error`,()=>{}),{dispose:()=>{o=!0,clearInterval(d),a!==void 0&&clearTimeout(a),f.close()}}}function dt(e,t){return t.image===void 0?e.map(e=>{if(!Array.isArray(e.content))return e;let t=[];for(let n of e.content){let e=n;if(e.type!==`image`){t.push(n);continue}let r=e.mimeType??(typeof e.image==`object`&&e.image?e.image.mediaType:void 0),i=r===void 0?`[image]`:`[image: ${r}]`,a=t.length-1,o=t[a];o?.type===`text`?t[a]={...o,text:o.text+i}:t.push({type:`text`,text:i})}return{...e,content:t}}):e}var ft=class extends Error{constructor(e){super(`Model not configured: ${e}`),this.modelId=e,this.name=`ModelNotConfiguredError`}},Y=class extends Error{constructor(e,t){super(`Provider not configured: ${e}${t?` (${t})`:``}`),this.ref=e,this.detail=t,this.name=`ProviderNotConfiguredError`}},pt=class extends Error{constructor(e){super(`Effort template not found: "${e}"`),this.templateName=e,this.name=`EffortTemplateNotFoundError`}},mt=class extends Error{constructor(e,t){super(`Effort default "${t}" not in resolved levels (model ${e})`),this.ref=e,this.defaultId=t,this.name=`EffortDefaultNotInLevelsError`}};function ht(e,t){let n=new Map(e.map(e=>[e.id,e]));for(let e of t){let t=n.get(e.id);n.set(e.id,t===void 0?e:{...t,...e})}return[...n.values()]}function gt(e,t,n){let r=e?.levels;if(!(r===void 0||r.length===0))return n!==void 0&&r.some(e=>e.id===n)?n:t!==void 0&&r.some(e=>e.id===t)?t:e?.default??r[0]?.id}function _t(e,t,n){if(!e)return;if(!e.effort)return e;let r=e.effort,i;if(r.template!==void 0){let n=t?.[r.template];if(n===void 0)throw new pt(r.template);let a=ht(n.levels,r.levels??[]);if(a.length===0)return{...e,effort:void 0};i={...n,default:r.default??n.default??a[0].id,levels:a}}else if(r.levels!==void 0&&r.levels.length>0)i={...r,default:r.default??r.levels[0].id,levels:r.levels};else return{...e,effort:void 0};let a=i.default;if(!i.levels.some(e=>e.id===a))throw new mt(n??`(unknown)`,a);return{...e,effort:i}}const vt=e=>Array.isArray(e);function yt(e){return e.map(e=>{if(e.role!==`assistant`)return e;if(vt(e.content))return e.content.some(e=>e.type===`reasoning`)?e:{...e,content:[...e.content,{type:`reasoning`,text:``}]};let t=typeof e.content==`string`?e.content:``;return{...e,content:[...t?[{type:`text`,text:t}]:[],{type:`reasoning`,text:``}]}})}function bt(e){let t=e=>e.replace(/[^a-zA-Z0-9_-]/g,`_`);return e.map(e=>vt(e.content)?{...e,content:e.content.map(e=>{let n=e;return(n.type===`tool-call`||n.type===`tool-result`)&&n.toolCallId!==void 0?{...n,toolCallId:t(n.toolCallId)}:n})}:e)}function xt(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&t.push(r);let i=e[n+1];r?.role===`tool`&&i?.role===`user`&&t.push({role:`assistant`,content:[{type:`text`,text:`Done.`}]})}return t}function St(e){return e.filter(e=>!(vt(e.content)&&e.content.length===0))}const Ct={"ensure-assistant-reasoning":yt,"scrub-tool-call-id":bt,"done-after-tool":xt,"drop-empty-content":St};function wt(e,t=[]){return t.reduce((e,t)=>Ct[t](e),e)}function Tt(e){switch(e){case`openai`:return`openai`;case`anthropic`:return`anthropic`;case`openai-compatible`:return`openaiCompatible`}}function Et(e){return e===void 0||e===`none`?`none`:typeof e==`string`?{mode:`automatic`,ttl:`5m`}:{...e}}function Dt(e){let t=Ot(e);return a(`sha256`).update(t).digest(`hex`).slice(0,16)}function Ot(e){return JSON.stringify(kt(e))}function kt(e){if(Array.isArray(e))return e.map(kt);if(typeof e==`object`&&e){let t=e;return Object.fromEntries(Object.keys(t).sort().map(e=>[e,kt(t[e])]))}return e}function At(e,t){return e===`openai-compatible`?t:Tt(e)}const jt=/\$\{(\w+(?:\.\w+)?)\}/g;function Mt(e,t,n){let r=e.replace(jt,(e,r)=>{switch(r){case`sessionId`:return t.sessionId;case`effort`:return n??t.effort??``;case`model.output`:return String(t.model.output);case`model.context`:return String(t.model.context);default:return``}});return r=Nt(r),r}function Nt(e){let t=e;return t=t.replace(/min\(([^)]+)\)/g,(e,t)=>{let n=t.split(`,`).map(e=>Number.parseFloat(e.trim()));return String(Math.min(...n))}),t=t.replace(/max\(([^)]+)\)/g,(e,t)=>{let n=t.split(`,`).map(e=>Number.parseFloat(e.trim()));return String(Math.max(...n))}),t=t.replace(/floor\(([^)]+)\)/g,(e,t)=>String(Math.floor(Number.parseFloat(t.trim())))),t}function Pt(e,t,n,r,i,a){let o=Tt(t.protocol),s=t.protocol===`anthropic`?`anthropic`:o,c=gt(t.reasoning?.effort,void 0,n.effort),l=wt(e,t.quirks);l=dt(l,t);let u=t.reasoning;if(u?.interleaved===!0&&u.field!==void 0){let e=u.field;l=l.map(t=>{if(t.role!==`assistant`||!Array.isArray(t.content))return t;let n=t.content.filter(e=>e.type===`reasoning`).map(e=>e.text??``).join(``),r=t.content.filter(e=>e.type!==`reasoning`),i=t.providerOptions,a=i?.[o]??{};return{...t,content:r,providerOptions:{...i,[o]:{...a,[e]:n}}}})}let d=Et(t.cache),f=r,p=null,m=null;if(d!==`none`){let e=d.ttl,n=d.mode===`explicit`?d.scope??[`system`,`tools`]:[`system`,`messages`],i={type:`ephemeral`,ttl:e},o=n.includes(`system`);if(o&&(f={role:`system`,content:r,providerOptions:{[s]:{cacheControl:i}}}),n.includes(`tools`)&&(p=i,m=s),n.includes(`messages`)&&(a?.messageBreakpoints??!0)){let e=t.protocol===`anthropic`?Math.max(0,4-(o?1:0)-(p===null?0:1)):1;if(e>0){let n=l.slice(-e);for(let e of n)Ft(e,i,s,t.protocol)}}}let h={...t.body??{}};for(let[e,r]of Object.entries(t.body_templates??{}))h[e]=Mt(r,n,c);let g=t.reasoning?.effort?.levels;if(c!==void 0&&g!==void 0){let e=g.find(e=>e.id===c);e?.body!==void 0&&Object.assign(h,e.body)}let _=h;if(t.when?.reasoning===!0&&!n.reasoningEnabled){let e=t.when?.reasoning_keys??[`enable_thinking`,`thinking`];_=Object.fromEntries(Object.entries(h).filter(([t])=>!e.includes(t)))}let v=At(t.protocol,i),y={};if(Object.keys(_).length>0){let e={..._};t.protocol===`openai-compatible`&&typeof e.reasoning_effort==`string`&&e.reasoningEffort===void 0&&(e.reasoningEffort=e.reasoning_effort),y[v]=e}return{messages:l,system:f,providerOptions:y,extraBody:_,toolsCacheControl:p,toolsCacheControlKey:m}}function Ft(e,t,n,r){if(r!==`anthropic`&&Array.isArray(e.content)&&e.content.length>0){let r=e.content[e.content.length-1],i=r.providerOptions?.[n]??{};r.providerOptions={...r.providerOptions,[n]:{...i,cacheControl:t}}}else{let r=e,i=r.providerOptions?.[n]??{};r.providerOptions={...r.providerOptions,[n]:{...i,cacheControl:t}}}}function It(e){return ie({apiKey:e.apiKey,baseURL:e.baseURL,headers:e.headers,fetch:e.fetch})(e.upstream_model)}function Lt(){return{extractMetadata:async({parsedBody:e})=>{let t=e?.usage;return t===void 0?void 0:{usage:t}},createStreamExtractor:()=>{let e;return{processChunk(t){let n=t?.usage;n!==void 0&&(e=n)},buildMetadata(){return e===void 0?void 0:{usage:e}}}}}}function Rt(e){return O({name:e.provider_name,apiKey:e.apiKey,baseURL:e.baseURL??`http://offline.invalid/v1`,headers:e.headers,fetch:e.fetch,includeUsage:!0,metadataExtractor:Lt(),supportedUrls:()=>({"image/*":[/^https?:\/\//]})}).chatModel(e.upstream_model)}function zt(e){return k({apiKey:e.apiKey,baseURL:e.baseURL,headers:e.headers,fetch:e.fetch})(e.upstream_model)}function Bt(e,t){let{provider_name:n,upstream_model:r,traits:i,credentials:a}=e,o=t?.drain,s=t?.headers===void 0&&a.headers===void 0?void 0:{...a.headers??{},...t?.headers??{}},c;switch(i.protocol){case`openai`:c=zt({upstream_model:r,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break;case`openai-compatible`:c=Rt({upstream_model:r,provider_name:n,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break;case`anthropic`:c=It({upstream_model:r,apiKey:a.apiKey,baseURL:a.baseURL,headers:s,fetch:t?.fetch});break}return{streamText(e){return ne({model:c,system:e.system,messages:e.messages,providerOptions:e.providerOptions,tools:e.tools,toolChoice:e.toolChoice,abortSignal:e.signal,maxRetries:e.maxRetries??0,...e.params})},dispose(){return o?.()}}}const Vt=D.enum([`openai`,`openai-compatible`,`anthropic`]),Ht=D.enum([`5m`,`1h`]),Ut=D.object({mode:D.enum([`automatic`,`explicit`]),ttl:Ht,scope:D.array(D.enum([`system`,`tools`,`messages`])).optional()}),Wt=D.enum([`ensure-assistant-reasoning`,`scrub-tool-call-id`,`done-after-tool`,`drop-empty-content`]),Gt=D.object({id:D.string().min(1).max(80),name:D.string().max(80).optional(),description:D.string().optional(),body:D.record(D.string(),D.unknown()).optional(),headers:D.record(D.string(),D.string()).optional()}),Kt=D.object({default:D.string().min(1).max(80).optional(),levels:D.array(Gt).optional()}).passthrough().extend({template:D.string().min(1).max(120).optional()}).refine(e=>e.template||e.levels!==void 0&&e.levels.length>0,`effort requires either template or levels`),qt=D.object({default:D.string().min(1).max(80).optional(),levels:D.array(Gt).min(1)}).passthrough(),Jt=D.object({field:D.enum([`reasoning`,`reasoning_content`,`reasoning_details`]).optional(),interleaved:D.boolean().optional(),summary:D.literal(`auto`).optional(),include:D.literal(`encrypted`).optional(),effort:Kt.optional()}),Yt=D.object({protocol:Vt,provider_name:D.string().optional(),upstream_model:D.string().min(1).optional(),reasoning:Jt.optional(),image:D.enum([`url`,`base64`]).optional(),image_max_bytes:D.number().int().positive().optional(),image_max_images:D.number().int().nonnegative().optional(),image_byte_quantum:D.number().int().positive().optional(),image_count_quantum:D.number().int().positive().optional(),request_max_bytes:D.number().int().positive().optional(),image_max_pixels:D.number().int().positive().optional(),image_max_aspect_ratio:D.number().positive().optional(),cache:D.union([D.literal(`none`),D.literal(`anthropic`),D.literal(`openai-compatible`),D.literal(`bedrock`),Ut]).optional(),limit:D.object({context:D.number().positive(),output:D.number().positive(),idle_timeout_ms:D.number().int().positive().optional()}),body:D.record(D.string(),D.unknown()).optional(),body_templates:D.record(D.string(),D.string()).optional(),headers:D.record(D.string(),D.string()).optional(),when:D.object({reasoning:D.boolean().optional(),reasoning_keys:D.array(D.string()).optional()}).optional(),quirks:D.array(Wt).optional()}).passthrough(),Xt=D.object({apiKey:D.string().optional(),baseURL:D.string().optional(),headers:D.record(D.string(),D.string()).optional()}).passthrough(),Zt=D.object({mode:D.enum([`normal`,`always`]),maxRetries:D.number().int().min(0).optional(),retryableCodes:D.array(D.string()).optional(),backoff:D.object({initialDelayMs:D.number().int().positive().optional(),maxDelayMs:D.number().int().positive().optional(),jitterRatio:D.number().min(0).max(1).optional()}).strict().optional()}).strict(),Qt=Yt.extend({protocol:Vt.optional()}),$t=D.object({type:D.literal(`sofa`)}).strict(),en=D.object({protocol:Vt.optional(),name:D.string().optional(),npm:D.string().optional(),api:D.string().optional(),options:Xt.optional(),retry:Zt.optional(),trace:$t.optional(),models:D.record(D.string(),Qt)}).passthrough(),tn=D.object({match:D.object({provider:D.string().optional(),protocol:D.enum([`openai`,`openai-compatible`,`anthropic`]).optional(),model:D.string().optional()}),traits:Yt.partial().omit({protocol:!0,upstream_model:!0}).refine(e=>!(`protocol`in e)&&!(`upstream_model`in e),{message:`trait presets must not set protocol or upstream_model (F6/F7)`})}),nn=D.object({enabled:D.boolean().default(!0),max_file_bytes:D.number().int().nonnegative().default(512*1024*1024),sanitize_headers:D.boolean().default(!0),retention_days:D.number().int().nonnegative().default(14)}).optional(),rn=`tbox/deepseek-v4.1-flash-1017`,X=`auto`,an=D.object({init_model:D.string().min(1).optional()}).passthrough(),on=D.object({mode:D.enum([`project`,`offload`]).optional(),image_reserve_bytes:D.number().int().nonnegative().optional()}).passthrough(),sn=D.object({model:D.string().optional(),workspace:an.optional(),media_policy:on.optional(),provider:D.record(D.string(),en).optional(),enabled_providers:D.array(D.string()).optional(),disabled_providers:D.array(D.string()).optional(),effort:D.string().optional(),effort_templates:D.record(D.string(),qt).optional(),trait_presets:D.array(tn).optional(),llm_log:nn}).passthrough(),cn=D.object({type:D.literal(`api`).default(`api`),key:D.string().refine(e=>e.trim().length>0,{message:`auth entry key must not be empty`})}),ln=D.record(D.string().min(1),cn),un=Object.freeze({});function dn(e){return{enabled:e?.enabled!==!1&&process.env.TBOXCODE_LLM_LOG!==`0`&&process.env.TBOXCODE_LLM_LOG!==`false`,max_file_bytes:e?.max_file_bytes??512*1024*1024,sanitize_headers:e?.sanitize_headers!==!1,retention_days:e?.retention_days??14}}function Z(e){let t=e.indexOf(`/`);if(t===-1)throw new Y(e,`model reference must use provider/model format`);let n=e.slice(0,t),r=e.slice(t+1);if(n.length===0||r.length===0)throw new Y(e,`empty provider or model segment`);return{providerId:n,modelId:r}}function fn(t,n,r=un){let{providerId:i,modelId:a}=Z(t),o=n.provider?.[i];if(o===void 0)throw new Y(t,`provider not found`);if(n.disabled_providers?.includes(i)===!0)throw new Y(t,`provider disabled`);if(n.enabled_providers!==void 0&&n.enabled_providers.length>0&&!n.enabled_providers.includes(i))throw new Y(t,`provider not enabled`);let s=o.models[a];if(s===void 0)throw new ft(t);let c=s.protocol??o.protocol;if(c===void 0)throw new Y(t,`protocol unresolved`);let l={};for(let e of n.trait_presets??[]){let t=e.match.provider===void 0||new RegExp(e.match.provider).test(i),n=e.match.protocol===void 0||c===e.match.protocol,r=e.match.model===void 0||new RegExp(e.match.model).test(a);t&&n&&r&&(l={...l,...e.traits})}let u={...l,...s,protocol:c},d=_t(u.reasoning,n.effort_templates,t);d!==void 0&&(u={...u,reasoning:d});let f=e(s.headers),p={...o.options?.headers,...f},m=u.reasoning?.effort,h={};for(let t of m?.levels??[]){let n=e(t.headers);n!==void 0&&(h[t.id]=n)}let g=gt(m,n.effort,void 0),_={...p,...g===void 0?{}:h[g]},v={apiKey:r[i]?.key??o.options?.apiKey??``,baseURL:o.options?.baseURL??o.api,headers:Object.keys(_).length>0?_:void 0},y=s.provider_name??o.name??i;return{providerId:i,modelId:a,upstream_model:u.upstream_model??a,traits:u,credentials:v,provider_name:y,...Object.keys(p).length>0?{baseHeaders:p}:{},...Object.keys(h).length>0?{effortHeaders:h}:{},...g===void 0?{}:{defaultEffortId:g}}}function pn(e){let t=e.toLowerCase();return/rate[_ ]?limit/.test(t)||t.includes(`速率限制`)||/too[_ ]?many[_ ]?requests/.test(t)||/quota/.test(t)||/exceeded.*requests/.test(t)||/rate.*increased/.test(t)}function mn(e){let t=String(e.code??``),n=String(e.type??``);return t===`1302`||t===`429`||t===`insufficient_quota`||n===`too_many_requests`||n===`insufficient_quota`||/rate[_-]?limit/i.test(t)||/exhausted/i.test(t)?!0:pn(String(e.message??``))}function hn(e){if(typeof e!=`object`||!e)return;let t=e;if(typeof t.retry_after==`number`&&t.retry_after>0)return Math.ceil(t.retry_after);if(typeof t.retry_after_secs==`number`&&t.retry_after_secs>0)return Math.ceil(t.retry_after_secs)}function gn(e){return async(t,n)=>{let r=await e(t,n);if(r.status!==200||r.body===null||!(r.headers.get(`content-type`)??``).includes(`text/event-stream`))return r;let i=r.body.getReader(),a=new TextDecoder,o=[],s=``;try{for(;;){let{done:e,value:t}=await i.read();if(e)break;o.push(t),s+=a.decode(t,{stream:!0});let n=s.indexOf(`
|
|
115
115
|
|
|
116
|
-
`);if(n===-1)continue;let c=
|
|
117
|
-
`)){let e=t.trim();if(e.startsWith(`data:`))try{let t=JSON.parse(e.slice(5).trim());return t.error!==void 0&&typeof t.error==`object`?t.error:t}catch{}}return null}function
|
|
116
|
+
`);if(n===-1)continue;let c=vn(s.slice(0,n));return c!==null&&mn(c)?(i.cancel(),yn(c)):_n(r,o,i)}}catch{return _n(r,o,i)}return _n(r,o,i)}}function _n(e,t,n){let r=!1;return new Response(new ReadableStream({start(e){for(let n of t){if(r)return;try{e.enqueue(n)}catch{return}}(async()=>{try{for(;!r;){let{done:t,value:r}=await n.read();if(t)break;try{e.enqueue(r)}catch{break}}}catch{}try{e.close()}catch{}})()},cancel(){r=!0,n.cancel().catch(()=>{})}}),{status:e.status,statusText:e.statusText,headers:e.headers})}function vn(e){for(let t of e.split(`
|
|
117
|
+
`)){let e=t.trim();if(e.startsWith(`data:`))try{let t=JSON.parse(e.slice(5).trim());return t.error!==void 0&&typeof t.error==`object`?t.error:t}catch{}}return null}function yn(e){let t=hn(e)??5,n=typeof e?.message==`string`?e.message:`Rate limit exceeded`;return new Response(JSON.stringify({error:{message:n,type:`rate_limit_error`,code:`rate_limit_exceeded`}}),{status:429,headers:{"content-type":`application/json`,"retry-after":String(t)}})}function bn(e){for(let t of[`providerMetadata`,`providerOptions`]){let n=e[t];if(typeof n!=`object`||!n)continue;let r=n.anthropic;if(typeof r==`object`&&r)return r}}function xn(e){let t=bn(e);if(t===void 0)return;let n=typeof t.signature==`string`&&t.signature.length>0?t.signature:void 0,r=typeof t.redactedData==`string`&&t.redactedData.length>0?t.redactedData:void 0;if(!(n===void 0&&r===void 0))return{...n===void 0?{}:{signature:n},...r===void 0?{}:{redactedData:r}}}function Sn(e){let t=e.source?.replayState;if(typeof t!=`object`||!t)return;let n=t.blocks;return Array.isArray(n)?n:void 0}function Cn(e){return e.map(e=>e.text??``).filter(e=>e.length>0).join(``)}function Q(e){let t=e.attachment,n=e.type===`image`?`image`:`file`,r=t?.mediaType??`unknown`;return`[${n}${t?.name===void 0?``:` ${t.name}`}: ${r}]`}function wn(e,t,n,r){let i=e.map(e=>{let n=e;if(n.type===`text`)return n.text??``;if(n.type===`image`&&n.attachment!==void 0){let e=t?.images?.get(n.attachment.attachmentId);if(e!==void 0&&r!==`anthropic`)return`\n${v(n.attachment,e,t?.resolveImageAccess?.(n.attachment))} This provider cannot transmit images in tool results.`}return Q(e)}).join(``);if(n)return{type:`error-text`,value:i};if(r!==`anthropic`)return{type:`text`,value:i};let a=[],o=!1;for(let n of e){let e=n;if(e.type===`text`){(e.text??``).length>0&&a.push({type:`text`,text:e.text});continue}if(e.type!==`image`||e.attachment===void 0)continue;let r=t?.images?.get(e.attachment.attachmentId);if(r===void 0){a.push({type:`text`,text:Q(n)});continue}o=!0,a.push({type:`image-data`,data:Buffer.from(r.data).toString(`base64`),mediaType:r.mediaType})}return o?{type:`content`,value:a}:{type:`text`,value:i}}function Tn(e,t,n){let r=t!==void 0&&t.length>0?[t]:[],i=r.length>0,a=[],o=new Map;for(let t of e){let e=t.content,s=Array.isArray(e)?e:[];switch(t.role){case`system`:{if(i)continue;let e=Cn(s);e.length>0&&r.push(e);continue}case`developer`:continue;case`user`:{let e=[];for(let t of s){let r=t;if(r.type===`text`){e.push({type:`text`,text:r.text??``});continue}if(r.type!==`reasoning`){if(r.type===`image`){let r=t,i=n?.images?.get(r.attachment.attachmentId);i===void 0?e.push({type:`text`,text:Q(t)}):(e.push({type:`text`,text:v(r.attachment,i,n?.resolveImageAccess?.(r.attachment))}),e.push({type:`image`,image:i.data,mediaType:i.mediaType}));continue}if(r.type===`file`){e.push({type:`text`,text:Q(t)});continue}}}a.push({role:`user`,content:e});continue}case`assistant`:{let e=[],r=n?.protocol===`anthropic`?Sn(t):void 0,i=r!==void 0&&r.length===s.length?r:void 0;for(let[t,r]of s.entries()){let a=r;if(a.type===`text`){(a.text??``).length>0&&e.push({type:`text`,text:a.text});continue}if(a.type===`reasoning`){let r=i?.[t]?.anthropic;if(n?.protocol===`anthropic`){r?.signature===void 0?r?.redactedData!==void 0&&e.push({type:`reasoning`,text:a.text??``,providerOptions:{anthropic:{redactedData:r.redactedData}}}):e.push({type:`reasoning`,text:a.text??``,providerOptions:{anthropic:{signature:r.signature}}});continue}(a.text??``).length>0&&e.push({type:`reasoning`,text:a.text});continue}if(a.type===`tool-call`){let t=a.id??``,n=a.name??``;t.length>0&&n.length>0&&o.set(t,n),e.push({type:`tool-call`,toolCallId:t,toolName:n,input:En(a.arguments??`{}`)});continue}(a.type===`image`||a.type===`file`)&&e.push({type:`text`,text:Q(r)})}a.push({role:`assistant`,content:e});continue}case`tool`:{let e=t;a.push({role:`tool`,content:[{type:`tool-result`,toolCallId:e.toolCallId,toolName:o.get(e.toolCallId)??`unknown`,output:wn(e.content,n,e.isError===!0,n?.protocol)}]});continue}default:continue}}return{system:r.join(`
|
|
118
118
|
|
|
119
|
-
`),messages:a}}function xn(e){try{return JSON.parse(e)}catch{return{}}}function Sn(e){if(e===void 0||e.length===0)return;let t={};for(let n of e)t[n.name]=j({description:n.description,inputSchema:k(n.parameters)});return t}function Cn(e){let t=new Map;for(let n of e)if(h(n.content)){if(n.role!==`user`&&n.role!==`tool`)throw new f(`cannot represent an image in an in-history ${n.role} message`,`UNSUPPORTED_CONTENT`);for(let e of n.content)e.type!==`image`||e.offloaded===!0||t.set(e.attachment.attachmentId,e.attachment)}return t}async function wn(e,t,n){let r=_(e,e=>g(e,n.resolveAccess(e))),i=Cn(r);if(i.size===0)return{messages:r,versions:new Map};if(t===void 0)throw new f(`image input requires the mounted attachment service`,`UNSUPPORTED_CONTENT`);let a=new Map;for(let e of i.values())a.set(e.attachmentId,await t.readImageRequest(e,n.targetOf(e),n.signal));if(n.budget!==void 0){let e=y(r,n.budget,e=>{let t=a.get(e.attachment.attachmentId);if(t===void 0)throw new f(`missing prepared request image version`,`UNSUPPORTED_CONTENT`);return t.bytes});if(e>0)throw new f(`image request exceeds route budget; ${e} more oldest occurrence(s) must be offloaded`,u,{offloadImages:e})}return{messages:r,versions:a}}function Tn(e,t){if(e===void 0)return;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n&&r.length>0)return r}function En(e,t){let n=e.requestId;if(typeof n==`string`&&n.length>0)return n;let r=e.data;if(typeof r==`object`&&r){let e=r,t=e.request_id??e.requestId;if(typeof t==`string`&&t.length>0)return t}for(let e of[`x-request-id`,`request-id`,`x-correlation-id`,`openai-request-id`,`x-amzn-requestid`,`cf-ray`,`x-goog-request-id`]){let n=Tn(t,e);if(n!==void 0)return n}}function Dn(e){if(e===void 0)return;let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;let n=Number(t[`retry-after-ms`]);if(Number.isFinite(n)&&n>0)return Math.ceil(n);let r=t[`retry-after`];if(r===void 0)return;let i=Number(r);if(Number.isFinite(i)&&i>0)return Math.ceil(i*1e3);let a=Date.parse(r);if(Number.isFinite(a))return Math.max(0,a-Date.now())||void 0}function On(e){if(e instanceof Error){let t=e.lastError??e,n=t.statusCode,r=t.responseHeaders,i=r instanceof Headers?Object.fromEntries(r.entries()):typeof r==`object`&&r?Object.fromEntries(Object.entries(r).filter(e=>typeof e[1]==`string`)):void 0;return{name:e.name,msg:e.message.toLowerCase(),statusCode:typeof n==`number`?n:void 0,responseHeaders:i,retryAfterMs:Dn(i),requestId:En(t,i)}}return{name:``,msg:String(e).toLowerCase(),statusCode:void 0,responseHeaders:void 0,retryAfterMs:void 0,requestId:void 0}}function kn(e){return e.name===`TypeError`&&e.msg.includes(`terminated`)||e.msg.includes(`econnreset`)||e.msg.includes(`econnrefused`)||e.msg.includes(`socket hang up`)||e.msg.includes(`fetch failed`)||e.msg.includes(`network error`)||e.msg.includes(`other side closed`)||e.msg.includes(`cannot connect to api`)}function An(e){return e.statusCode===401||e.statusCode===403||e.msg.includes(`unauthorized`)||e.msg.includes(`forbidden`)||e.msg.includes(`invalid api key`)}function jn(e){return e.statusCode===429||e.msg.includes(`rate limit`)||e.msg.includes(`rate_limit`)||e.msg.includes(`too many requests`)||cn(e.msg)}function Mn(e){return e.statusCode!==void 0&&e.statusCode>=500||e.msg.includes(`server error`)||e.msg.includes(`internal server`)}function Nn(e){return e.statusCode===400&&(e.msg.includes(`context length`)||e.msg.includes(`context_window`)||e.msg.includes(`maximum context`))}function Pn(e){return e.name===`AI_NoOutputGeneratedError`||e.msg.includes(`no output generated`)}function Fn(e){return e.msg.includes(`content_filter`)||e.msg.includes(`content policy`)||e.msg.includes(`content filter`)||e.msg.includes(`safety filter`)}function In(e){return e.statusCode===408||e.msg.includes(`timeout`)||e.msg.includes(`timed out`)}function Ln(e){return e.statusCode===400||e.statusCode===404||e.statusCode===413||e.statusCode===422||e.msg.includes(`invalid request`)||e.msg.includes(`bad request`)}const Rn=[{match:kn,code:`TRANSPORT`,message:`与 LLM 服务的连接中断(网络异常)`},{match:An,code:`AUTH`,message:`模型服务鉴权失败,请检查 API Key 配置`},{match:jn,code:`RATE_LIMIT`,message:`触发限流,请稍后重试`},{match:Nn,code:`CONTEXT_WINDOW_EXCEEDED`,message:`上下文长度超限`},{match:Mn,code:`SERVER`,message:`模型服务异常`},{match:Pn,code:`EMPTY_RESPONSE`,message:`模型未产生输出`},{match:Fn,code:`INVALID_REQUEST`,message:`内容被安全策略拦截`},{match:In,code:`TIMEOUT`,message:`模型服务请求超时`},{match:Ln,code:`INVALID_REQUEST`,message:`模型请求无效`}];function zn(e){return e instanceof DOMException&&e.name===`AbortError`||e instanceof Error&&e.name===`AbortError`}function Bn(e){if(e instanceof f)return e;if(zn(e))return new f(`请求已取消`,`ABORTED`,{cause:e});let t=On(e),n=t.statusCode!==void 0&&Number.isInteger(t.statusCode)&&t.statusCode>=100&&t.statusCode<=599?t.statusCode:void 0,r={cause:e instanceof Error?e:void 0,...n===void 0?{}:{status:n},...t.retryAfterMs===void 0?{}:{providerRetryAfterMs:t.retryAfterMs},...t.requestId===void 0?{}:{requestId:p(t.requestId)}};for(let e of Rn)if(e.match(t))return new f(e.message,e.code,r);return new f(`LLM 调用失败`,`TRANSPORT`,r)}const Vn=e=>e;function $(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.trunc(t)):0}function Hn(e,t){let n=t?.name;return typeof n==`string`&&n.trim().length>0?n.trim():e}function Un(e){return e?.image===void 0?[`text`]:[`text`,`image`]}function Wn(e){let t=e;if(!(t===void 0||t.image_max_bytes===void 0&&t.image_max_images===void 0&&t.image_byte_quantum===void 0&&t.image_count_quantum===void 0))return{representation:`base64`,...t.image_max_bytes===void 0?{}:{maxBytes:t.image_max_bytes},...t.image_max_images===void 0?{}:{maxImages:t.image_max_images},...t.image_byte_quantum===void 0?{}:{byteQuantum:t.image_byte_quantum},...t.image_count_quantum===void 0?{}:{countQuantum:t.image_count_quantum}}}var Gn=class extends d{#e;#t;#n;#r;#i;#a;constructor(e){super(),this.#e=e.config,this.#t=e.auth,this.#n=e.llmLog,this.#r=e.callLogPaths,this.#i=e.resolveAttachments,this.#a=e.resolveImageAccess}refresh(e,t,n){this.#e=e,this.#t=t,this.#n=n}get llmLog(){return this.#n}providerInfo(e){let t=this.#e.provider?.[e]?.name,n=typeof t==`string`?t.trim():``;return{id:e,name:n.length>0?n:e}}listModels(e){if(!this.#s(e))return Promise.resolve([]);let t=this.#e.provider?.[e];if(t===void 0)return Promise.resolve([]);let n=[],r=new Set;for(let[i,a]of Object.entries(t.models)){if(i.length===0||r.has(i)){console.warn(`[tboxcode-llm] 跳过非法/重复模型条目: provider=${e} id="${i}"`);continue}r.add(i);let t=Hn(i,a);t.length!==0&&n.push({provider:e,id:i,name:t,inputModalities:Un(a)})}return Promise.resolve(n)}async resolveModel(e,t){return this.#o(this.#c(`${e}/${t}`))}#o(e){let t=e.traits.reasoning?.effort,n=this.#e.effort,r=t?.levels!==void 0&&typeof n==`string`&&n.length>0&&t.levels.some(e=>e.id===n)?n:t?.default;return{provider:e.providerId,id:e.modelId,name:Hn(e.modelId,e.traits),inputModalities:Un(e.traits),context:{contextWindow:e.traits.limit.context},defaultMaxTokens:e.traits.limit.output,...t?.levels!==void 0&&t.levels.length>0?{reasoning:{efforts:t.levels.map(e=>({id:Vn(e.id),name:e.name??e.id})),...r===void 0?{}:{defaultEffort:Vn(r)}}}:{}}}#s(e){if(this.#e.disabled_providers?.includes(e)===!0)return!1;let t=this.#e.enabled_providers;return t===void 0||t.length===0||t.includes(e)}providerRetryPolicy(e){let t=this.#e.provider?.[e]?.retry;return x(t??{mode:`normal`,maxRetries:2},`tboxcode-llm provider "${e}" retryPolicy`)}async*stream(e){yield*(await this.prepareCall(e.provider,e.model,e.signal)).stream(e)}async prepareCall(e,t,n){let r=this.#c(`${e}/${t}`);return{model:this.#o(r),stream:e=>this.#u(r,e)}}#c(e){try{return sn(e,this.#e,this.#t)}catch(e){throw e instanceof ut?new f(e.message,`UNKNOWN_MODEL`,{cause:e}):e instanceof Z||e instanceof dt||e instanceof ft?new f(e.message,`INVALID_CONFIG`,{cause:e}):e}}async#l(e,i){if(!this.#n.enabled||this.#r===void 0)return;let{root:a,cwdOf:s}=this.#r,c=i.sessionId===void 0?void 0:String(i.sessionId),l=`llmc_${o(8).toString(`hex`)}`,u;if(c!==void 0)try{let e=await s(c);u=e===void 0?r(a):t(a,e,c)}catch{u=r(a)}else u=r(a);let d=i.purpose,f=d===`compaction`?`compact`:d===`session-title`?`title`:`main`,p=n({enabled:!0,max_file_bytes:this.#n.max_file_bytes,sanitize_headers:this.#n.sanitize_headers,logDir:u,sessionId:c??`agentless`,trigger:f,callId:l,traitsVersion:qn(e.traits),provider_name:e.provider_name,modelId:i.model,upstream_model:e.upstream_model,protocol:e.traits.protocol,onError:(e,t)=>console.warn(`[tboxcode-llm] ${e}: ${String(t)}`)},dn(globalThis.fetch));return{fetch:p.fetch,drain:p.drain,callId:l}}async*#u(e,t){let n=e.traits,r=await this.#l(e,t),i=mt(n.reasoning?.effort,void 0,t.reasoningEffort),a={...e,credentials:{...e.credentials,headers:{...e.baseHeaders,...i===void 0?{}:e.effortHeaders?.[i]}}},o=Rt(a,{headers:m(),...r===void 0?{}:{fetch:r.fetch,drain:r.drain}}),{system:s}=t,c=this.#i?.(),l=e=>c===void 0||this.#a===void 0?void 0:this.#a(c,e),u=Wn(n),d;try{d=await wn(t.messages,c,{resolveAccess:l,targetOf:t=>this.imageRequestTarget(e.providerId,e.modelId,t),...u===void 0?{}:{budget:u},...t.signal===void 0?{}:{signal:t.signal}})}catch(e){throw Bn(e)}let p=bn(d.messages,s,{images:d.versions,resolveImageAccess:l,protocol:n.protocol}),h=Sn(t.tools),g={sessionId:t.sessionId??`agentless`,effort:t.reasoningEffort,model:{id:t.model,context:n.limit.context,output:n.limit.output},reasoningEnabled:n.reasoning!==void 0},_=t.purpose!==`compaction`,v=Mt(p.messages,n,g,p.system,e.provider_name,{messageBreakpoints:_}),y=v.toolsCacheControl!==null&&v.toolsCacheControlKey!==null&&h!==void 0?Object.fromEntries(Object.entries(h).map(([e,t])=>[e,{...t,providerOptions:{...t.providerOptions,[v.toolsCacheControlKey]:{...t.providerOptions?.[v.toolsCacheControlKey]??{},cacheControl:v.toolsCacheControl}}}])):h,b=t.purpose===`compaction`?n.limit.output:t.maxTokens??n.limit.output,x=new AbortController,S=t.signal,C=()=>x.abort(S?.reason);S!==void 0&&(S.aborted?x.abort(S.reason):S.addEventListener(`abort`,C,{once:!0}));let w=o.streamText({model:{id:e.upstream_model,traits:n},system:v.system,messages:v.messages,providerOptions:v.providerOptions,tools:y,signal:x.signal,credentials:a.credentials,maxRetries:0,params:{...t.temperature===void 0?{}:{temperature:t.temperature},maxOutputTokens:b,...t.stop!==void 0&&t.stop.length>0?{stopSequences:t.stop}:{}}}),T=0,E=()=>T++,D=n.protocol===`anthropic`,O=[],k=e=>{for(;O.length<=e;)O.push(null)},A=(e,t)=>{if(!D)return;let n=gn(t);n!==void 0&&(k(e),O[e]={anthropic:n})},j=new Map,M=new Map,N=new Map,P,F=!1,I=!1,L=n.limit.idle_timeout_ms,R=w.fullStream[Symbol.asyncIterator](),z=!1,B,ee=async()=>L===void 0?R.next():Promise.race([R.next(),new Promise((e,t)=>{B=setTimeout(()=>{z=!0;let e=new f(`LLM stream idle timeout`,`TIMEOUT`);x.abort(e),t(e)},L)})]);try{for(;;){let t=await ee();if(B!==void 0&&(clearTimeout(B),B=void 0),t.done===!0)break;let n=t.value;switch(n.type){case`text-start`:{let e=String(n.id??``),t=E();k(t),j.set(e,{index:t,buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`text`};break}case`text-delta`:{let e=String(n.id??``),t=j.get(e),r=String(n.text??``);if(t===void 0)break;F=!0,t.buffer+=r,yield{type:`text-delta`,index:t.index,text:r};break}case`text-end`:{let e=String(n.id??``),t=j.get(e);if(t===void 0)break;F=!0,j.delete(e),yield{type:`block-end`,index:t.index,block:{type:`text`,text:t.buffer}};break}case`reasoning-start`:{let e=String(n.id??``),t=E();k(t),A(t,n),M.set(e,{index:t,buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`reasoning`};break}case`reasoning-delta`:{let e=String(n.id??``),t=M.get(e),r=String(n.text??``);if(t===void 0)break;A(t.index,n),F=!0,t.buffer+=r,yield{type:`reasoning-delta`,index:t.index,text:r};break}case`reasoning-end`:{let e=String(n.id??``),t=M.get(e);if(t===void 0)break;A(t.index,n),F=!0,M.delete(e),yield{type:`block-end`,index:t.index,block:{type:`reasoning`,text:t.buffer}};break}case`tool-input-start`:{let e=String(n.id??``),t=E();k(t),N.set(e,{index:t,name:String(n.toolName??``),buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`tool-call`};break}case`tool-input-delta`:{let e=String(n.id??``),t=N.get(e);if(t===void 0)break;F=!0;let r=String(n.delta??``);t.buffer+=r,yield{type:`tool-call-delta`,index:t.index,id:Vn(e),name:t.name,argumentsDelta:r};break}case`tool-call`:{let e=String(n.toolCallId??n.id??``),t=N.get(e);if(t===void 0)break;F=!0;let r=typeof n.toolName==`string`&&n.toolName.length>0?n.toolName:t.name;N.delete(e);let i=n.invalid===!0?t.buffer:JSON.stringify(n.input??{});yield{type:`block-end`,index:t.index,block:{type:`tool-call`,id:Vn(e),name:r,arguments:i}};break}case`abort`:throw new f(`请求已取消`,`ABORTED`);case`error`:throw Bn(n.error);case`finish-step`:P=n.usage;break;case`finish`:{let t=P??n.totalUsage??{},r=P?.raw??{},i=t.inputTokenDetails??{},a=t.outputTokenDetails??{},o=$(t.inputTokens),s=Math.max($(i.cacheReadTokens),$(r.prompt_cache_hit_tokens),$(r.cache_read_input_tokens)),c=Math.max($(i.cacheWriteTokens),$(r.cache_creation_input_tokens)),l=Math.max(o,s+c),u=Math.max(0,l-s-c),d=$(t.outputTokens),f=Math.max($(a.reasoningTokens),$(r.completion_tokens_details?.reasoning_tokens)),p=$(t.totalTokens)||$(r.total_tokens),m=l+d,h=p===m?p:m;yield{type:`usage`,usage:{inputTokens:u,outputTokens:d,...h>0?{totalTokens:h}:{},...s>0?{cacheReadTokens:s}:{},...c>0?{cacheWriteTokens:c}:{},...f>0&&f<=d?{reasoningTokens:f}:{}}};let g=Kn(n.finishReason);g.kind===`stop`&&!F&&(g={kind:`error`,failure:{message:`model returned no content`,code:`EMPTY_RESPONSE`}});let _=D&&g.kind!==`error`&&O.some(e=>e!==null);yield{type:`finish`,reason:g,..._?{replayState:{response:{provider:e.provider_name,model:e.upstream_model,...typeof n.finishReason==`string`?{finishReason:n.finishReason}:{}},blocks:O}}:{}},I=!0;break}default:break}}if(!I)throw S?.aborted?new f(`请求已取消`,`ABORTED`):new f(`LLM stream ended without a finish chunk`,`TRANSPORT`)}catch(e){throw z?new f(`LLM stream idle timeout`,`TIMEOUT`,{cause:e instanceof Error?e:void 0}):S?.aborted?new f(`请求已取消`,`ABORTED`,{cause:e instanceof Error?e:void 0}):Bn(e)}finally{B!==void 0&&clearTimeout(B),S?.removeEventListener(`abort`,C),await o.dispose()}}};function Kn(e){switch(e){case`tool-calls`:return{kind:`tool-calls`};case`length`:return{kind:`max-tokens`};case`content-filter`:return{kind:`error`,failure:{message:`模型输出被内容安全策略拦截`,code:`INVALID_REQUEST`}};case`other`:case`unknown`:return{kind:`error`,failure:{message:`LLM 流以未识别的 finishReason 结束(可能被截断)`,code:`TRANSPORT`}};case`error`:return{kind:`error`,failure:{message:`stream error`,code:`SERVER`}};case`stop`:default:return{kind:`stop`}}}function qn(e){return Tt(e)}const Jn=`tboxcode-llm`,Yn=[`llm`];function Xn(e){let t=e.get(`sessionPersistence`),n=t?.config?.root,r=t?.stat;if(!(n===void 0||r===void 0))return{root:n,cwdOf:async e=>(await r.call(t,e))?.header.cwd}}function Zn(e){for(let t of[`auth.jsonc`,`auth.json`]){let n=l(e,t);if(S(n))try{w(n).mode&63&&console.warn(`[tboxcode-llm] auth 文件权限过宽(建议 0600): ${n}`);let e=ot(JSON.parse(at(C(n,`utf-8`))));return nn.parse(e)}catch(e){throw new f(`auth 文件解析失败(${n}):${e instanceof Error?e.message:String(e)}`,`INVALID_CREDENTIAL`)}}return{}}function Qn(){let e=rt(),t=st(e).config;return{config:en.parse(t),auth:Zn(e)}}function $n(e){if(e instanceof E){let t=e.issues.slice(0,5).map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`),n=e.issues.length>t.length?`(共 ${e.issues.length} 项)`:``;return`config schema 校验失败:${t.join(`;`)}${n}`}return e instanceof Error?e.message:String(e)}function er(e,t,n){let r=n?`——保存后自动注册,无需重启`:`——该配置目录为首次创建,配置后需重启进程`;if(e instanceof f&&e.code===`INVALID_ADAPTER`){console.warn(`[tboxcode-llm] config 未配置 provider——LLM 域待命(adapter 不注册,模型调用不可用)`),console.warn(`[tboxcode-llm] 编辑 ${l(t,`config.jsonc`)} 的 provider 段(示例见 tboxcode-dsh init --config 生成的模板注释)${r}`);return}if(e instanceof f&&e.code===`DUPLICATE_ADAPTER`){console.warn(`[tboxcode-llm] provider 路由注册冲突——LLM 域待命:${e.message}(路由 id 已被其他 adapter 占用,请更换 provider id)${r}`);return}console.warn(`[tboxcode-llm] config/auth 加载失败——LLM 域待命:${$n(e)}${r}`)}function tr(e,t){let n=e.provider??{},r=new Map;for(let[e,t]of Object.entries(n)){let n=typeof t.name==`string`&&t.name.trim().length>0?t.name.trim():e;r.set(n,[...r.get(n)??[],e])}for(let[e,t]of r)t.length>1&&console.warn(`[tboxcode-llm] provider 显示名重复: "${e}" (${t.join(`, `)})——GUI 分组可能同名,建议区分`);let i=Object.entries(n).filter(([,e])=>Object.values(e.models).some(e=>e.image!==void 0)).map(([e])=>e);if(i.length>0&&t.get(`attachments`)===void 0&&console.warn(`[tboxcode-llm] provider 声明了 image 但附件服务未挂载(${i.join(`, `)})——图片输入不可用`),e.model===void 0||e.model.length===0)return;let a=e.model.indexOf(`/`);if(a<=0||a===e.model.length-1){console.warn(`[tboxcode-llm] 默认模型引用格式无效: "${e.model}"(应为 provider/model)`);return}let o=e.model.slice(0,a),s=e.model.slice(a+1),c=n[o];if(c!==void 0){if(e.disabled_providers?.includes(o)===!0){console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(provider disabled)`);return}if(e.enabled_providers!==void 0&&e.enabled_providers.length>0&&!e.enabled_providers.includes(o)){console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(provider 不在 enabled_providers)`);return}c.models[s]===void 0&&console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(model 不存在)`)}}function nr(e){let t=rt(),n=S(t),r,i,a,o=()=>{let t=Qn(),n=Object.keys(t.config.provider??{});if(n.length===0)throw new f(`config 未配置 provider`,`INVALID_ADAPTER`);i=new Gn({config:t.config,auth:t.auth,llmLog:an(t.config.llm_log),callLogPaths:Xn(e),resolveAttachments:()=>e.get(`attachments`),resolveImageAccess:(t,n)=>b(t,t=>e.get(`fs`)?.processPathFromHostPath?.(t),n)}),a=e.llm.registerAdapter(n,i),tr(t.config,e),r=t};try{o()}catch(e){er(e,t,n)}let s;try{s=ct(t,[`config.jsonc`,`config.json`,`auth.jsonc`,`auth.json`],()=>{try{if(a===void 0){o(),console.warn(`[tboxcode-llm] provider 路由已注册(热载挂载):${Object.keys(r?.config.provider??{}).join(`, `)}`);return}let t=Qn();i?.refresh?.(t.config,t.auth,an(t.config.llm_log)),a.replace(Object.keys(t.config.provider??{})),tr(t.config,e),r=t}catch(e){let t=a===void 0?`维持待命`:`保留上一代`,n=e instanceof Error?e.message:String(e);console.warn(`[tboxcode-llm] 配置热载失败(${t}):${n}`)}})}catch{}return()=>{s?.dispose(),a?.()}}export{nr as apply,Yn as inject,Jn as name};
|
|
119
|
+
`),messages:a}}function En(e){try{return JSON.parse(e)}catch{return{}}}function Dn(e){if(e===void 0||e.length===0)return;let t={};for(let n of e)t[n.name]=re({description:n.description,inputSchema:te(n.parameters)});return t}function On(e){let t=new Map;for(let n of e)if(h(n.content)){if(n.role!==`user`&&n.role!==`tool`)throw new f(`cannot represent an image in an in-history ${n.role} message`,`UNSUPPORTED_CONTENT`);for(let e of n.content)e.type!==`image`||e.offloaded===!0||t.set(e.attachment.attachmentId,e.attachment)}return t}function kn(e,t){let n=-1;for(let t=0;t<e.length;t++)e[t]?.role===`assistant`&&(n=t);let r=[];for(let i=0;i<e.length;i++){let a=e[i];if(!(a===void 0||a.role!==`user`&&a.role!==`tool`)&&h(a.content))for(let e=0;e<a.content.length;e++){let o=a.content[e];o?.type!==`image`||o.offloaded===!0||r.push({messageIndex:i,blockIndex:e,attachmentId:o.attachment.attachmentId,role:a.role,currentTurn:i>n,counted:a.role===`user`||t===`anthropic`})}}return{occurrences:r}}function An(e){return Math.ceil(e/3)*4}function jn(e){switch(e){case`count_limit_current_turn`:return`[image omitted: request image-count limit (30); oldest current-turn image dropped]`;case`count_limit`:return`[image omitted: request image-count limit (30); oldest image dropped]`;case`byte_limit`:return`[image omitted: request-size limit (32 MiB); oldest image dropped]`}}function Mn(e,t,n){let r=n.maxImages??30,i=n.maxImageBytes??Math.max(0,(n.requestMaxBytes??32*1024*1024)-(n.imageReserveBytes??8*1024*1024)),a=kn(e,n.protocol).occurrences.filter(e=>e.counted),o=[];if(a.length>r){let e=r===0?new Set:new Set(a.slice(-r));for(let t of a)e.has(t)||o.push(t)}let s=new Set(o),c=0;for(let e of a){if(s.has(e))continue;let n=t.get(e.attachmentId);n!==void 0&&(c+=An(n.bytes))}let l=[];if(c>i)for(let e of a){if(c<=i)break;if(s.has(e))continue;let n=t.get(e.attachmentId);n!==void 0&&(l.push(e),c-=An(n.bytes))}let u=[...o,...l],d=a.length-u.length,f=[];if(o.length>0){let e=0;for(let n of o){let r=t.get(n.attachmentId);r!==void 0&&(e+=An(r.bytes))}let n=o.filter(e=>e.currentTurn).length;f.push({reason:n>0?`count_limit_current_turn`:`count_limit`,dropped:o.length,droppedCurrentTurn:n,retained:d,bytesDropped:e})}if(l.length>0){let e=0;for(let n of l){let r=t.get(n.attachmentId);r!==void 0&&(e+=An(r.bytes))}f.push({reason:`byte_limit`,dropped:l.length,droppedCurrentTurn:l.filter(e=>e.currentTurn).length,retained:d,bytesDropped:e})}if(u.length===0)return{messages:e,events:f};let p=new Map;for(let e of o){let t=p.get(e.messageIndex)??new Map;t.set(e.blockIndex,e.currentTurn?`count_limit_current_turn`:`count_limit`),p.set(e.messageIndex,t)}for(let e of l){let t=p.get(e.messageIndex)??new Map;t.set(e.blockIndex,`byte_limit`),p.set(e.messageIndex,t)}return{messages:e.map((e,t)=>{let n=p.get(t);if(n===void 0)return e;let r=e.content.map((e,t)=>{let r=n.get(t);return r===void 0?e:{type:`text`,text:jn(r)}});return{...e,content:r}}),events:f}}async function Nn(e,t,n){let r=_(e,e=>g(e,n.resolveAccess(e))),i=On(r);if(i.size===0)return{messages:r,versions:new Map};if(t===void 0)throw new f(`image input requires the mounted attachment service`,`UNSUPPORTED_CONTENT`);for(let e of i.values())n.projection?.validateRef?.(e);let a=new Map;for(let e of i.values())a.set(e.attachmentId,await t.readImageRequest(e,n.targetOf(e),n.signal));if(n.projection!==void 0){let e=Mn(r,a,n.projection);for(let t of e.events)n.projection.onProjection?.(t);let t=e.events[0];return{messages:e.messages,versions:a,...t===void 0?{}:{projection:{reason:t.reason,dropped:e.events.reduce((e,t)=>e+t.dropped,0),droppedCurrentTurn:e.events.reduce((e,t)=>e+t.droppedCurrentTurn,0),retained:t.retained,bytesDropped:e.events.reduce((e,t)=>e+t.bytesDropped,0)}}}}if(n.budget!==void 0){let e=y(r,n.budget,e=>{let t=a.get(e.attachment.attachmentId);if(t===void 0)throw new f(`missing prepared request image version`,`UNSUPPORTED_CONTENT`);return t.bytes});if(e>0)throw new f(`image request exceeds route budget; ${e} more oldest occurrence(s) must be offloaded`,u,{offloadImages:e})}return{messages:r,versions:a}}function Pn(e,t){let n=e.image_max_pixels,r=Math.max(1,t.width),i=Math.max(1,t.height);if(n===void 0||r*i<=n)return{width:r,height:i,maxBytes:t.bytes};let a=Math.sqrt(n/(r*i));return{width:Math.max(1,Math.floor(r*a)),height:Math.max(1,Math.floor(i*a)),maxBytes:t.bytes}}function Fn(e,t){if(![`image/png`,`image/jpeg`,`image/webp`,`image/gif`].includes(t.mediaType))throw new f(`unsupported image media type: ${t.mediaType}`,`UNSUPPORTED_CONTENT`);let n=e.image_max_aspect_ratio;if(n===void 0)return;let r=Math.max(1,t.width),i=Math.max(1,t.height);if(Math.max(r,i)/Math.min(r,i)>n)throw new f(`image aspect ratio exceeds ${n}: ${r}x${i}`,`UNSUPPORTED_CONTENT`)}function In(e){if(e==null)return 0;if(typeof e==`string`)return new TextEncoder().encode(e).byteLength;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(typeof Blob<`u`&&e instanceof Blob)return e.size;if(typeof URLSearchParams<`u`&&e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).byteLength}function Ln(e,t=globalThis.fetch){return(async(n,r)=>{let i=In(r?.body);if(i!==void 0&&i>e)throw new f(`request body ${i} bytes exceeds request_max_bytes ${e}`,`REQUEST_TOO_LARGE`);return t(n,r)})}function Rn(){return{traceId:o(16).toString(`hex`),rpcId:`0.1`}}function zn(e){return{"sofa-traceid":e.traceId,"sofa-rpcid":e.rpcId,traceid:e.traceId,rpcid:e.rpcId}}function Bn(e,t){if(e===void 0)return;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n&&r.length>0)return r}function Vn(e,t){let n=e.requestId;if(typeof n==`string`&&n.length>0)return n;let r=e.data;if(typeof r==`object`&&r){let e=r,t=e.request_id??e.requestId;if(typeof t==`string`&&t.length>0)return t}for(let e of[`x-request-id`,`request-id`,`x-correlation-id`,`openai-request-id`,`x-amzn-requestid`,`cf-ray`,`x-goog-request-id`]){let n=Bn(t,e);if(n!==void 0)return n}}function Hn(e){if(e===void 0)return;let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;let n=Number(t[`retry-after-ms`]);if(Number.isFinite(n)&&n>0)return Math.ceil(n);let r=t[`retry-after`];if(r===void 0)return;let i=Number(r);if(Number.isFinite(i)&&i>0)return Math.ceil(i*1e3);let a=Date.parse(r);if(Number.isFinite(a))return Math.max(0,a-Date.now())||void 0}function Un(e){if(e instanceof Error){let t=e.lastError??e,n=t.statusCode,r=t.responseHeaders,i=r instanceof Headers?Object.fromEntries(r.entries()):typeof r==`object`&&r?Object.fromEntries(Object.entries(r).filter(e=>typeof e[1]==`string`)):void 0;return{name:e.name,msg:e.message.toLowerCase(),statusCode:typeof n==`number`?n:void 0,responseHeaders:i,retryAfterMs:Hn(i),requestId:Vn(t,i)}}return{name:``,msg:String(e).toLowerCase(),statusCode:void 0,responseHeaders:void 0,retryAfterMs:void 0,requestId:void 0}}function Wn(e){return e.name===`TypeError`&&e.msg.includes(`terminated`)||e.msg.includes(`econnreset`)||e.msg.includes(`econnrefused`)||e.msg.includes(`socket hang up`)||e.msg.includes(`fetch failed`)||e.msg.includes(`network error`)||e.msg.includes(`other side closed`)||e.msg.includes(`cannot connect to api`)}function Gn(e){return e.statusCode===401||e.statusCode===403||e.msg.includes(`unauthorized`)||e.msg.includes(`forbidden`)||e.msg.includes(`invalid api key`)}function Kn(e){return e.statusCode===429||e.msg.includes(`rate limit`)||e.msg.includes(`rate_limit`)||e.msg.includes(`too many requests`)||pn(e.msg)}function qn(e){return e.statusCode!==void 0&&e.statusCode>=500||e.msg.includes(`server error`)||e.msg.includes(`internal server`)}function Jn(e){return e.statusCode===400&&(e.msg.includes(`context length`)||e.msg.includes(`context_window`)||e.msg.includes(`maximum context`))}function Yn(e){return e.name===`AI_NoOutputGeneratedError`||e.msg.includes(`no output generated`)}function Xn(e){return e.msg.includes(`content_filter`)||e.msg.includes(`content policy`)||e.msg.includes(`content filter`)||e.msg.includes(`safety filter`)}function Zn(e){return e.statusCode===408||e.msg.includes(`timeout`)||e.msg.includes(`timed out`)}function Qn(e){return e.statusCode===400||e.statusCode===404||e.statusCode===413||e.statusCode===422||e.msg.includes(`invalid request`)||e.msg.includes(`bad request`)}const $n=[{match:Wn,code:`TRANSPORT`,message:`与 LLM 服务的连接中断(网络异常)`},{match:Gn,code:`AUTH`,message:`模型服务鉴权失败,请检查 API Key 配置`},{match:Kn,code:`RATE_LIMIT`,message:`触发限流,请稍后重试`},{match:Jn,code:`CONTEXT_WINDOW_EXCEEDED`,message:`上下文长度超限`},{match:qn,code:`SERVER`,message:`模型服务异常`},{match:Yn,code:`EMPTY_RESPONSE`,message:`模型未产生输出`},{match:Xn,code:`INVALID_REQUEST`,message:`内容被安全策略拦截`},{match:Zn,code:`TIMEOUT`,message:`模型服务请求超时`},{match:Qn,code:`INVALID_REQUEST`,message:`模型请求无效`}];function er(e){return e instanceof DOMException&&e.name===`AbortError`||e instanceof Error&&e.name===`AbortError`}function tr(e){if(e instanceof f)return e;if(er(e))return new f(`请求已取消`,`ABORTED`,{cause:e});let t=Un(e),n=t.statusCode!==void 0&&Number.isInteger(t.statusCode)&&t.statusCode>=100&&t.statusCode<=599?t.statusCode:void 0,r={cause:e instanceof Error?e:void 0,...n===void 0?{}:{status:n},...t.retryAfterMs===void 0?{}:{providerRetryAfterMs:t.retryAfterMs},...t.requestId===void 0?{}:{requestId:p(t.requestId)}};for(let e of $n)if(e.match(t))return new f(e.message,e.code,r);return new f(`LLM 调用失败`,`TRANSPORT`,r)}const nr=e=>e;function $(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.trunc(t)):0}function rr(e,t){let n=t?.name;return typeof n==`string`&&n.trim().length>0?n.trim():e}function ir(e){return e?.image===void 0?[`text`]:[`text`,`image`]}function ar(e){let t=e;if(!(t===void 0||t.image_max_bytes===void 0&&t.image_max_images===void 0&&t.image_byte_quantum===void 0&&t.image_count_quantum===void 0))return{representation:`base64`,...t.image_max_bytes===void 0?{}:{maxBytes:t.image_max_bytes},...t.image_max_images===void 0?{}:{maxImages:t.image_max_images},...t.image_byte_quantum===void 0?{}:{byteQuantum:t.image_byte_quantum},...t.image_count_quantum===void 0?{}:{countQuantum:t.image_count_quantum}}}function or(e){let t=e.workspace?.init_model??rn;try{if(Z(t).modelId===X)throw Error(`workspace.init_model must not reference auto`);return t}catch(e){throw new f(`workspace.init_model 非法:${t}(须为 provider/model,且不能是 auto)`,`INVALID_CONFIG`,{cause:e instanceof Error?e:void 0})}}function sr(e){try{let t=Z(e.workspace?.init_model??rn);return t.modelId===X?void 0:t}catch{return}}var cr=class extends d{#e;#t;#n;#r;#i;#a;#o;constructor(e){super(),this.#e=e.config,this.#t=e.auth,this.#n=e.llmLog,this.#r=e.callLogPaths,this.#i=e.resolveAttachments,this.#a=e.resolveImageAccess,this.#o=e.onImageProjection}refresh(e,t,n){this.#e=e,this.#t=t,this.#n=n}get llmLog(){return this.#n}providerInfo(e){let t=this.#e.provider?.[e]?.name,n=typeof t==`string`?t.trim():``;return{id:e,name:n.length>0?n:e}}listModels(e){if(!this.#c(e))return Promise.resolve([]);let t=this.#e.provider?.[e];if(t===void 0)return Promise.resolve([]);let n=[],r=new Set;for(let[i,a]of Object.entries(t.models)){if(i.length===0||r.has(i)){console.warn(`[tboxcode-llm] 跳过非法/重复模型条目: provider=${e} id="${i}"`);continue}if(i===X){console.warn(`[tboxcode-llm] 忽略显式 auto 条目(auto 是 workspace.init_model 虚拟 alias)`);continue}r.add(i);let t=rr(i,a);t.length!==0&&n.push({provider:e,id:i,name:t,inputModalities:ir(a)})}let i=sr(this.#e);if(i?.providerId===e){let r=t.models[i.modelId];r?.image===void 0?r===void 0?console.warn(`[tboxcode-llm] auto 目标模型不存在: ${i.providerId}/${i.modelId}`):console.warn(`[tboxcode-llm] auto 目标模型未声明 image: ${i.providerId}/${i.modelId}`):n.push({provider:e,id:X,name:`Auto`,inputModalities:ir(r)})}return Promise.resolve(n)}async resolveModel(e,t){return this.#s(this.#l(`${e}/${t}`))}imageRequestTarget(e,t,n){return Pn(this.#l(`${e}/${t}`).traits,n)}#s(e){let t=e.traits.reasoning?.effort,n=this.#e.effort,r=t?.levels!==void 0&&typeof n==`string`&&n.length>0&&t.levels.some(e=>e.id===n)?n:t?.default;return{provider:e.providerId,id:e.modelId,name:e.modelId===X?`Auto`:rr(e.modelId,e.traits),inputModalities:ir(e.traits),context:{contextWindow:e.traits.limit.context},defaultMaxTokens:e.traits.limit.output,...t?.levels!==void 0&&t.levels.length>0?{reasoning:{efforts:t.levels.map(e=>({id:nr(e.id),name:e.name??e.id})),...r===void 0?{}:{defaultEffort:nr(r)}}}:{}}}#c(e){if(this.#e.disabled_providers?.includes(e)===!0)return!1;let t=this.#e.enabled_providers;return t===void 0||t.length===0||t.includes(e)}providerRetryPolicy(e){let t=this.#e.provider?.[e]?.retry;return x(t??{mode:`normal`,maxRetries:2},`tboxcode-llm provider "${e}" retryPolicy`)}async*stream(e){yield*(await this.prepareCall(e.provider,e.model,e.signal)).stream(e)}async prepareCall(e,t,n){let r=this.#l(`${e}/${t}`);return{model:this.#s(r),stream:e=>this.#d(r,e)}}#l(e){try{let t=Z(e);if(t.modelId===X){let e=or(this.#e),n=Z(e);if(n.providerId!==t.providerId)throw new f(`auto 只挂在 workspace.init_model 的 provider 上:请求 ${t.providerId},目标 ${n.providerId}`,`INVALID_CONFIG`);if(!this.#c(n.providerId))throw new f(`auto 目标 provider 不可用:${n.providerId}`,`INVALID_CONFIG`);let r;try{r=fn(e,this.#e,this.#t)}catch(t){throw new f(`workspace.init_model 无法解析:${e}`,`INVALID_CONFIG`,{cause:t instanceof Error?t:void 0})}if(r.traits.image===void 0)throw new f(`workspace.init_model 必须声明 image:${e}`,`INVALID_CONFIG`);return{...r,modelId:X}}return fn(e,this.#e,this.#t)}catch(e){throw e instanceof f?e:e instanceof ft?new f(e.message,`UNKNOWN_MODEL`,{cause:e}):e instanceof Y||e instanceof pt||e instanceof mt?new f(e.message,`INVALID_CONFIG`,{cause:e}):e}}async#u(e,i){if(!this.#n.enabled||this.#r===void 0)return;let{root:a,cwdOf:s}=this.#r,c=i.sessionId===void 0?void 0:String(i.sessionId),l=`llmc_${o(8).toString(`hex`)}`,u;if(c!==void 0)try{let e=await s(c);u=e===void 0?r(a):t(a,e,c)}catch{u=r(a)}else u=r(a);let d=i.purpose,f=d===`compaction`?`compact`:d===`session-title`?`title`:`main`,p=n({enabled:!0,max_file_bytes:this.#n.max_file_bytes,sanitize_headers:this.#n.sanitize_headers,logDir:u,sessionId:c??`agentless`,trigger:f,callId:l,traitsVersion:ur(e.traits),provider_name:e.provider_name,modelId:i.model,upstream_model:e.upstream_model,protocol:e.traits.protocol,onError:(e,t)=>console.warn(`[tboxcode-llm] ${e}: ${String(t)}`)},gn(globalThis.fetch));return{fetch:p.fetch,drain:p.drain,callId:l}}async*#d(e,t){let n=e.traits,r=await this.#u(e,t),i=gt(n.reasoning?.effort,void 0,t.reasoningEffort),a=this.#e.provider?.[e.providerId]?.trace?.type===`sofa`?zn(Rn()):void 0,o={...e,credentials:{...e.credentials,headers:{...e.baseHeaders,...i===void 0?{}:e.effortHeaders?.[i],...a??{}}}},s=r?.fetch??globalThis.fetch.bind(globalThis),c=n.request_max_bytes===void 0?void 0:Ln(n.request_max_bytes,s),l=Bt(o,{headers:m(),...c===void 0&&r===void 0?{}:{fetch:c??r.fetch,...r===void 0?{}:{drain:r.drain}}}),{system:u}=t,d=this.#i?.(),p=e=>d===void 0||this.#a===void 0?void 0:this.#a(d,e),h=this.#e.media_policy,g=h?.mode===`project`,_=g?void 0:ar(n),v;try{v=await Nn(t.messages,d,{resolveAccess:p,targetOf:t=>this.imageRequestTarget(e.providerId,e.modelId,t),..._===void 0?{}:{budget:_},...g?{projection:{mode:`project`,protocol:n.protocol,requestMaxBytes:n.request_max_bytes,imageReserveBytes:h?.image_reserve_bytes,validateRef:e=>Fn(n,e),onProjection:n=>this.#o?.({...t.sessionId===void 0?{}:{sessionId:String(t.sessionId)},provider:e.providerId,model:t.model,...n})}}:{},...t.signal===void 0?{}:{signal:t.signal}})}catch(e){throw tr(e)}let y=Tn(v.messages,u,{images:v.versions,resolveImageAccess:p,protocol:n.protocol}),b=Dn(t.tools),x={sessionId:t.sessionId??`agentless`,effort:t.reasoningEffort,model:{id:t.model,context:n.limit.context,output:n.limit.output},reasoningEnabled:n.reasoning!==void 0},S=t.purpose!==`compaction`,C=Pt(y.messages,n,x,y.system,e.provider_name,{messageBreakpoints:S}),w=C.toolsCacheControl!==null&&C.toolsCacheControlKey!==null&&b!==void 0?Object.fromEntries(Object.entries(b).map(([e,t])=>[e,{...t,providerOptions:{...t.providerOptions,[C.toolsCacheControlKey]:{...t.providerOptions?.[C.toolsCacheControlKey]??{},cacheControl:C.toolsCacheControl}}}])):b,T=t.purpose===`compaction`?n.limit.output:t.maxTokens??n.limit.output,E=new AbortController,D=t.signal,ee=()=>E.abort(D?.reason);D!==void 0&&(D.aborted?E.abort(D.reason):D.addEventListener(`abort`,ee,{once:!0}));let te=l.streamText({model:{id:e.upstream_model,traits:n},system:C.system,messages:C.messages,providerOptions:C.providerOptions,tools:w,signal:E.signal,credentials:o.credentials,maxRetries:0,params:{...t.temperature===void 0?{}:{temperature:t.temperature},maxOutputTokens:T,...t.stop!==void 0&&t.stop.length>0?{stopSequences:t.stop}:{}}}),ne=0,re=()=>ne++,ie=n.protocol===`anthropic`,O=[],k=e=>{for(;O.length<=e;)O.push(null)},A=(e,t)=>{if(!ie)return;let n=xn(t);n!==void 0&&(k(e),O[e]={anthropic:n})},j=new Map,M=new Map,N=new Map,P,F=!1,I=!1,L=n.limit.idle_timeout_ms,R=te.fullStream[Symbol.asyncIterator](),z=!1,B,V=async()=>L===void 0?R.next():Promise.race([R.next(),new Promise((e,t)=>{B=setTimeout(()=>{z=!0;let e=new f(`LLM stream idle timeout`,`TIMEOUT`);E.abort(e),t(e)},L)})]);try{for(;;){let t=await V();if(B!==void 0&&(clearTimeout(B),B=void 0),t.done===!0)break;let n=t.value;switch(n.type){case`text-start`:{let e=String(n.id??``),t=re();k(t),j.set(e,{index:t,buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`text`};break}case`text-delta`:{let e=String(n.id??``),t=j.get(e),r=String(n.text??``);if(t===void 0)break;F=!0,t.buffer+=r,yield{type:`text-delta`,index:t.index,text:r};break}case`text-end`:{let e=String(n.id??``),t=j.get(e);if(t===void 0)break;F=!0,j.delete(e),yield{type:`block-end`,index:t.index,block:{type:`text`,text:t.buffer}};break}case`reasoning-start`:{let e=String(n.id??``),t=re();k(t),A(t,n),M.set(e,{index:t,buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`reasoning`};break}case`reasoning-delta`:{let e=String(n.id??``),t=M.get(e),r=String(n.text??``);if(t===void 0)break;A(t.index,n),F=!0,t.buffer+=r,yield{type:`reasoning-delta`,index:t.index,text:r};break}case`reasoning-end`:{let e=String(n.id??``),t=M.get(e);if(t===void 0)break;A(t.index,n),F=!0,M.delete(e),yield{type:`block-end`,index:t.index,block:{type:`reasoning`,text:t.buffer}};break}case`tool-input-start`:{let e=String(n.id??``),t=re();k(t),N.set(e,{index:t,name:String(n.toolName??``),buffer:``}),F=!0,yield{type:`block-start`,index:t,blockType:`tool-call`};break}case`tool-input-delta`:{let e=String(n.id??``),t=N.get(e);if(t===void 0)break;F=!0;let r=String(n.delta??``);t.buffer+=r,yield{type:`tool-call-delta`,index:t.index,id:nr(e),name:t.name,argumentsDelta:r};break}case`tool-call`:{let e=String(n.toolCallId??n.id??``),t=N.get(e);if(t===void 0)break;F=!0;let r=typeof n.toolName==`string`&&n.toolName.length>0?n.toolName:t.name;N.delete(e);let i=n.invalid===!0?t.buffer:JSON.stringify(n.input??{});yield{type:`block-end`,index:t.index,block:{type:`tool-call`,id:nr(e),name:r,arguments:i}};break}case`abort`:throw new f(`请求已取消`,`ABORTED`);case`error`:throw tr(n.error);case`finish-step`:P=n.usage;break;case`finish`:{let t=P??n.totalUsage??{},r=P?.raw??{},i=t.inputTokenDetails??{},a=t.outputTokenDetails??{},o=$(t.inputTokens),s=Math.max($(i.cacheReadTokens),$(r.prompt_cache_hit_tokens),$(r.cache_read_input_tokens)),c=Math.max($(i.cacheWriteTokens),$(r.cache_creation_input_tokens)),l=Math.max(o,s+c),u=Math.max(0,l-s-c),d=$(t.outputTokens),f=Math.max($(a.reasoningTokens),$(r.completion_tokens_details?.reasoning_tokens)),p=$(t.totalTokens)||$(r.total_tokens),m=l+d,h=p===m?p:m;yield{type:`usage`,usage:{inputTokens:u,outputTokens:d,...h>0?{totalTokens:h}:{},...s>0?{cacheReadTokens:s}:{},...c>0?{cacheWriteTokens:c}:{},...f>0&&f<=d?{reasoningTokens:f}:{}}};let g=lr(n.finishReason);g.kind===`stop`&&!F&&(g={kind:`error`,failure:{message:`model returned no content`,code:`EMPTY_RESPONSE`}});let _=ie&&g.kind!==`error`&&O.some(e=>e!==null);yield{type:`finish`,reason:g,..._?{replayState:{response:{provider:e.provider_name,model:e.upstream_model,...typeof n.finishReason==`string`?{finishReason:n.finishReason}:{}},blocks:O}}:{}},I=!0;break}default:break}}if(!I)throw D?.aborted?new f(`请求已取消`,`ABORTED`):new f(`LLM stream ended without a finish chunk`,`TRANSPORT`)}catch(e){throw z?new f(`LLM stream idle timeout`,`TIMEOUT`,{cause:e instanceof Error?e:void 0}):D?.aborted?new f(`请求已取消`,`ABORTED`,{cause:e instanceof Error?e:void 0}):tr(e)}finally{B!==void 0&&clearTimeout(B),D?.removeEventListener(`abort`,ee),await l.dispose()}}};function lr(e){switch(e){case`tool-calls`:return{kind:`tool-calls`};case`length`:return{kind:`max-tokens`};case`content-filter`:return{kind:`error`,failure:{message:`模型输出被内容安全策略拦截`,code:`INVALID_REQUEST`}};case`other`:case`unknown`:return{kind:`error`,failure:{message:`LLM 流以未识别的 finishReason 结束(可能被截断)`,code:`TRANSPORT`}};case`error`:return{kind:`error`,failure:{message:`stream error`,code:`SERVER`}};case`stop`:default:return{kind:`stop`}}}function ur(e){return Dt(e)}const dr=`tboxcode-llm`,fr=[`llm`];function pr(e){let t=e.get(`sessionPersistence`),n=t?.config?.root,r=t?.stat;if(!(n===void 0||r===void 0))return{root:n,cwdOf:async e=>(await r.call(t,e))?.header.cwd}}function mr(e){for(let t of[`auth.jsonc`,`auth.json`]){let n=l(e,t);if(S(n))try{w(n).mode&63&&console.warn(`[tboxcode-llm] auth 文件权限过宽(建议 0600): ${n}`);let e=ct(JSON.parse(st(C(n,`utf-8`))));return ln.parse(e)}catch(e){throw new f(`auth 文件解析失败(${n}):${e instanceof Error?e.message:String(e)}`,`INVALID_CREDENTIAL`)}}return{}}function hr(){let e=at(),t=lt(e).config;return{config:sn.parse(t),auth:mr(e)}}function gr(e){if(e instanceof E){let t=e.issues.slice(0,5).map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`),n=e.issues.length>t.length?`(共 ${e.issues.length} 项)`:``;return`config schema 校验失败:${t.join(`;`)}${n}`}return e instanceof Error?e.message:String(e)}function _r(e,t,n){let r=n?`——保存后自动注册,无需重启`:`——该配置目录为首次创建,配置后需重启进程`;if(e instanceof f&&e.code===`INVALID_ADAPTER`){console.warn(`[tboxcode-llm] config 未配置 provider——LLM 域待命(adapter 不注册,模型调用不可用)`),console.warn(`[tboxcode-llm] 编辑 ${l(t,`config.jsonc`)} 的 provider 段(示例见 tboxcode-dsh init --config 生成的模板注释)${r}`);return}if(e instanceof f&&e.code===`DUPLICATE_ADAPTER`){console.warn(`[tboxcode-llm] provider 路由注册冲突——LLM 域待命:${e.message}(路由 id 已被其他 adapter 占用,请更换 provider id)${r}`);return}console.warn(`[tboxcode-llm] config/auth 加载失败——LLM 域待命:${gr(e)}${r}`)}function vr(e,t){let n=e.provider??{},r=new Map;for(let[e,t]of Object.entries(n)){let n=typeof t.name==`string`&&t.name.trim().length>0?t.name.trim():e;r.set(n,[...r.get(n)??[],e])}for(let[e,t]of r)t.length>1&&console.warn(`[tboxcode-llm] provider 显示名重复: "${e}" (${t.join(`, `)})——GUI 分组可能同名,建议区分`);let i=Object.entries(n).filter(([,e])=>Object.values(e.models).some(e=>e.image!==void 0)).map(([e])=>e);if(i.length>0&&t.get(`attachments`)===void 0&&console.warn(`[tboxcode-llm] provider 声明了 image 但附件服务未挂载(${i.join(`, `)})——图片输入不可用`),e.model===void 0||e.model.length===0)return;let a=e.model.indexOf(`/`);if(a<=0||a===e.model.length-1){console.warn(`[tboxcode-llm] 默认模型引用格式无效: "${e.model}"(应为 provider/model)`);return}let o=e.model.slice(0,a),s=e.model.slice(a+1),c=n[o];if(c!==void 0){if(e.disabled_providers?.includes(o)===!0){console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(provider disabled)`);return}if(e.enabled_providers!==void 0&&e.enabled_providers.length>0&&!e.enabled_providers.includes(o)){console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(provider 不在 enabled_providers)`);return}c.models[s]===void 0&&console.warn(`[tboxcode-llm] 默认模型不可用: "${e.model}"(model 不存在)`)}}function yr(e){let t=at(),n=S(t),r,i,a,o=()=>{let t=hr(),n=Object.keys(t.config.provider??{});if(n.length===0)throw new f(`config 未配置 provider`,`INVALID_ADAPTER`);i=new cr({config:t.config,auth:t.auth,llmLog:dn(t.config.llm_log),callLogPaths:pr(e),resolveAttachments:()=>e.get(`attachments`),resolveImageAccess:(t,n)=>b(t,t=>e.get(`fs`)?.processPathFromHostPath?.(t),n),onImageProjection:e=>{console.warn(`[tboxcode-llm] ${JSON.stringify({event:`llm.image.projected`,...e})}`)}}),a=e.llm.registerAdapter(n,i),vr(t.config,e),r=t};try{o()}catch(e){_r(e,t,n)}let s;try{s=ut(t,[`config.jsonc`,`config.json`,`auth.jsonc`,`auth.json`],()=>{try{if(a===void 0){o(),console.warn(`[tboxcode-llm] provider 路由已注册(热载挂载):${Object.keys(r?.config.provider??{}).join(`, `)}`);return}let t=hr();i?.refresh?.(t.config,t.auth,dn(t.config.llm_log)),a.replace(Object.keys(t.config.provider??{})),vr(t.config,e),r=t}catch(e){let t=a===void 0?`维持待命`:`保留上一代`,n=e instanceof Error?e.message:String(e);console.warn(`[tboxcode-llm] 配置热载失败(${t}):${n}`)}})}catch{}return()=>{s?.dispose(),a?.()}}export{yr as apply,fr as inject,dr as name};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/tboxcode-dsh-llm",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "LlmAdapter:三协议 + traits + 限流 + call-log(zstd)+ echo / scenario driver + listModels GUI 硬规格 + adapters-updated 刷新",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@types/ws": "^8.18.0",
|
|
46
46
|
"ws": "^8.19.0",
|
|
47
47
|
"yaml": "^2.8.0",
|
|
48
|
-
"@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.
|
|
49
|
-
"@tbox.cn/tboxcode-dsh-cli": "0.1.0-rc.
|
|
48
|
+
"@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.5",
|
|
49
|
+
"@tbox.cn/tboxcode-dsh-cli": "0.1.0-rc.5"
|
|
50
50
|
},
|
|
51
51
|
"dsh": {
|
|
52
52
|
"bundle": {
|