eve 0.79.2 → 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/src/compiled/.vendor-stamp.json +6 -6
- package/dist/src/compiled/@chat-adapter/slack/api.d.ts +6 -0
- package/dist/src/compiled/@chat-adapter/slack/api.js +1 -1
- package/dist/src/compiled/@chat-adapter/slack/blocks.js +1 -1
- package/dist/src/compiled/@chat-adapter/slack/format.js +1 -1
- package/dist/src/compiled/@chat-adapter/slack/index.d.ts +14 -8
- package/dist/src/compiled/@chat-adapter/slack/index.js +33 -32
- package/dist/src/compiled/@chat-adapter/twilio/index.d.ts +37 -1
- package/dist/src/compiled/@chat-adapter/twilio/index.js +2 -2
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/index.js +1 -1
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.js +1 -1
- package/dist/src/compiled/@vercel/connect/index.js +5 -5
- package/dist/src/compiled/@vercel/connect/token.d.ts +11 -1
- package/dist/src/compiled/_chunks/node/chunk-NBSLXVG3-Bt7pDfyn.js +12 -0
- package/dist/src/compiled/_chunks/node/dist-BKsV21Vu.js +6 -0
- package/dist/src/compiled/_chunks/node/dist-CO_n_hUa.js +98 -0
- package/dist/src/compiled/chat/index.js +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +6 -6
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.d.ts +8 -4
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-connection.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/context/schedule-collection-tools.js +1 -1
- package/dist/src/execution/catalog/connection-auth.d.ts +4 -2
- package/dist/src/execution/catalog/connection-auth.js +1 -1
- package/dist/src/execution/catalog/connection-entry.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/session/entry.js +1 -1
- package/dist/src/execution/session-event-stream.js +1 -1
- package/dist/src/execution/stable-workflow-names.d.ts +2 -0
- package/dist/src/execution/stable-workflow-names.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/web-fetch/execute.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +6 -0
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/extensions/git/extension/extension.d.ts +3 -1
- package/dist/src/extensions/git/extension/extension.js +1 -1
- package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -1
- package/dist/src/extensions/git/extension/lib/github-shell.d.ts +14 -0
- package/dist/src/extensions/git/extension/lib/github-shell.js +1 -1
- package/dist/src/harness/model-call/call.js +1 -1
- package/dist/src/harness/model-call/errors.d.ts +2 -2
- package/dist/src/harness/model-call/recovery.d.ts +2 -3
- package/dist/src/instrumentation/session-init.d.ts +2 -1
- package/dist/src/instrumentation/session-init.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-definition/connection.js +1 -1
- package/dist/src/internal/authored-definition/schedule-collection.js +1 -1
- package/dist/src/internal/nitro/host/application-route-registry.d.ts +7 -2
- package/dist/src/internal/nitro/host/application-route-registry.js +1 -1
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +1 -1
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.d.ts +3 -1
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
- package/dist/src/internal/nitro/routes/connection-events.d.ts +5 -0
- package/dist/src/internal/nitro/routes/connection-events.js +1 -0
- package/dist/src/internal/workflow-bundle/builder.js +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.js +1 -1
- package/dist/src/public/channels/slack/blocks.js +2 -2
- package/dist/src/public/connections/index.d.ts +1 -0
- package/dist/src/public/definitions/connections/events.d.ts +43 -0
- package/dist/src/public/definitions/connections/events.js +1 -0
- package/dist/src/public/definitions/connections/mcp.d.ts +3 -0
- package/dist/src/public/schedules/subscription.d.ts +4 -3
- package/dist/src/runtime/connections/events/actions.d.ts +17 -0
- package/dist/src/runtime/connections/events/actions.js +1 -0
- package/dist/src/runtime/connections/events/delivery.d.ts +10 -0
- package/dist/src/runtime/connections/events/delivery.js +1 -0
- package/dist/src/runtime/connections/events/dispatch-step.d.ts +20 -0
- package/dist/src/runtime/connections/events/dispatch-step.js +1 -0
- package/dist/src/runtime/connections/events/lifecycle-step.d.ts +42 -0
- package/dist/src/runtime/connections/events/lifecycle-step.js +1 -0
- package/dist/src/runtime/connections/events/owner.d.ts +38 -0
- package/dist/src/runtime/connections/events/owner.js +1 -0
- package/dist/src/runtime/connections/events/path.d.ts +4 -0
- package/dist/src/runtime/connections/events/path.js +1 -0
- package/dist/src/runtime/connections/events/state.d.ts +37 -0
- package/dist/src/runtime/connections/events/state.js +1 -0
- package/dist/src/runtime/connections/events/workflow.d.ts +28 -0
- package/dist/src/runtime/connections/events/workflow.js +1 -0
- package/dist/src/runtime/connections/mcp-client.d.ts +4 -2
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/openapi-client.js +1 -1
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/runtime/resolve-connection.js +1 -1
- package/dist/src/runtime/schedules/collection-client.d.ts +0 -2
- package/dist/src/runtime/schedules/collection-client.js +1 -1
- package/dist/src/runtime/types.d.ts +11 -0
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -2
- package/dist/src/setup/scaffold/update/channels.js +1 -1
- package/dist/src/setup/scaffold/update/connections.js +2 -2
- package/dist/src/setup/scaffold/version-tokens.d.ts +1 -1
- package/dist/src/setup/scaffold/version-tokens.js +1 -1
- package/dist/src/shared/agent-definition.d.ts +12 -4
- package/dist/src/shared/connection-events.d.ts +84 -0
- package/dist/src/shared/connection-events.js +1 -0
- package/dist/src/shared/connection-types.d.ts +10 -0
- package/dist/src/shared/validate-authorization.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/no-reply.d.ts +5 -0
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tracing/eve/connection-events.d.ts +25 -0
- package/dist/src/tracing/eve/connection-events.js +1 -0
- package/dist/src/tracing/eve/install-instrumentation-runtime.js +1 -1
- package/dist/src/tracing/eve/mcp.d.ts +1 -0
- package/dist/src/tracing/eve/mcp.js +1 -1
- package/dist/src/tracing/eve/otel-declaration.d.ts +5 -0
- package/docs/agent-config.md +38 -13
- package/docs/code-extension.mdx +28 -0
- package/docs/concepts/built-in-tools.md +2 -0
- package/docs/connections/mcp.mdx +105 -0
- package/docs/guides/instrumentation/otel.mdx +10 -0
- package/docs/sandbox/vercel.mdx +46 -0
- package/package.json +7 -7
- package/dist/src/compiled/_chunks/node/chunk-6QHBXN7B-gl4n6nmi.js +0 -12
- package/dist/src/compiled/_chunks/node/dist-DYDVZ-FS.js +0 -98
- package/dist/src/compiled/_chunks/node/dist-iEFkK9qw.js +0 -6
|
@@ -8,6 +8,15 @@ export interface ConnectUserTokenSubject {
|
|
|
8
8
|
type: 'user';
|
|
9
9
|
id: string;
|
|
10
10
|
issuer?: string;
|
|
11
|
+
/**
|
|
12
|
+
* When specified, `id` and `issuer` identify the user in the namespace of
|
|
13
|
+
* this IDP connector. The connector must be configured as an IDP.
|
|
14
|
+
* The XAA/ID-JAG protocol is used to resolve the target access token when
|
|
15
|
+
* configured by the target connector.
|
|
16
|
+
*
|
|
17
|
+
* @experimental Subject to change.
|
|
18
|
+
*/
|
|
19
|
+
experimental_idp?: string;
|
|
11
20
|
}
|
|
12
21
|
export interface ConnectJwtBearerTokenSubject {
|
|
13
22
|
type: 'jwt-bearer';
|
|
@@ -19,7 +28,8 @@ export interface ConnectJwtBearerTokenSubject {
|
|
|
19
28
|
additionalClaims?: Record<string, unknown>;
|
|
20
29
|
}
|
|
21
30
|
export interface ConnectTokenExchangeSubject {
|
|
22
|
-
|
|
31
|
+
/** Inferred as `'token'` when omitted. */
|
|
32
|
+
type?: 'token';
|
|
23
33
|
token: string;
|
|
24
34
|
}
|
|
25
35
|
export interface ConnectTokenParams {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var e=/[<>|]/,t=/[\^|>]/,n=/^[A-Z0-9_]+$/,r=/(?<![<\w])@([A-Z][A-Z0-9_]+)/g,i=/^<!(here|channel|everyone)(?:\|[^<>]*)?>$/,a=/^<!subteam\^([A-Z0-9_]+)\|@?([^<>]+)>$/,o=/^<!subteam\^([A-Z0-9_]+)>$/,s=3e3,c=/^[ \t]+/,l=/^(?:>|<|#{1,6}(?=[ \t\n]|$)|[-+*](?=[ \t\n]|$)|`{3,}|~{3,}|(?:[-*_][ \t]*){3,}(?=\n|$))/,u=/^(\d{1,9})([.)])(?=[ \t\n]|$)/;function d(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function f(e){return e.replace(/</g,`<`).replace(/>/g,`>`).replace(/&/g,`&`)}function p(e,t={}){return P(e),{...t.emoji===void 0?{}:{emoji:t.emoji},text:e,type:`plain_text`}}function m(e,t={}){return P(e),{text:e,type:`mrkdwn`,...t.verbatim===void 0?{}:{verbatim:t.verbatim}}}function h(e){return F(e,`userId`),`<@${e}>`}function g(e){return F(e,`channelId`),`<#${e}>`}function _(e){return F(e,`userGroupId`),`<!subteam^${e}>`}function v(e){return`<!${e}>`}function y(e,t){return I(e,`url`),t?`<${e}|${d(t)}>`:`<${e}>`}function b(e,t,n,r={}){L(t,`token`);let i=e instanceof Date?Math.floor(e.getTime()/1e3):e;if(!Number.isInteger(i))throw TypeError(`timestamp must be an integer unix timestamp or Date`);return`<!date^${i}^${t}${r.link?`^${R(r.link)}`:``}|${d(n)}>`}function x(e){return f(e.includes("```")?D(e):w(e))}function S(e){let t=e.replace(/<@([A-Z0-9_]+)\|([^<>]+)>/g,`@$2`);return t=t.replace(/<@([A-Z0-9_]+)>/g,`@$1`),t=t.replace(/<#([A-Z0-9_]+)\|([^<>]+)>/g,`#$2 ($1)`),t=t.replace(/<#([A-Z0-9_]+)>/g,`#$1`),t=t.replace(/<(?!https?:\/\/|mailto:|tel:)([^<>|]+)\|(https?:\/\/[^|<>]+)>/g,`<$2|$1>`),t=t.replace(/<(https?:\/\/[^|<>]+)\|([^<>]+)>/g,`[$2]($1)`),t=t.replace(/<(https?:\/\/[^<>]+)>/g,`$1`),t=t.replace(/<((?:mailto|tel):[^|<>]+)\|([^<>]+)>/g,(e,t,n)=>C(t,n)),t=t.replace(/<((?:mailto|tel):([^|<>]+))>/g,(e,t,n)=>C(t,n)),t}function C(e,t){return`[${t.replace(/[\\[\]*_~`]/g,`\\$&`)}](${e.replace(/[\\()]/g,`\\$&`)})`}function w(e){return S(E(T(e)))}function T(e){let t=``,n=0,r=0;for(;n<e.length;){if(e[n]!=="`"&&e[n]!==`<`){n+=1;continue}if(e.startsWith("```",n)){n+=3;continue}let i=e[n]===`<`?O(e,n):k(e,n);if(i===-1){n+=1;continue}t+=e.slice(r,n)+`x`.repeat(i-n),r=i,n=i}t+=e.slice(r);let i=new Set;for(let e of[/(?<![_*\\])\*([^\s*](?:[^*\n]*[^\s*])?)\*(?![_*])/g,/(?<!~)~([^\s~](?:[^~\n]*[^\s~])?)~(?!~)/g])for(let n of t.matchAll(e))i.add(n.index),i.add(n.index+n[0].length-1);return e.replace(/[*~]/g,(e,t)=>i.has(t)?e.repeat(2):e)}function E(e){let t=``,n=0,r=0;for(;r<e.length;){if(e.startsWith("```",r)){r+=3;continue}if(e[r]==="`"){let t=k(e,r);r=t===-1?r+1:t;continue}if(e[r]!==`<`){r+=1;continue}let s=O(e,r);if(s===-1){r+=1;continue}let c=e.slice(r,s).replace(i,`@$1`).replace(a,`@$2`).replace(o,`@$1`);t+=e.slice(n,r)+c,n=s,r=s}return t+e.slice(n)}function D(e){let t=``,n=0,r=0,i=!1,a=r=>{let a=e.slice(n,r);i&&=(a=j(a),!1),t+=w(a)};for(;r<e.length;){let o=e[r];if(o===`<`){let t=O(e,r);r=t===-1?r+1:t;continue}if(o!=="`"){r+=1;continue}if(!e.startsWith("```",r)){let t=k(e,r);r=t===-1?r+1:t;continue}let s=r+3,c=e.indexOf("```",s);if(c===-1||A(e,r)){r=s;continue}a(r),t.length>0&&!t.endsWith(`
|
|
2
|
+
`)&&(t+=`
|
|
3
|
+
`);let l=e.slice(s,c);t+="```",l.startsWith(`
|
|
4
|
+
`)||(t+=`
|
|
5
|
+
`),t+=S(l),l.endsWith(`
|
|
6
|
+
`)||(t+=`
|
|
7
|
+
`),t+="```",r=c+3,n=r,r<e.length&&e[r]!==`
|
|
8
|
+
`&&(t+=`
|
|
9
|
+
`,i=!0)}return a(e.length),t}function O(e,t){let n=t+1;for(;n<e.length&&e[n]!==`<`&&e[n]!==`>`&&e[n]!==`
|
|
10
|
+
`&&e[n]!==`\r`;)n+=1;return e[n]===`>`?n+1:-1}function k(e,t){let n=t+1;for(;n<e.length&&e[n]!=="`"&&e[n]!==`
|
|
11
|
+
`&&e[n]!==`\r`;)n+=1;return e[n]==="`"?n+1:-1}function A(e,t){let n=e.lastIndexOf(`
|
|
12
|
+
`,t-1)+1;return e.slice(n,t).trimStart().startsWith(`>`)}function j(e){let t=c.exec(e)?.[0]??``,n=t.length>0?` `:``,r=e.slice(t.length);return l.test(r)?`${n}\\${r}`:n+r.replace(u,`$1\\$2`)}function M(e){return e.replace(/\*\*(.+?)\*\*/g,`*$1*`)}function N(e){return e.replace(r,`<@$1>`)}function P(e){if(e.length<1||e.length>s)throw TypeError(`text must be between 1 and ${s} characters`)}function F(e,t){if(!n.test(e))throw TypeError(`${t} must be a Slack ID`)}function I(t,n){if(e.test(t))throw TypeError(`${n} cannot contain Slack control characters`)}function L(e,n){if(t.test(e))throw TypeError(`${n} cannot contain Slack date control characters`)}function R(e){return L(e,`link`),e}export{b as a,h as c,M as d,x as f,g as i,_ as l,p as n,y as o,f as p,d as r,v as s,m as t,N as u};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{A as e,Ft as t,R as n,j as r}from"./dist-CO_n_hUa.js";import i from"crypto";import{lookup as a}from"dns/promises";import{request as o}from"https";import{BlockList as s,isIP as c}from"net";import{pipeline as l}from"stream";import{createBrotliDecompress as u,createGunzip as d,createInflate as f}from"zlib";function ee(e){return n(e)?e:typeof e==`object`&&e&&`card`in e?e.card:null}function te(e){return typeof e==`object`&&e&&`files`in e?e.files??[]:[]}function ne(e){return typeof e==`object`&&e&&`attachments`in e?e.attachments??[]:[]}var p=class extends Error{adapter;code;constructor(e,t,n){super(e),this.name=`AdapterError`,this.adapter=t,this.code=n}},m=class extends p{retryAfter;constructor(e,t){super(`Rate limited by ${e}${t?`, retry after ${t}s`:``}`,e,`RATE_LIMITED`),this.name=`AdapterRateLimitError`,this.retryAfter=t}},h=class extends p{constructor(e,t){super(t||`Authentication failed for ${e}`,e,`AUTH_FAILED`),this.name=`AuthenticationError`}},g=class extends p{constructor(e,t){super(t,e,`VALIDATION_ERROR`),this.name=`ValidationError`}},_=class extends p{originalError;constructor(e,t,n){super(t||`Network error communicating with ${e}`,e,`NETWORK_ERROR`),this.name=`NetworkError`,this.originalError=n}};async function v(e,t){let{platform:n,throwOnUnsupported:r=!0}=t;if(Buffer.isBuffer(e))return e;if(e instanceof ArrayBuffer)return Buffer.from(e);if(e instanceof Blob){let t=await e.arrayBuffer();return Buffer.from(t)}if(r)throw new g(n,`Unsupported file data type`);return null}var y={slack:{primary:`primary`,danger:`danger`},gchat:{primary:`primary`,danger:`danger`},teams:{primary:`positive`,danger:`destructive`},discord:{primary:`primary`,danger:`danger`}};function b(e){return t=>r(t,e)}function x(e,t){if(e)return y[t][e]}function re(e,t={}){let{boldFormat:n=`*`,lineBreak:r=`
|
|
2
|
+
`,platform:i}=t,a=i?b(i):e=>e,o=[];e.title&&o.push(`${n}${a(e.title)}${n}`),e.subtitle&&o.push(a(e.subtitle));for(let t of e.children){let e=S(t,a);e&&o.push(e)}return o.join(r)}function S(n,r){switch(n.type){case`text`:return r(n.content);case`link`:return`${r(n.label)} (${n.url})`;case`fields`:return n.children.map(e=>`${r(e.label)}: ${r(e.value)}`).join(`
|
|
3
|
+
`);case`actions`:return null;case`section`:return n.children.map(e=>S(e,r)).filter(Boolean).join(`
|
|
4
|
+
`);case`table`:return t(n.headers,n.rows);case`divider`:return`---`;case`text_input`:return r(n.label);default:return e(n)}}var C=`aes-256-gcm`,w=12,T=16,ie=/^[0-9a-fA-F]{64}$/;function ae(e,t){let n=i.randomBytes(w),r=i.createCipheriv(C,t,n,{authTagLength:T}),a=Buffer.concat([r.update(e,`utf8`),r.final()]),o=r.getAuthTag();return{iv:n.toString(`base64`),data:a.toString(`base64`),tag:o.toString(`base64`)}}function oe(e,t){let n=Buffer.from(e.iv,`base64`),r=Buffer.from(e.data,`base64`),a=Buffer.from(e.tag,`base64`),o=i.createDecipheriv(C,t,n,{authTagLength:T});return o.setAuthTag(a),Buffer.concat([o.update(r),o.final()]).toString(`utf8`)}function se(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.iv==`string`&&typeof t.data==`string`&&typeof t.tag==`string`}function ce(e){let t=e.trim(),n=ie.test(t),r=Buffer.from(t,n?`hex`:`base64`);if(r.length!==32)throw Error(`Encryption key must decode to exactly 32 bytes (received ${r.length}). Use a 64-char hex string or 44-char base64 string.`);return r}var E=26214400,le=5,D=3e4,O=new Set([301,302,303,307,308]),k=/^\[|\]$/g,A=[[`0.0.0.0`,8],[`10.0.0.0`,8],[`100.64.0.0`,10],[`127.0.0.0`,8],[`169.254.0.0`,16],[`172.16.0.0`,12],[`192.0.0.0`,24],[`192.0.2.0`,24],[`192.88.99.0`,24],[`192.168.0.0`,16],[`198.18.0.0`,15],[`198.51.100.0`,24],[`203.0.113.0`,24],[`224.0.0.0`,4],[`240.0.0.0`,4]],j=[[`::`,3],[`2001::`,23],[`2001:db8::`,32],[`2002::`,16],[`3fff::`,20],[`4000::`,2],[`8000::`,1]],M={br:u,deflate:f,gzip:d,"x-gzip":d};function N(e,t){let n=new s;for(let[r,i]of e)n.addSubnet(r,i,t);return n}var P=N(A,`ipv4`),F=N(j,`ipv6`);function I(e,t){return t!==4&&t!==6?!0:t===6?F.check(e,`ipv6`):P.check(e,`ipv4`)}function L(e){return new _(e,`Refusing to fetch an internal attachment URL`)}function R(e,t=a){return(n,r,i)=>{t(n,{...r,all:!0}).then(t=>{if(t.length===0){i(new _(e,`Could not resolve the attachment host`),``,0);return}if(t.some(({address:e,family:t})=>I(e,t))){i(L(e),``,0);return}if(r.all){i(null,t);return}let[n]=t;i(null,n.address,n.family)},e=>{i(e instanceof Error?e:Error(String(e)),``,0)})}}function z(e,t,n){let r=e instanceof URL?e:new URL(e),i=r.hostname.replace(k,``),a=c(i);if(a&&I(i,a))throw L(t);if(r.protocol!==`https:`||n&&!n.some(e=>{let t=e.toLowerCase();return i===t||i.endsWith(`.${t}`)}))throw new _(t,`Refusing to fetch an untrusted attachment URL`);return r}function B(e){let t=R(e);return(e,n,r)=>new Promise((i,a)=>{let s=o(e,{agent:!1,headers:r,lookup:t,signal:n},i);s.on(`error`,a),s.end()})}async function V(e,t,n=E,r){if(r?.aborted)throw e.destroy(),new _(t,`Timed out fetching the attachment`);let i=()=>e.destroy(ue(r));r?.addEventListener(`abort`,i,{once:!0});try{return await U(e,t,n)}finally{r?.removeEventListener(`abort`,i)}}function ue(e){let t=e?.reason;return t instanceof Error?t:Error(String(t))}function H(e,t,n){return new Promise((r,i)=>{let a=()=>i(new _(n,`Timed out fetching the attachment`));t.aborted?a():t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,a),t.aborted&&e.destroy(),r(e)},e=>{t.removeEventListener(`abort`,a),i(e)})})}async function U(e,t,n){let r=e.headers[`content-encoding`]?.trim().toLowerCase()||`identity`,i=r===`identity`?void 0:M[r];if(r!==`identity`&&!i)throw e.destroy(),new _(t,`Unsupported attachment encoding: ${r}`);let a=i?NaN:Number(e.headers[`content-length`]);if(Number.isFinite(a)&&a>n)throw e.destroy(),new _(t,`Attachment exceeds the download limit`);let o=i?l(e,i(),()=>void 0):e;if(Number.isFinite(a)){let n=Buffer.allocUnsafe(a),r=0;for await(let i of o){let o=Buffer.isBuffer(i)?i:Buffer.from(i);if(r+o.length>a)throw e.destroy(),new _(t,`Attachment body exceeds its declared length`);o.copy(n,r),r+=o.length}return r===a?n:n.subarray(0,r)}let s=[],c=0;for await(let r of o){let i=Buffer.isBuffer(r)?r:Buffer.from(r);if(c+=i.length,c>n)throw e.destroy(),new _(t,`Attachment exceeds the download limit`);s.push(i)}return Buffer.concat(s,c)}async function de(e,t){let{adapter:n,headers:r,hosts:i,limit:a=E,onResponse:o,redirects:s=le,timeoutMs:c=D,transport:l}=t,u=l??B(n),d=AbortSignal.timeout(c),f=z(e,n,i);try{for(let e=0;e<=s;e+=1){let t=await H(u(f,d,{"accept-encoding":`gzip, deflate, br`,"user-agent":`Vercel.ChatSDK`,...typeof r==`function`?r(f):r}),d,n),c=t.statusCode??0;if(O.has(c)){let r=t.headers.location;if(t.destroy(),!r)throw new _(n,`Attachment redirect has no location`);if(e===s)throw new _(n,`Too many attachment redirects`);f=z(new URL(r,f),n,i);continue}if(c<200||c>=300)throw t.destroy(),new _(n,`Failed to fetch file: ${c} ${t.statusMessage??``}`.trim());if(o)try{o(t)}catch(e){throw t.destroy(),e}return await V(t,n,a,d)}throw new _(n,`Too many attachment redirects`)}catch(e){throw d.aborted&&!(e instanceof _)?new _(n,`Timed out fetching the attachment`,e instanceof Error?e:void 0):e}}var W=`http://`,G=`https://`;function K(e){let t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function q(e){let t=e.charCodeAt(0);return t>=48&&t<=57}function J(e){return e!==void 0&&(K(e)||q(e)||e===`_`)}function Y(e){return K(e)||q(e)||e===`.`||e===`-`}function X(e){return e===`<`||e===`>`||e.trim()===``}function Z(e,t,n){return e.slice(t,t+n.length).toLowerCase()===n}function fe(e,t,n){let r=0;if(Z(e,t,G)?r=G.length:Z(e,t,W)&&(r=W.length),r===0||t+r>=n)return t;let i=t+r;for(;i<n&&!X(e[i]);)i+=1;return i}function pe(e,t,n){if(!(K(e[t])||q(e[t]))||t>0&&Y(e[t-1]))return t;let r=t;for(;r<n&&Y(e[r]);)r+=1;let i=e[r];if(i!==`/`&&i!==`?`&&i!==`#`)return t;let a=e.slice(t,r),o=a.lastIndexOf(`.`),s=a.slice(o+1);if(o<=0||s.length<2)return t;for(let e of s)if(!K(e))return t;for(r+=1;r<n&&!X(e[r]);)r+=1;return r}function Q(e,t,n){if(e[t]!=="`")return t;let r=e.startsWith("```",t),i=r?"```":"`",a=t+i.length,o=e.indexOf(i,a);if(o===-1||o>=n)return t;if(!r){let n=e.indexOf(`
|
|
5
|
+
`,a);if(n!==-1&&n<o)return t}return o+i.length}function $(e,t,n,r,i){let a=``,o=t;for(;o<n;){let t=Q(e,o,n);if(t>o){a+=e.slice(o,t),o=t;continue}if(i&&e[o]===`<`){let t=o+1;for(;t<n&&e[t]!==`>`&&e[t]!==`
|
|
6
|
+
`&&e[t]!==`\r`;)t+=1;if(e[t]===`>`){a+=e.slice(o,t+1),o=t+1;continue}a+=$(e,o,t,r,!1),o=t;continue}let s=fe(e,o,n);if(s>o){a+=e.slice(o,s),o=s;continue}let c=pe(e,o,n);if(c>o){a+=e.slice(o,c),o=c;continue}if(e[o]===`@`&&e[o-1]!==`<`&&!J(e[o-1])&&J(e[o+1])){let t=o+2;for(;t<n&&J(e[t]);)t+=1;let i=e.slice(o,t);a+=r(i,i.slice(1)),o=t;continue}a+=e[o],o+=1}return a}function me(e,t){return $(e,0,e.length,t,!0)}function he(e,t=` `){let n=``,r=0,i=e.length;for(;r<i;){let a=Q(e,r,i);if(a>r){n+=t,r=a;continue}n+=e[r],r+=1}return n}export{me as _,re as a,oe as c,ee as d,te as f,he as g,x as h,g as i,de as l,se as m,h as n,b as o,ne as p,_ as r,ce as s,m as t,ae as u,v};
|