Initial commit: Complete Hive distributed AI orchestration platform
This comprehensive implementation includes: - FastAPI backend with MCP server integration - React/TypeScript frontend with Vite - PostgreSQL database with Redis caching - Grafana/Prometheus monitoring stack - Docker Compose orchestration - Full MCP protocol support for Claude Code integration Features: - Agent discovery and management across network - Visual workflow editor and execution engine - Real-time task coordination and monitoring - Multi-model support with specialized agents - Distributed development task allocation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
596
mcp-server/node_modules/eventsource/src/EventSource.ts
generated
vendored
Normal file
596
mcp-server/node_modules/eventsource/src/EventSource.ts
generated
vendored
Normal file
@@ -0,0 +1,596 @@
|
||||
import {createParser, type EventSourceMessage, type EventSourceParser} from 'eventsource-parser'
|
||||
|
||||
import {ErrorEvent, flattenError, syntaxError} from './errors.js'
|
||||
import type {
|
||||
AddEventListenerOptions,
|
||||
EventListenerOptions,
|
||||
EventListenerOrEventListenerObject,
|
||||
EventSourceEventMap,
|
||||
EventSourceFetchInit,
|
||||
EventSourceInit,
|
||||
FetchLike,
|
||||
FetchLikeResponse,
|
||||
} from './types.js'
|
||||
|
||||
/**
|
||||
* An `EventSource` instance opens a persistent connection to an HTTP server, which sends events
|
||||
* in `text/event-stream` format. The connection remains open until closed by calling `.close()`.
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
* ```js
|
||||
* const eventSource = new EventSource('https://example.com/stream')
|
||||
* eventSource.addEventListener('error', (error) => {
|
||||
* console.error(error)
|
||||
* })
|
||||
* eventSource.addEventListener('message', (event) => {
|
||||
* console.log('Received message:', event.data)
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export class EventSource extends EventTarget {
|
||||
/**
|
||||
* ReadyState representing an EventSource currently trying to connect
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
static CONNECTING = 0 as const
|
||||
|
||||
/**
|
||||
* ReadyState representing an EventSource connection that is open (eg connected)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
static OPEN = 1 as const
|
||||
|
||||
/**
|
||||
* ReadyState representing an EventSource connection that is closed (eg disconnected)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
static CLOSED = 2 as const
|
||||
|
||||
/**
|
||||
* ReadyState representing an EventSource currently trying to connect
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
readonly CONNECTING = 0 as const
|
||||
|
||||
/**
|
||||
* ReadyState representing an EventSource connection that is open (eg connected)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
readonly OPEN = 1 as const
|
||||
|
||||
/**
|
||||
* ReadyState representing an EventSource connection that is closed (eg disconnected)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
readonly CLOSED = 2 as const
|
||||
|
||||
/**
|
||||
* Returns the state of this EventSource object's connection. It can have the values described below.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
|
||||
*
|
||||
* Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
|
||||
* defined in the TypeScript `dom` library.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
public get readyState(): number {
|
||||
return this.#readyState
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL providing the event stream.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
public get url(): string {
|
||||
return this.#url.href
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
|
||||
*/
|
||||
public get withCredentials(): boolean {
|
||||
return this.#withCredentials
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
|
||||
public get onerror(): ((ev: ErrorEvent) => unknown) | null {
|
||||
return this.#onError
|
||||
}
|
||||
public set onerror(value: ((ev: ErrorEvent) => unknown) | null) {
|
||||
this.#onError = value
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
|
||||
public get onmessage(): ((ev: MessageEvent) => unknown) | null {
|
||||
return this.#onMessage
|
||||
}
|
||||
public set onmessage(value: ((ev: MessageEvent) => unknown) | null) {
|
||||
this.#onMessage = value
|
||||
}
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
|
||||
public get onopen(): ((ev: Event) => unknown) | null {
|
||||
return this.#onOpen
|
||||
}
|
||||
public set onopen(value: ((ev: Event) => unknown) | null) {
|
||||
this.#onOpen = value
|
||||
}
|
||||
|
||||
override addEventListener<K extends keyof EventSourceEventMap>(
|
||||
type: K,
|
||||
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void
|
||||
override addEventListener(
|
||||
type: string,
|
||||
listener: (this: EventSource, event: MessageEvent) => unknown,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void
|
||||
override addEventListener(
|
||||
type: string,
|
||||
listener: EventListenerOrEventListenerObject,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void
|
||||
override addEventListener(
|
||||
type: string,
|
||||
listener:
|
||||
| ((this: EventSource, event: MessageEvent) => unknown)
|
||||
| EventListenerOrEventListenerObject,
|
||||
options?: boolean | AddEventListenerOptions,
|
||||
): void {
|
||||
const listen = listener as (this: EventSource, event: Event) => unknown
|
||||
super.addEventListener(type, listen, options)
|
||||
}
|
||||
|
||||
override removeEventListener<K extends keyof EventSourceEventMap>(
|
||||
type: K,
|
||||
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): void
|
||||
override removeEventListener(
|
||||
type: string,
|
||||
listener: (this: EventSource, event: MessageEvent) => unknown,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): void
|
||||
override removeEventListener(
|
||||
type: string,
|
||||
listener: EventListenerOrEventListenerObject,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): void
|
||||
override removeEventListener(
|
||||
type: string,
|
||||
listener:
|
||||
| ((this: EventSource, event: MessageEvent) => unknown)
|
||||
| EventListenerOrEventListenerObject,
|
||||
options?: boolean | EventListenerOptions,
|
||||
): void {
|
||||
const listen = listener as (this: EventSource, event: Event) => unknown
|
||||
super.removeEventListener(type, listen, options)
|
||||
}
|
||||
|
||||
constructor(url: string | URL, eventSourceInitDict?: EventSourceInit) {
|
||||
super()
|
||||
|
||||
try {
|
||||
if (url instanceof URL) {
|
||||
this.#url = url
|
||||
} else if (typeof url === 'string') {
|
||||
this.#url = new URL(url, getBaseURL())
|
||||
} else {
|
||||
throw new Error('Invalid URL')
|
||||
}
|
||||
} catch (err) {
|
||||
throw syntaxError('An invalid or illegal string was specified')
|
||||
}
|
||||
|
||||
this.#parser = createParser({
|
||||
onEvent: this.#onEvent,
|
||||
onRetry: this.#onRetryChange,
|
||||
})
|
||||
|
||||
this.#readyState = this.CONNECTING
|
||||
this.#reconnectInterval = 3000
|
||||
this.#fetch = eventSourceInitDict?.fetch ?? globalThis.fetch
|
||||
this.#withCredentials = eventSourceInitDict?.withCredentials ?? false
|
||||
|
||||
this.#connect()
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
close(): void {
|
||||
if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer)
|
||||
if (this.#readyState === this.CLOSED) return
|
||||
if (this.#controller) this.#controller.abort()
|
||||
this.#readyState = this.CLOSED
|
||||
this.#controller = undefined
|
||||
}
|
||||
|
||||
// PRIVATES FOLLOW
|
||||
|
||||
/**
|
||||
* Current connection state
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#readyState: number
|
||||
|
||||
/**
|
||||
* Original URL used to connect.
|
||||
*
|
||||
* Note that this will stay the same even after a redirect.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#url: URL
|
||||
|
||||
/**
|
||||
* The destination URL after a redirect. Is reset on reconnection.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#redirectUrl: URL | undefined
|
||||
|
||||
/**
|
||||
* Whether to include credentials in the request
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#withCredentials: boolean
|
||||
|
||||
/**
|
||||
* The fetch implementation to use
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#fetch: FetchLike
|
||||
|
||||
/**
|
||||
* The reconnection time in milliseconds
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#reconnectInterval: number
|
||||
|
||||
/**
|
||||
* Reference to an ongoing reconnect attempt, if any
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
/**
|
||||
* The last event ID seen by the EventSource, which will be sent as `Last-Event-ID` in the
|
||||
* request headers on a reconnection attempt.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#lastEventId: string | null = null
|
||||
|
||||
/**
|
||||
* The AbortController instance used to abort the fetch request
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#controller: AbortController | undefined
|
||||
|
||||
/**
|
||||
* Instance of an EventSource parser (`eventsource-parser` npm module)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#parser: EventSourceParser
|
||||
|
||||
/**
|
||||
* Holds the current error handler, attached through `onerror` property directly.
|
||||
* Note that `addEventListener('error', …)` will not be stored here.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#onError: ((ev: ErrorEvent) => unknown) | null = null
|
||||
|
||||
/**
|
||||
* Holds the current message handler, attached through `onmessage` property directly.
|
||||
* Note that `addEventListener('message', …)` will not be stored here.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#onMessage: ((ev: MessageEvent) => unknown) | null = null
|
||||
|
||||
/**
|
||||
* Holds the current open handler, attached through `onopen` property directly.
|
||||
* Note that `addEventListener('open', …)` will not be stored here.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#onOpen: ((ev: Event) => unknown) | null = null
|
||||
|
||||
/**
|
||||
* Connect to the given URL and start receiving events
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#connect() {
|
||||
this.#readyState = this.CONNECTING
|
||||
this.#controller = new AbortController()
|
||||
|
||||
// Browser tests are failing if we directly call `this.#fetch()`, thus the indirection.
|
||||
const fetch = this.#fetch
|
||||
fetch(this.#url, this.#getRequestOptions())
|
||||
.then(this.#onFetchResponse)
|
||||
.catch(this.#onFetchError)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the fetch response
|
||||
*
|
||||
* @param response - The Fetch(ish) response
|
||||
* @internal
|
||||
*/
|
||||
#onFetchResponse = async (response: FetchLikeResponse) => {
|
||||
this.#parser.reset()
|
||||
|
||||
const {body, redirected, status, headers} = response
|
||||
|
||||
// [spec] a client can be told to stop reconnecting using the HTTP 204 No Content response code.
|
||||
if (status === 204) {
|
||||
// We still need to emit an error event - this mirrors the browser behavior,
|
||||
// and without it there is no way to tell the user that the connection was closed.
|
||||
this.#failConnection('Server sent HTTP 204, not reconnecting', 204)
|
||||
this.close()
|
||||
return
|
||||
}
|
||||
|
||||
// [spec] …Event stream requests can be redirected using HTTP 301 and 307 redirects as with
|
||||
// [spec] normal HTTP requests.
|
||||
// Spec does not say anything about other redirect codes (302, 308), but this seems an
|
||||
// unintended omission, rather than a feature. Browsers will happily redirect on other 3xxs's.
|
||||
if (redirected) {
|
||||
this.#redirectUrl = new URL(response.url)
|
||||
} else {
|
||||
this.#redirectUrl = undefined
|
||||
}
|
||||
|
||||
// [spec] if res's status is not 200, …, then fail the connection.
|
||||
if (status !== 200) {
|
||||
this.#failConnection(`Non-200 status code (${status})`, status)
|
||||
return
|
||||
}
|
||||
|
||||
// [spec] …or if res's `Content-Type` is not `text/event-stream`, then fail the connection.
|
||||
const contentType = headers.get('content-type') || ''
|
||||
if (!contentType.startsWith('text/event-stream')) {
|
||||
this.#failConnection('Invalid content type, expected "text/event-stream"', status)
|
||||
return
|
||||
}
|
||||
|
||||
// [spec] …if the readyState attribute is set to a value other than CLOSED…
|
||||
if (this.#readyState === this.CLOSED) {
|
||||
return
|
||||
}
|
||||
|
||||
// [spec] …sets the readyState attribute to OPEN and fires an event
|
||||
// [spec] …named open at the EventSource object.
|
||||
this.#readyState = this.OPEN
|
||||
|
||||
const openEvent = new Event('open')
|
||||
this.#onOpen?.(openEvent)
|
||||
this.dispatchEvent(openEvent)
|
||||
|
||||
// Ensure that the response stream is a web stream
|
||||
if (typeof body !== 'object' || !body || !('getReader' in body)) {
|
||||
this.#failConnection('Invalid response body, expected a web ReadableStream', status)
|
||||
this.close() // This should only happen if `fetch` provided is "faulty" - don't reconnect
|
||||
return
|
||||
}
|
||||
|
||||
const decoder = new TextDecoder()
|
||||
|
||||
const reader = body.getReader()
|
||||
let open = true
|
||||
|
||||
do {
|
||||
const {done, value} = await reader.read()
|
||||
if (value) {
|
||||
this.#parser.feed(decoder.decode(value, {stream: !done}))
|
||||
}
|
||||
|
||||
if (!done) {
|
||||
continue
|
||||
}
|
||||
|
||||
open = false
|
||||
this.#parser.reset()
|
||||
|
||||
this.#scheduleReconnect()
|
||||
} while (open)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles rejected requests for the EventSource endpoint
|
||||
*
|
||||
* @param err - The error from `fetch()`
|
||||
* @internal
|
||||
*/
|
||||
#onFetchError = (err: Error & {type?: string}) => {
|
||||
this.#controller = undefined
|
||||
|
||||
// We expect abort errors when the user manually calls `close()` - ignore those
|
||||
if (err.name === 'AbortError' || err.type === 'aborted') {
|
||||
return
|
||||
}
|
||||
|
||||
this.#scheduleReconnect(flattenError(err))
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request options for the `fetch()` request
|
||||
*
|
||||
* @returns The request options
|
||||
* @internal
|
||||
*/
|
||||
#getRequestOptions(): EventSourceFetchInit {
|
||||
const lastEvent = this.#lastEventId ? {'Last-Event-ID': this.#lastEventId} : undefined
|
||||
|
||||
const init: EventSourceFetchInit = {
|
||||
// [spec] Let `corsAttributeState` be `Anonymous`…
|
||||
// [spec] …will have their mode set to "cors"…
|
||||
mode: 'cors',
|
||||
redirect: 'follow',
|
||||
headers: {Accept: 'text/event-stream', ...lastEvent},
|
||||
cache: 'no-store',
|
||||
signal: this.#controller?.signal,
|
||||
}
|
||||
|
||||
// Some environments crash if attempting to set `credentials` where it is not supported,
|
||||
// eg on Cloudflare Workers. To avoid this, we only set it in browser-like environments.
|
||||
if ('window' in globalThis) {
|
||||
// [spec] …and their credentials mode set to "same-origin"
|
||||
// [spec] …if the `withCredentials` attribute is `true`, set the credentials mode to "include"…
|
||||
init.credentials = this.withCredentials ? 'include' : 'same-origin'
|
||||
}
|
||||
|
||||
return init
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by EventSourceParser instance when an event has successfully been parsed
|
||||
* and is ready to be processed.
|
||||
*
|
||||
* @param event - The parsed event
|
||||
* @internal
|
||||
*/
|
||||
#onEvent = (event: EventSourceMessage) => {
|
||||
if (typeof event.id === 'string') {
|
||||
this.#lastEventId = event.id
|
||||
}
|
||||
|
||||
const messageEvent = new MessageEvent(event.event || 'message', {
|
||||
data: event.data,
|
||||
origin: this.#redirectUrl ? this.#redirectUrl.origin : this.#url.origin,
|
||||
lastEventId: event.id || '',
|
||||
})
|
||||
|
||||
// The `onmessage` property of the EventSource instance only triggers on messages without an
|
||||
// `event` field, or ones that explicitly set `message`.
|
||||
if (this.#onMessage && (!event.event || event.event === 'message')) {
|
||||
this.#onMessage(messageEvent)
|
||||
}
|
||||
|
||||
this.dispatchEvent(messageEvent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by EventSourceParser instance when a new reconnection interval is received
|
||||
* from the EventSource endpoint.
|
||||
*
|
||||
* @param value - The new reconnection interval in milliseconds
|
||||
* @internal
|
||||
*/
|
||||
#onRetryChange = (value: number) => {
|
||||
this.#reconnectInterval = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the process referred to in the EventSource specification as "failing a connection".
|
||||
*
|
||||
* @param error - The error causing the connection to fail
|
||||
* @param code - The HTTP status code, if available
|
||||
* @internal
|
||||
*/
|
||||
#failConnection(message?: string, code?: number) {
|
||||
// [spec] …if the readyState attribute is set to a value other than CLOSED,
|
||||
// [spec] sets the readyState attribute to CLOSED…
|
||||
if (this.#readyState !== this.CLOSED) {
|
||||
this.#readyState = this.CLOSED
|
||||
}
|
||||
|
||||
// [spec] …and fires an event named `error` at the `EventSource` object.
|
||||
// [spec] Once the user agent has failed the connection, it does not attempt to reconnect.
|
||||
// [spec] > Implementations are especially encouraged to report detailed information
|
||||
// [spec] > to their development consoles whenever an error event is fired, since little
|
||||
// [spec] > to no information can be made available in the events themselves.
|
||||
// Printing to console is not very programatically helpful, though, so we emit a custom event.
|
||||
const errorEvent = new ErrorEvent('error', {code, message})
|
||||
|
||||
this.#onError?.(errorEvent)
|
||||
this.dispatchEvent(errorEvent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a reconnection attempt against the EventSource endpoint.
|
||||
*
|
||||
* @param message - The error causing the connection to fail
|
||||
* @param code - The HTTP status code, if available
|
||||
* @internal
|
||||
*/
|
||||
#scheduleReconnect(message?: string, code?: number) {
|
||||
// [spec] If the readyState attribute is set to CLOSED, abort the task.
|
||||
if (this.#readyState === this.CLOSED) {
|
||||
return
|
||||
}
|
||||
|
||||
// [spec] Set the readyState attribute to CONNECTING.
|
||||
this.#readyState = this.CONNECTING
|
||||
|
||||
// [spec] Fire an event named `error` at the EventSource object.
|
||||
const errorEvent = new ErrorEvent('error', {code, message})
|
||||
this.#onError?.(errorEvent)
|
||||
this.dispatchEvent(errorEvent)
|
||||
|
||||
// [spec] Wait a delay equal to the reconnection time of the event source.
|
||||
this.#reconnectTimer = setTimeout(this.#reconnect, this.#reconnectInterval)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnects to the EventSource endpoint after a disconnect/failure
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#reconnect = () => {
|
||||
this.#reconnectTimer = undefined
|
||||
|
||||
// [spec] If the EventSource's readyState attribute is not set to CONNECTING, then return.
|
||||
if (this.#readyState !== this.CONNECTING) {
|
||||
return
|
||||
}
|
||||
|
||||
this.#connect()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* According to spec, when constructing a URL:
|
||||
* > 1. Let baseURL be environment's base URL, if environment is a Document object
|
||||
* > 2. Return the result of applying the URL parser to url, with baseURL.
|
||||
*
|
||||
* Thus we should use `document.baseURI` if available, since it can be set through a base tag.
|
||||
*
|
||||
* @returns The base URL, if available - otherwise `undefined`
|
||||
* @internal
|
||||
*/
|
||||
function getBaseURL(): string | undefined {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const doc = 'document' in globalThis ? (globalThis as any).document : undefined
|
||||
return doc && typeof doc === 'object' && 'baseURI' in doc && typeof doc.baseURI === 'string'
|
||||
? doc.baseURI
|
||||
: undefined
|
||||
}
|
||||
141
mcp-server/node_modules/eventsource/src/errors.ts
generated
vendored
Normal file
141
mcp-server/node_modules/eventsource/src/errors.ts
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* An extended version of the `Event` emitted by the `EventSource` object when an error occurs.
|
||||
* While the spec does not include any additional properties, we intentionally go beyond the spec
|
||||
* and provide some (minimal) additional information to aid in debugging.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class ErrorEvent extends Event {
|
||||
/**
|
||||
* HTTP status code, if this was triggered by an HTTP error
|
||||
* Note: this is not part of the spec, but is included for better error handling.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
public code?: number | undefined
|
||||
|
||||
/**
|
||||
* Optional message attached to the error.
|
||||
* Note: this is not part of the spec, but is included for better error handling.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
public message?: string | undefined
|
||||
|
||||
/**
|
||||
* Constructs a new `ErrorEvent` instance. This is typically not called directly,
|
||||
* but rather emitted by the `EventSource` object when an error occurs.
|
||||
*
|
||||
* @param type - The type of the event (should be "error")
|
||||
* @param errorEventInitDict - Optional properties to include in the error event
|
||||
*/
|
||||
constructor(
|
||||
type: string,
|
||||
errorEventInitDict?: {message?: string | undefined; code?: number | undefined},
|
||||
) {
|
||||
super(type)
|
||||
this.code = errorEventInitDict?.code ?? undefined
|
||||
this.message = errorEventInitDict?.message ?? undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
||||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
||||
* we explicitly include the properties in the `inspect` method.
|
||||
*
|
||||
* This is automatically called by Node.js when you `console.log` an instance of this class.
|
||||
*
|
||||
* @param _depth - The current depth
|
||||
* @param options - The options passed to `util.inspect`
|
||||
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
||||
* @returns A string representation of the error
|
||||
*/
|
||||
[Symbol.for('nodejs.util.inspect.custom')](
|
||||
_depth: number,
|
||||
options: {colors: boolean},
|
||||
inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,
|
||||
): string {
|
||||
return inspect(inspectableError(this), options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
||||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
||||
* we explicitly include the properties in the `inspect` method.
|
||||
*
|
||||
* This is automatically called by Deno when you `console.log` an instance of this class.
|
||||
*
|
||||
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
||||
* @param options - The options passed to `Deno.inspect`
|
||||
* @returns A string representation of the error
|
||||
*/
|
||||
[Symbol.for('Deno.customInspect')](
|
||||
inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string,
|
||||
options: {colors: boolean},
|
||||
): string {
|
||||
return inspect(inspectableError(this), options)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For environments where DOMException may not exist, we will use a SyntaxError instead.
|
||||
* While this isn't strictly according to spec, it is very close.
|
||||
*
|
||||
* @param message - The message to include in the error
|
||||
* @returns A `DOMException` or `SyntaxError` instance
|
||||
* @internal
|
||||
*/
|
||||
export function syntaxError(message: string): SyntaxError {
|
||||
// If someone can figure out a way to make this work without depending on DOM/Node.js typings,
|
||||
// and without casting to `any`, please send a PR 🙏
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const DomException = (globalThis as any).DOMException
|
||||
if (typeof DomException === 'function') {
|
||||
return new DomException(message, 'SyntaxError')
|
||||
}
|
||||
|
||||
return new SyntaxError(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an error into a single error message string.
|
||||
* Unwraps nested errors and joins them with a comma.
|
||||
*
|
||||
* @param err - The error to flatten
|
||||
* @returns A string representation of the error
|
||||
* @internal
|
||||
*/
|
||||
export function flattenError(err: unknown): string {
|
||||
if (!(err instanceof Error)) {
|
||||
return `${err}`
|
||||
}
|
||||
|
||||
if ('errors' in err && Array.isArray(err.errors)) {
|
||||
return err.errors.map(flattenError).join(', ')
|
||||
}
|
||||
|
||||
if ('cause' in err && err.cause instanceof Error) {
|
||||
return `${err}: ${flattenError(err.cause)}`
|
||||
}
|
||||
|
||||
return err.message
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an `ErrorEvent` instance into a plain object for inspection.
|
||||
*
|
||||
* @param err - The `ErrorEvent` instance to inspect
|
||||
* @returns A plain object representation of the error
|
||||
* @internal
|
||||
*/
|
||||
function inspectableError(err: ErrorEvent) {
|
||||
return {
|
||||
type: err.type,
|
||||
message: err.message,
|
||||
code: err.code,
|
||||
defaultPrevented: err.defaultPrevented,
|
||||
cancelable: err.cancelable,
|
||||
timeStamp: err.timeStamp,
|
||||
}
|
||||
}
|
||||
3
mcp-server/node_modules/eventsource/src/index.ts
generated
vendored
Normal file
3
mcp-server/node_modules/eventsource/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export {ErrorEvent} from './errors.js'
|
||||
export {EventSource} from './EventSource.js'
|
||||
export type * from './types.js'
|
||||
152
mcp-server/node_modules/eventsource/src/types.ts
generated
vendored
Normal file
152
mcp-server/node_modules/eventsource/src/types.ts
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
import type {ErrorEvent} from './errors.js'
|
||||
|
||||
/**
|
||||
* Stripped down version of `fetch()`, only defining the parts we care about.
|
||||
* This ensures it should work with "most" fetch implementations.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type FetchLike = (
|
||||
url: string | URL,
|
||||
init: EventSourceFetchInit,
|
||||
) => Promise<FetchLikeResponse>
|
||||
|
||||
/**
|
||||
* Subset of `RequestInit` used for `fetch()` calls made by the `EventSource` class.
|
||||
* As we know that we will be passing certain values, we can be more specific and have
|
||||
* users not have to do optional chaining and similar for things that will always be there.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventSourceFetchInit {
|
||||
/** An AbortSignal to set request's signal. Typed as `any` because of polyfill inconsistencies. */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
signal: {aborted: boolean} | any
|
||||
|
||||
/** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
|
||||
headers: {
|
||||
[key: string]: string
|
||||
Accept: 'text/event-stream'
|
||||
}
|
||||
|
||||
/** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
|
||||
mode: 'cors' | 'no-cors' | 'same-origin'
|
||||
|
||||
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
|
||||
credentials?: 'include' | 'omit' | 'same-origin'
|
||||
|
||||
/** Controls how the request is cached. */
|
||||
cache: 'no-store'
|
||||
|
||||
/** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
|
||||
redirect: 'error' | 'follow' | 'manual'
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated Use `EventSourceFetchInit` instead.
|
||||
* This type is only here for backwards compatibility and will be removed in a future version.
|
||||
*/
|
||||
export type FetchLikeInit = EventSourceFetchInit
|
||||
|
||||
/**
|
||||
* Stripped down version of `ReadableStreamDefaultReader`, only defining the parts we care about.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ReaderLike {
|
||||
read(): Promise<{done: false; value: unknown} | {done: true; value?: undefined}>
|
||||
cancel(): Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal version of the `Response` type returned by `fetch()`.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface FetchLikeResponse {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
readonly body: {getReader(): ReaderLike} | Response['body'] | null
|
||||
readonly url: string
|
||||
readonly status: number
|
||||
readonly redirected: boolean
|
||||
readonly headers: {get(name: string): string | null}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings, with the exception of the extended ErrorEvent.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventSourceEventMap {
|
||||
error: ErrorEvent
|
||||
message: MessageEvent
|
||||
open: Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings (for the most part)
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventSourceInit {
|
||||
/**
|
||||
* A boolean value, defaulting to `false`, indicating if CORS should be set to `include` credentials.
|
||||
*/
|
||||
withCredentials?: boolean
|
||||
|
||||
/**
|
||||
* Optional fetch implementation to use. Defaults to `globalThis.fetch`.
|
||||
* Can also be used for advanced use cases like mocking, proxying, custom certs etc.
|
||||
*/
|
||||
fetch?: FetchLike
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings (sorta).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventListenerOptions {
|
||||
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */
|
||||
capture?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings (sorta).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface AddEventListenerOptions extends EventListenerOptions {
|
||||
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
|
||||
once?: boolean
|
||||
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
|
||||
passive?: boolean
|
||||
/** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type EventListenerOrEventListenerObject = EventListener | EventListenerObject
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventListener {
|
||||
(evt: Event | MessageEvent): void
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the official DOM typings.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EventListenerObject {
|
||||
handleEvent(object: Event): void
|
||||
}
|
||||
Reference in New Issue
Block a user