@llmnative/react 2.4.0 → 3.0.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/README.md +3 -2
- package/dist/index.js +20 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6570 -6733
- package/dist/index.mjs.map +1 -1
- package/dist/modelIdentity-CIXNPtTA.mjs +624 -0
- package/dist/modelIdentity-CIXNPtTA.mjs.map +1 -0
- package/dist/modelIdentity-DX62i7g2.js +3 -0
- package/dist/modelIdentity-DX62i7g2.js.map +1 -0
- package/dist/server-B430eH0y.mjs +352 -0
- package/dist/server-B430eH0y.mjs.map +1 -0
- package/dist/server-CDheNgME.js +2 -0
- package/dist/server-CDheNgME.js.map +1 -0
- package/dist/server.js +1 -1
- package/dist/server.mjs +3 -3
- package/dist/types/src/App.d.ts +6 -4
- package/dist/types/src/index.d.ts +16 -7
- package/dist/types/src/libs/index.d.ts +0 -1
- package/dist/types/src/providers/ProviderRegistryContext.d.ts +7 -5
- package/dist/types/src/providers/ai/server.d.ts +20 -0
- package/dist/types/src/providers/api/ApiProvider.d.ts +1 -1
- package/dist/types/src/providers/email/EmailError.d.ts +27 -0
- package/dist/types/src/providers/email/EmailProviderContext.d.ts +13 -7
- package/dist/types/src/providers/email/EmailRead.d.ts +48 -0
- package/dist/types/src/providers/email/EmailSend.d.ts +54 -0
- package/dist/types/src/providers/email/brevo/BrevoEmailSender.d.ts +21 -0
- package/dist/types/src/providers/email/definitions.d.ts +4 -2
- package/dist/types/src/providers/email/gmail/GmailEmailReader.d.ts +37 -0
- package/dist/types/src/providers/email/gmail/GmailEmailSender.d.ts +21 -0
- package/dist/types/src/providers/email/gmail/browser.d.ts +10 -0
- package/dist/types/src/providers/email/gmail/gmailApi.d.ts +53 -0
- package/dist/types/src/providers/email/gmail/gmailOAuth.d.ts +25 -0
- package/dist/types/src/providers/email/imap/ImapEmailReader.d.ts +70 -0
- package/dist/types/src/providers/email/resend/ResendEmailSender.d.ts +20 -0
- package/dist/types/src/providers/manifest.d.ts +7 -5
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/llms-full.txt +1690 -1657
- package/llms.txt +83 -82
- package/package.json +18 -1
- package/dist/modelIdentity-CGWliGDU.mjs +0 -183
- package/dist/modelIdentity-CGWliGDU.mjs.map +0 -1
- package/dist/modelIdentity-CgRMrC5H.js +0 -2
- package/dist/modelIdentity-CgRMrC5H.js.map +0 -1
- package/dist/server-CCbjPJEz.js +0 -2
- package/dist/server-CCbjPJEz.js.map +0 -1
- package/dist/server-CiWwr3Zg.mjs +0 -107
- package/dist/server-CiWwr3Zg.mjs.map +0 -1
- package/dist/types/src/libs/email.d.ts +0 -16
- package/dist/types/src/providers/email/EmailProvider.d.ts +0 -10
- package/dist/types/src/providers/email/google/GmailEmailProvider.d.ts +0 -7
- package/dist/types/src/providers/email/google/email.d.ts +0 -13
|
@@ -3,7 +3,7 @@ export { default as App, AppProvider } from './App';
|
|
|
3
3
|
export { useMenu } from './App';
|
|
4
4
|
export type { AppProps, AppProviderProps, AppProvidersConfig, MenuConfig } from './App';
|
|
5
5
|
export type { AIConfig, FirebaseConfig } from './Config';
|
|
6
|
-
export type { ServicesConfig, SupabaseProviderConfig, GoogleProviderConfig, MockProviderConfig, DataDriverName, StorageDriverName, AuthDriverName,
|
|
6
|
+
export type { ServicesConfig, SupabaseProviderConfig, GoogleProviderConfig, MockProviderConfig, DataDriverName, StorageDriverName, AuthDriverName, EmailSendDriverName, AIDriverName, } from './providers/manifest';
|
|
7
7
|
export type { ProxyConfig, GitHubAuthConfig } from './Config';
|
|
8
8
|
export { Head, HeadProvider, DEFAULT_DOCUMENT_HEAD, DEFAULT_HEAD_APP_NAME, DEFAULT_LANGUAGE_HEAD, useAssetsHead, useDocumentHead, useHead, useHeadLinks, useLanguageHead, usePaginationHead, usePwaHead, useSchemaOrgHead, useSocialHead, } from './Head';
|
|
9
9
|
export type { HeadController, AssetsHeadState, DocumentBaseHead, DocumentHeadState, DocumentHttpEquivMeta, HeadFontAsset, HeadLinkDescriptor, HeadLinksState, HeadMetaAttributes, HeadProviderProps, HeadScriptAsset, HeadStyleAsset, LanguageAlternateLink, LanguageHeadState, OpenGraphHeadState, PageMetadataState, PaginationHeadState, PwaIconLink, PwaHeadState, SchemaOrgHeadState, SchemaOrgJson, SocialHeadState, TwitterHeadState, } from './Head';
|
|
@@ -71,9 +71,20 @@ export type { GitHubSessionProfile } from './providers/auth/github/GitHubAuthPro
|
|
|
71
71
|
export type { CredentialsAdapter } from './providers/credentials/CredentialsProvider';
|
|
72
72
|
export { useCredentialsProvider } from './providers/credentials/CredentialsProviderContext';
|
|
73
73
|
export { GoogleServiceAccountProvider } from './providers/credentials/google/GoogleServiceAccountProvider';
|
|
74
|
-
export type {
|
|
75
|
-
export type {
|
|
76
|
-
export {
|
|
74
|
+
export type { EmailSendAdapter, EmailSendParams, EmailSendResult, EmailAddress, EmailRecipient } from './providers/email/EmailSend';
|
|
75
|
+
export type { EmailReadAdapter, EmailMessage, EmailReadStart, EmailReadBatch, EmailReadOptions } from './providers/email/EmailRead';
|
|
76
|
+
export { EmailProviderError } from './providers/email/EmailError';
|
|
77
|
+
export type { EmailProviderErrorCode } from './providers/email/EmailError';
|
|
78
|
+
export type { EmailSendProviderId, EmailReadProviderId } from './providers/email/definitions';
|
|
79
|
+
export { EMAIL_SEND_PROVIDER_DEFINITIONS, EMAIL_READ_PROVIDER_DEFINITIONS } from './providers/email/definitions';
|
|
80
|
+
export { ResendEmailSender } from './providers/email/resend/ResendEmailSender';
|
|
81
|
+
export type { ResendEmailSenderConfig } from './providers/email/resend/ResendEmailSender';
|
|
82
|
+
export { BrevoEmailSender } from './providers/email/brevo/BrevoEmailSender';
|
|
83
|
+
export type { BrevoEmailSenderConfig } from './providers/email/brevo/BrevoEmailSender';
|
|
84
|
+
export { GmailEmailSender } from './providers/email/gmail/GmailEmailSender';
|
|
85
|
+
export type { GmailEmailSenderConfig } from './providers/email/gmail/GmailEmailSender';
|
|
86
|
+
export { GMAIL_SCOPES } from './providers/email/gmail/gmailApi';
|
|
87
|
+
export type { GmailAuth } from './providers/email/gmail/gmailApi';
|
|
77
88
|
export type { BuildManifest, BuildArtifacts, DeployOptions, DeployResult, Deployment, PublishProviderAdapter } from './providers/publish/PublishProvider';
|
|
78
89
|
export type { PublishProviderId } from './providers/publish/definitions';
|
|
79
90
|
export { PUBLISH_PROVIDER_DEFINITIONS } from './providers/publish/definitions';
|
|
@@ -86,15 +97,13 @@ export type { AppIconProviderConfig, IconController } from './providers/icon/Ico
|
|
|
86
97
|
export { GoogleMapsProvider, useGoogleMapsConfig } from './providers/googleMaps/GoogleMapsProviderContext';
|
|
87
98
|
export { loadGoogleMaps } from './providers/googleMaps/loadGoogleMaps';
|
|
88
99
|
export type { GoogleMapsConfig } from './providers/googleMaps/loadGoogleMaps';
|
|
89
|
-
export {
|
|
90
|
-
export { GmailEmailProvider } from './providers/email/google/GmailEmailProvider';
|
|
100
|
+
export { useEmailSendProvider, useEmailReadProvider, EmailSendProvider, EmailReadProvider } from './providers/email/EmailProviderContext';
|
|
91
101
|
export type { AIRequestOptions, AIReasoningLevel, AIAttachment, AIProviderAdapter, AIKeyValidationResult, AIModelDescriptor, AIModelPricing, DiscoveredAIModel, AIProviderCapabilities, AIModelCatalog, AIProviderDefinition, AICompleteRequest, AICompleteResult, AIConversationTurn, AIToolDefinition, AIToolCall, AIToolResult, CloudflareProviderOptions, ServerAIProviderConnection, ServerAIConnection, ModelIdentity, ModelIdentityEntry, ModelIdentityIndex, ResolvedModel, ModelOffer, ModelCost, } from './providers/ai';
|
|
92
102
|
export { createAIProviderRegistry, getAIModelCatalog, formatAIModelRef, parseAIModelRef, isFreeAIModel, AI_PROVIDER_DEFINITIONS, AI_PROVIDER_DESCRIPTORS, OPENAI_COMPATIBLE_PROVIDER_DESCRIPTOR, CLOUDFLARE_PROVIDER_DESCRIPTOR, createCloudflareProviderDefinition, toProviderDescriptor, createServerCredentialAIRegistry, serverCredential, SERVER_CREDENTIAL_PREFIX, AI_PROVIDER_HOSTS, isAIProviderTarget, canonicalModelName, buildModelIdentityIndex, resolveModel, modelOffers, loadModelIdentityIndex } from './providers/ai';
|
|
93
103
|
export type { ProviderDescriptor, ProviderCredentialField } from './providers/ProviderDescriptor';
|
|
94
104
|
export { useAIProvider, useAIProviderRegistry, AIProvider } from './providers/ai/AIProviderContext';
|
|
95
105
|
export { proxyFetch, useProxy, configureProxy, isProxyEnabled } from './providers/proxy';
|
|
96
106
|
export { googleGetAccessToken } from './providers/auth/google/GoogleAuth';
|
|
97
|
-
export { sendEmail } from './providers/email/google/email';
|
|
98
107
|
export { getKeywordIdeas } from './providers/seo/google/keyword';
|
|
99
108
|
export { getGoogleTrendsData, getGoogleTrendsRelated } from './providers/seo/google/trend';
|
|
100
109
|
export { dropBox, useDropBoxConnect, DropBoxConnectButton } from './providers/storage/dropbox';
|
|
@@ -2,18 +2,20 @@ import React from 'react';
|
|
|
2
2
|
import type { DataProviderAdapter } from './data/DataProvider';
|
|
3
3
|
import type { StorageProviderAdapter } from './storage/StorageProvider';
|
|
4
4
|
import type { AuthProviderAdapter } from './auth/AuthProvider';
|
|
5
|
-
import type {
|
|
5
|
+
import type { EmailSendAdapter } from './email/EmailSend';
|
|
6
|
+
import type { EmailReadAdapter } from './email/EmailRead';
|
|
6
7
|
import type { AIProviderAdapter } from './ai/AIProvider';
|
|
7
8
|
import type { CredentialsAdapter } from './credentials/CredentialsProvider';
|
|
8
9
|
export type ProviderAdapterMap = {
|
|
9
10
|
data: DataProviderAdapter;
|
|
10
11
|
storage: StorageProviderAdapter;
|
|
11
12
|
auth: AuthProviderAdapter;
|
|
12
|
-
|
|
13
|
+
emailSend: EmailSendAdapter;
|
|
14
|
+
emailRead: EmailReadAdapter;
|
|
13
15
|
ai: AIProviderAdapter;
|
|
14
16
|
credentials: CredentialsAdapter;
|
|
15
17
|
};
|
|
16
|
-
/** The
|
|
18
|
+
/** The 7 categories the framework ships out of the box. Any other string is a valid category too — see customCategories on <App>. */
|
|
17
19
|
export type ProviderService = keyof ProviderAdapterMap;
|
|
18
20
|
export type ProviderRegistrySnapshot = Record<string, {
|
|
19
21
|
registry: Record<string, unknown>;
|
|
@@ -21,7 +23,7 @@ export type ProviderRegistrySnapshot = Record<string, {
|
|
|
21
23
|
}>;
|
|
22
24
|
/**
|
|
23
25
|
* Replaces a single named adapter in a provider registry at runtime, in ANY
|
|
24
|
-
* category — one of the
|
|
26
|
+
* category — one of the 7 built-in ones (typed) or an arbitrary custom one a
|
|
25
27
|
* vertical registered (string). Calls the previous adapter's dispose() (if
|
|
26
28
|
* defined) only when the instance changes, then propagates the new registry to every
|
|
27
29
|
* useXProvider()/useProvider() consumer. If `category` didn't exist yet, it's
|
|
@@ -43,7 +45,7 @@ export declare const ProviderRegistryProvider: ({ registries, setProvider, child
|
|
|
43
45
|
export declare const useSetProvider: () => SetProviderFn;
|
|
44
46
|
/**
|
|
45
47
|
* Generic read access to any provider category — built-in or custom. Prefer the
|
|
46
|
-
* typed useDataProvider()/useStorageProvider()/... for the
|
|
48
|
+
* typed useDataProvider()/useStorageProvider()/... for the 7 built-ins; reach for
|
|
47
49
|
* this when consuming a category the framework doesn't know about (registered via
|
|
48
50
|
* providers.customCategories or a runtime setProvider() call).
|
|
49
51
|
*/
|
|
@@ -33,3 +33,23 @@ export type ServerCredentialResolution = {
|
|
|
33
33
|
* placeholder can never carry a key elsewhere. A request without placeholders passes unchanged.
|
|
34
34
|
*/
|
|
35
35
|
export declare function resolveServerCredentials(request: ServerCredentialRequest, lookup: ServerCredentialLookup): Promise<ServerCredentialResolution>;
|
|
36
|
+
export { EmailProviderError } from '../email/EmailError';
|
|
37
|
+
export type { EmailProviderErrorCode } from '../email/EmailError';
|
|
38
|
+
export type { EmailSendAdapter, EmailSendParams, EmailSendResult, EmailAddress, EmailRecipient } from '../email/EmailSend';
|
|
39
|
+
export type { EmailReadAdapter, EmailMessage, EmailReadStart, EmailReadBatch, EmailReadOptions } from '../email/EmailRead';
|
|
40
|
+
export { EMAIL_SEND_PROVIDER_DEFINITIONS, EMAIL_READ_PROVIDER_DEFINITIONS } from '../email/definitions';
|
|
41
|
+
export type { EmailSendProviderId, EmailReadProviderId } from '../email/definitions';
|
|
42
|
+
export { ResendEmailSender } from '../email/resend/ResendEmailSender';
|
|
43
|
+
export type { ResendEmailSenderConfig } from '../email/resend/ResendEmailSender';
|
|
44
|
+
export { BrevoEmailSender } from '../email/brevo/BrevoEmailSender';
|
|
45
|
+
export type { BrevoEmailSenderConfig } from '../email/brevo/BrevoEmailSender';
|
|
46
|
+
export { GmailEmailSender } from '../email/gmail/GmailEmailSender';
|
|
47
|
+
export type { GmailEmailSenderConfig } from '../email/gmail/GmailEmailSender';
|
|
48
|
+
export { GmailEmailReader, decodeGmailPushNotification } from '../email/gmail/GmailEmailReader';
|
|
49
|
+
export type { GmailEmailReaderConfig } from '../email/gmail/GmailEmailReader';
|
|
50
|
+
export { createGmailOAuth } from '../email/gmail/gmailOAuth';
|
|
51
|
+
export type { GmailOAuth, GmailOAuthConfig } from '../email/gmail/gmailOAuth';
|
|
52
|
+
export { GMAIL_SCOPES } from '../email/gmail/gmailApi';
|
|
53
|
+
export type { GmailAuth } from '../email/gmail/gmailApi';
|
|
54
|
+
export { ImapEmailReader } from '../email/imap/ImapEmailReader';
|
|
55
|
+
export type { ImapEmailReaderConfig, ImapModules } from '../email/imap/ImapEmailReader';
|
|
@@ -15,7 +15,7 @@ import type { ProviderConfigurable } from '../ProviderConfiguration';
|
|
|
15
15
|
* Registered/fixed fields always win over a matching key the caller passes — same
|
|
16
16
|
* authoritative-merge rule as the tenant-session handshake.
|
|
17
17
|
*
|
|
18
|
-
* Other category adapters (an
|
|
18
|
+
* Other category adapters (an EmailSendAdapter for an internal mail API, an AIProviderAdapter for a
|
|
19
19
|
* REST-only model) call an ApiProviderAdapter internally instead of fetch()/proxyFetch()
|
|
20
20
|
* directly — a vendor adapter is just a few lines of normal code, no framework-provided bridge.
|
|
21
21
|
*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type EmailProviderErrorCode =
|
|
2
|
+
/** The adapter misses a setting (key, sender, client, library). */
|
|
3
|
+
'not-configured'
|
|
4
|
+
/** The message itself is not valid: no recipient, no body. */
|
|
5
|
+
| 'invalid-message'
|
|
6
|
+
/** The provider refused the credentials (401/403, revoked token). */
|
|
7
|
+
| 'unauthorized'
|
|
8
|
+
/** The provider refused the message (400/422: sender not verified, address not valid). */
|
|
9
|
+
| 'rejected' | 'rate-limited'
|
|
10
|
+
/** The provider or the network did not answer. */
|
|
11
|
+
| 'unavailable' | 'unknown';
|
|
12
|
+
export declare class EmailProviderError extends Error {
|
|
13
|
+
readonly code: EmailProviderErrorCode;
|
|
14
|
+
readonly provider: string;
|
|
15
|
+
readonly status?: number;
|
|
16
|
+
constructor(code: EmailProviderErrorCode, provider: string, message: string, options?: {
|
|
17
|
+
status?: number;
|
|
18
|
+
cause?: unknown;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** The code of an HTTP status of a provider. */
|
|
22
|
+
export declare const emailErrorCode: (status: number) => EmailProviderErrorCode;
|
|
23
|
+
/**
|
|
24
|
+
* A JSON call to a provider: the answer, or an `EmailProviderError` with the status and the path only.
|
|
25
|
+
* A network failure is `unavailable`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function callEmailApi<T>(provider: string, http: typeof fetch, url: string, init: RequestInit): Promise<T>;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
type
|
|
4
|
-
|
|
2
|
+
import type { EmailSendAdapter } from './EmailSend';
|
|
3
|
+
import type { EmailReadAdapter } from './EmailRead';
|
|
4
|
+
type Registry<T> = {
|
|
5
|
+
registry: Record<string, T>;
|
|
5
6
|
defaultKey: string;
|
|
6
7
|
};
|
|
7
|
-
declare const
|
|
8
|
-
export declare const EmailProvider: ({ registry, defaultKey, children, }: EmailProviderContextValue & {
|
|
8
|
+
export declare const EmailSendProvider: ({ registry, defaultKey, children }: Registry<EmailSendAdapter> & {
|
|
9
9
|
children: React.ReactNode;
|
|
10
10
|
}) => React.JSX.Element;
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
11
|
+
export declare const EmailReadProvider: ({ registry, defaultKey, children }: Registry<EmailReadAdapter> & {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}) => React.JSX.Element;
|
|
14
|
+
/** The adapter that sends (the default one, or `name`), or `null` when none is registered. */
|
|
15
|
+
export declare const useEmailSendProvider: (name?: string) => EmailSendAdapter | null;
|
|
16
|
+
/** The adapter that reads (the default one, or `name`), or `null` when none is registered. */
|
|
17
|
+
export declare const useEmailReadProvider: (name?: string) => EmailReadAdapter | null;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ProviderConfigurable } from '../ProviderConfiguration';
|
|
2
|
+
export interface EmailMessage {
|
|
3
|
+
/** The id of the message in its mailbox. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The conversation: Gmail's thread, the Message-ID of the first message elsewhere. */
|
|
6
|
+
threadId: string;
|
|
7
|
+
/** The headers as text (`Ada <ada@example.com>`). */
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
subject: string;
|
|
11
|
+
/** When it arrived, ISO 8601. */
|
|
12
|
+
date: string;
|
|
13
|
+
/** The plain text: the text part, else the HTML without tags. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** `outbound` for a message the mailbox sent itself (Gmail's SENT). */
|
|
16
|
+
direction: 'inbound' | 'outbound';
|
|
17
|
+
/**
|
|
18
|
+
* Where to read on from once this message is handled: when the app stops at a message (its handler
|
|
19
|
+
* failed), it keeps the `cursor` of the last one handled and the next reading starts with the rest.
|
|
20
|
+
* With Gmail the next reading may give again the messages of the same history record handled before it.
|
|
21
|
+
*/
|
|
22
|
+
cursor: string;
|
|
23
|
+
}
|
|
24
|
+
export interface EmailReadStart {
|
|
25
|
+
/** Where reading goes on from: opaque, the app keeps it as it is. */
|
|
26
|
+
cursor: string;
|
|
27
|
+
/** Gmail: when its push to Pub/Sub ends; call `start()` again before. */
|
|
28
|
+
expiresAt?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface EmailReadBatch {
|
|
31
|
+
messages: EmailMessage[];
|
|
32
|
+
/** The cursor to read on from next time. */
|
|
33
|
+
cursor: string;
|
|
34
|
+
}
|
|
35
|
+
export interface EmailReadOptions {
|
|
36
|
+
/** At most this many messages (default 50): the returned cursor goes on from the last one. */
|
|
37
|
+
limit?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface EmailReadAdapter extends ProviderConfigurable {
|
|
40
|
+
/** Reading starts now: the mails already in the mailbox stay out. */
|
|
41
|
+
start(): Promise<EmailReadStart>;
|
|
42
|
+
/**
|
|
43
|
+
* The new mails since `cursor`, oldest first, and the cursor after them. A cursor the mailbox no longer
|
|
44
|
+
* knows (Gmail's history expired, IMAP's UIDVALIDITY changed) starts again from now, reading nothing old.
|
|
45
|
+
*/
|
|
46
|
+
read(cursor: string, options?: EmailReadOptions): Promise<EmailReadBatch>;
|
|
47
|
+
}
|
|
48
|
+
export declare const DEFAULT_EMAIL_READ_LIMIT = 50;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ProviderConfigurable } from '../ProviderConfiguration';
|
|
2
|
+
/** An address, with the name shown to who reads it. */
|
|
3
|
+
export type EmailAddress = {
|
|
4
|
+
email: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
};
|
|
7
|
+
/** An address as text (`ada@example.com`) or with its name. */
|
|
8
|
+
export type EmailRecipient = string | EmailAddress;
|
|
9
|
+
export interface EmailSendParams {
|
|
10
|
+
/** The sender; without it, the adapter's own `from`. */
|
|
11
|
+
from?: EmailRecipient;
|
|
12
|
+
to: EmailRecipient | EmailRecipient[];
|
|
13
|
+
cc?: EmailRecipient | EmailRecipient[];
|
|
14
|
+
bcc?: EmailRecipient | EmailRecipient[];
|
|
15
|
+
replyTo?: EmailRecipient;
|
|
16
|
+
subject: string;
|
|
17
|
+
/** The body as HTML, as text, or both (the reader's client picks). At least one. */
|
|
18
|
+
html?: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
/** Gmail: the conversation the message joins. The other providers ignore it. */
|
|
21
|
+
threadId?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface EmailSendResult {
|
|
24
|
+
/** The id the provider gave the message. */
|
|
25
|
+
id: string;
|
|
26
|
+
threadId?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface EmailSendAdapter extends ProviderConfigurable {
|
|
29
|
+
send(params: EmailSendParams): Promise<EmailSendResult>;
|
|
30
|
+
}
|
|
31
|
+
/** An address as `{ email, name? }`. */
|
|
32
|
+
export declare const toEmailAddress: (recipient: EmailRecipient) => EmailAddress;
|
|
33
|
+
/** One or more addresses as a list, without the empty ones. */
|
|
34
|
+
export declare const toEmailAddresses: (recipients: EmailRecipient | EmailRecipient[] | undefined) => EmailAddress[];
|
|
35
|
+
/** An address as a header shows it: `Ada <ada@example.com>`, or the bare address. */
|
|
36
|
+
export declare const formatEmailAddress: ({ email, name }: EmailAddress) => string;
|
|
37
|
+
/**
|
|
38
|
+
* The message an adapter sends: sender and recipients as addresses, at least one recipient and one body.
|
|
39
|
+
* Throws `invalid-message` or (no sender, when the provider needs one) `not-configured`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function prepareEmail(provider: string, params: EmailSendParams, defaultFrom: EmailRecipient | undefined, { fromRequired }?: {
|
|
42
|
+
fromRequired?: boolean | undefined;
|
|
43
|
+
}): {
|
|
44
|
+
from: EmailAddress | undefined;
|
|
45
|
+
to: EmailAddress[];
|
|
46
|
+
cc: EmailAddress[];
|
|
47
|
+
bcc: EmailAddress[];
|
|
48
|
+
replyTo: EmailAddress | undefined;
|
|
49
|
+
subject: string;
|
|
50
|
+
html: string | undefined;
|
|
51
|
+
text: string | undefined;
|
|
52
|
+
threadId: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
export type PreparedEmail = ReturnType<typeof prepareEmail>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type EmailRecipient, type EmailSendAdapter, type EmailSendParams, type EmailSendResult } from '../EmailSend';
|
|
3
|
+
export declare const BREVO_EMAIL_URL = "https://api.brevo.com/v3/smtp/email";
|
|
4
|
+
export type BrevoEmailSenderConfig = {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** The default sender, a sender or domain verified in Brevo. */
|
|
7
|
+
from?: EmailRecipient;
|
|
8
|
+
/** The `fetch` to use (a proxy, a test). */
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Sends with Brevo's transactional API (CR-130). The key is a secret: use it on a server, not in a
|
|
13
|
+
* browser bundle.
|
|
14
|
+
*/
|
|
15
|
+
export declare class BrevoEmailSender implements EmailSendAdapter {
|
|
16
|
+
private readonly config;
|
|
17
|
+
constructor(config: BrevoEmailSenderConfig);
|
|
18
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
19
|
+
isConfigured(): boolean;
|
|
20
|
+
send(params: EmailSendParams): Promise<EmailSendResult>;
|
|
21
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { ProviderDescriptor } from '../ProviderDescriptor';
|
|
2
|
-
export type
|
|
3
|
-
export
|
|
2
|
+
export type EmailSendProviderId = 'resend' | 'brevo' | 'gmail' | 'sendgrid' | 'mailgun' | 'postmark' | 'ses' | 'smtp';
|
|
3
|
+
export type EmailReadProviderId = 'gmail' | 'imap';
|
|
4
|
+
export declare const EMAIL_SEND_PROVIDER_DEFINITIONS: ProviderDescriptor[];
|
|
5
|
+
export declare const EMAIL_READ_PROVIDER_DEFINITIONS: ProviderDescriptor[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type EmailReadAdapter, type EmailReadBatch, type EmailReadOptions, type EmailReadStart } from '../EmailRead';
|
|
3
|
+
import { type GmailAuth } from './gmailApi';
|
|
4
|
+
export type GmailEmailReaderConfig = {
|
|
5
|
+
auth: GmailAuth;
|
|
6
|
+
/**
|
|
7
|
+
* The Pub/Sub topic Gmail notifies (`projects/<project>/topics/<name>`, with `roles/pubsub.publisher` to
|
|
8
|
+
* `gmail-api-push@system.gserviceaccount.com`). Without it `start()` registers no push: the app reads by polling.
|
|
9
|
+
*/
|
|
10
|
+
topic?: string;
|
|
11
|
+
/** The label read (default `INBOX`). */
|
|
12
|
+
labelId?: string;
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Reads a Gmail mailbox (CR-130) by its history: the cursor is a `historyId`. With a `topic`, `start()` also
|
|
17
|
+
* asks Gmail to notify the topic of every change (the push lasts 7 days: call `start()` again before
|
|
18
|
+
* `expiresAt`); a notification (`decodeGmailPushNotification`) tells the app when to `read()`.
|
|
19
|
+
* Scope `GMAIL_SCOPES.read`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class GmailEmailReader implements EmailReadAdapter {
|
|
22
|
+
private readonly config;
|
|
23
|
+
constructor(config: GmailEmailReaderConfig);
|
|
24
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
25
|
+
isConfigured(): boolean;
|
|
26
|
+
private session;
|
|
27
|
+
start(): Promise<EmailReadStart>;
|
|
28
|
+
read(cursor: string, { limit }?: EmailReadOptions): Promise<EmailReadBatch>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The notification Gmail publishes on the topic: the `data` of the Pub/Sub message (base64 JSON) as
|
|
32
|
+
* `{ emailAddress, historyId }`, or `null` when it is not one.
|
|
33
|
+
*/
|
|
34
|
+
export declare function decodeGmailPushNotification(data: string | undefined | null): {
|
|
35
|
+
emailAddress: string;
|
|
36
|
+
historyId: string;
|
|
37
|
+
} | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type EmailRecipient, type EmailSendAdapter, type EmailSendParams, type EmailSendResult } from '../EmailSend';
|
|
3
|
+
import { type GmailAuth } from './gmailApi';
|
|
4
|
+
export type GmailEmailSenderConfig = {
|
|
5
|
+
auth: GmailAuth;
|
|
6
|
+
/** The sender shown; without it Gmail uses the address of the account (an alias must be set in Gmail). */
|
|
7
|
+
from?: EmailRecipient;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Sends from a Gmail mailbox (CR-130): with the browser's Google sign-in (`auth.accessToken`), or on a server
|
|
12
|
+
* with the app's OAuth client and the mailbox's refresh token (scope `GMAIL_SCOPES.send`). `threadId` keeps a
|
|
13
|
+
* reply in its conversation.
|
|
14
|
+
*/
|
|
15
|
+
export declare class GmailEmailSender implements EmailSendAdapter {
|
|
16
|
+
protected readonly config: GmailEmailSenderConfig;
|
|
17
|
+
constructor(config: GmailEmailSenderConfig);
|
|
18
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
19
|
+
isConfigured(): boolean;
|
|
20
|
+
send(params: EmailSendParams): Promise<EmailSendResult>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { GmailEmailSender } from './GmailEmailSender';
|
|
3
|
+
/**
|
|
4
|
+
* The `gmail` driver of the `google` provider (CR-130): sends as the user signed in with Google in the
|
|
5
|
+
* browser, so it is configured when `google.oAuth2.clientId` is.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BrowserGmailEmailSender extends GmailEmailSender {
|
|
8
|
+
constructor();
|
|
9
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type PreparedEmail } from '../EmailSend';
|
|
3
|
+
import type { EmailMessage } from '../EmailRead';
|
|
4
|
+
export declare const GMAIL_API = "https://gmail.googleapis.com/gmail/v1/users/me";
|
|
5
|
+
export declare const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
6
|
+
/** The scopes of Gmail: read the mailbox, send from it. */
|
|
7
|
+
export declare const GMAIL_SCOPES: {
|
|
8
|
+
readonly read: "https://www.googleapis.com/auth/gmail.readonly";
|
|
9
|
+
readonly send: "https://www.googleapis.com/auth/gmail.send";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How a Gmail adapter gets its access token: a function (the browser's Google sign-in), or the OAuth client
|
|
13
|
+
* of the app and the refresh token of the mailbox (a server).
|
|
14
|
+
*/
|
|
15
|
+
export type GmailAuth = {
|
|
16
|
+
accessToken: () => Promise<string>;
|
|
17
|
+
} | {
|
|
18
|
+
clientId: string;
|
|
19
|
+
clientSecret: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const PROVIDER = "Gmail";
|
|
23
|
+
/** Whether the auth has what it needs. */
|
|
24
|
+
export declare function gmailConfigurationState(name: string, auth: GmailAuth | undefined): ProviderConfigurationState;
|
|
25
|
+
/** A fresh access token: from the function, or exchanging the refresh token. */
|
|
26
|
+
export declare function gmailAccessToken(auth: GmailAuth, http: typeof fetch): Promise<string>;
|
|
27
|
+
export declare const base64Url: (text: string) => string;
|
|
28
|
+
export declare const fromBase64Url: (data: string) => string;
|
|
29
|
+
/** The raw message (RFC 2822) in base64url, as `messages.send` takes it. */
|
|
30
|
+
export declare function gmailRawMessage(mail: PreparedEmail): string;
|
|
31
|
+
type GmailPart = {
|
|
32
|
+
mimeType?: string;
|
|
33
|
+
body?: {
|
|
34
|
+
data?: string;
|
|
35
|
+
};
|
|
36
|
+
parts?: GmailPart[];
|
|
37
|
+
};
|
|
38
|
+
export type GmailApiMessage = {
|
|
39
|
+
id: string;
|
|
40
|
+
threadId?: string;
|
|
41
|
+
labelIds?: string[];
|
|
42
|
+
snippet?: string;
|
|
43
|
+
internalDate?: string;
|
|
44
|
+
payload?: GmailPart & {
|
|
45
|
+
headers?: {
|
|
46
|
+
name: string;
|
|
47
|
+
value: string;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** A message of the API (`format=full`) as an `EmailMessage`, with the cursor after it. */
|
|
52
|
+
export declare function toEmailMessage(message: GmailApiMessage, cursor: string): EmailMessage;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type GmailOAuthConfig = {
|
|
2
|
+
clientId: string;
|
|
3
|
+
clientSecret: string;
|
|
4
|
+
/** Where Google comes back with the code: a route of the app's server. */
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
};
|
|
8
|
+
export type GmailOAuth = {
|
|
9
|
+
/** The consent page of Google, with a refresh token (offline, consent asked again). */
|
|
10
|
+
authorizationUrl(options: {
|
|
11
|
+
state: string;
|
|
12
|
+
scopes: string[];
|
|
13
|
+
loginHint?: string;
|
|
14
|
+
}): string;
|
|
15
|
+
/** The code Google came back with → the address of the mailbox and its refresh token. */
|
|
16
|
+
exchangeCode(code: string): Promise<{
|
|
17
|
+
email: string;
|
|
18
|
+
refreshToken: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Connecting a Gmail mailbox from a server (CR-130): the consent page, then the refresh token the Gmail
|
|
23
|
+
* adapters take as `auth`. The client secret and the refresh token stay on the server.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createGmailOAuth(config: GmailOAuthConfig): GmailOAuth;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type EmailReadAdapter, type EmailReadBatch, type EmailReadOptions, type EmailReadStart } from '../EmailRead';
|
|
3
|
+
export type ImapEmailReaderConfig = {
|
|
4
|
+
host: string;
|
|
5
|
+
/** Default 993. */
|
|
6
|
+
port?: number;
|
|
7
|
+
/** TLS from the start (default `true`, port 993); `false` for STARTTLS or plain (port 143). */
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
user: string;
|
|
10
|
+
/** The password, or an app password where the provider has them. */
|
|
11
|
+
password: string;
|
|
12
|
+
/** Default `INBOX`. */
|
|
13
|
+
mailbox?: string;
|
|
14
|
+
};
|
|
15
|
+
/** The parts of `imapflow` and `mailparser` the reader uses: injectable for tests. */
|
|
16
|
+
export type ImapModules = {
|
|
17
|
+
ImapFlow: new (options: Record<string, unknown>) => ImapClient;
|
|
18
|
+
simpleParser: (source: Buffer) => Promise<ParsedMail>;
|
|
19
|
+
};
|
|
20
|
+
type ImapClient = {
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
mailboxOpen(path: string, options?: {
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
uidValidity: bigint | number;
|
|
26
|
+
uidNext: number;
|
|
27
|
+
}>;
|
|
28
|
+
fetch(range: string, query: {
|
|
29
|
+
uid?: boolean;
|
|
30
|
+
source?: boolean;
|
|
31
|
+
}, options?: {
|
|
32
|
+
uid?: boolean;
|
|
33
|
+
}): AsyncIterable<{
|
|
34
|
+
uid: number;
|
|
35
|
+
source?: Buffer;
|
|
36
|
+
}>;
|
|
37
|
+
logout(): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
type ParsedAddress = {
|
|
40
|
+
text?: string;
|
|
41
|
+
};
|
|
42
|
+
type ParsedMail = {
|
|
43
|
+
messageId?: string;
|
|
44
|
+
from?: ParsedAddress;
|
|
45
|
+
to?: ParsedAddress | ParsedAddress[];
|
|
46
|
+
subject?: string;
|
|
47
|
+
date?: Date;
|
|
48
|
+
text?: string;
|
|
49
|
+
html?: string | false;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Reads a mailbox with IMAP (CR-130), for the providers without push: the app calls `read()` every few
|
|
53
|
+
* minutes. The cursor is the UIDVALIDITY of the mailbox and the last UID read; a new UIDVALIDITY (the
|
|
54
|
+
* mailbox renumbered) starts again from now. Server only: it opens a TCP connection. Needs the optional
|
|
55
|
+
* packages `imapflow` and `mailparser`, loaded on the first read.
|
|
56
|
+
*/
|
|
57
|
+
export declare class ImapEmailReader implements EmailReadAdapter {
|
|
58
|
+
private readonly config;
|
|
59
|
+
private readonly options;
|
|
60
|
+
constructor(config: ImapEmailReaderConfig, options?: {
|
|
61
|
+
modules?: () => Promise<ImapModules>;
|
|
62
|
+
});
|
|
63
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
64
|
+
isConfigured(): boolean;
|
|
65
|
+
/** Opens the mailbox read-only, runs `work`, logs out whatever happens. */
|
|
66
|
+
private withMailbox;
|
|
67
|
+
start(): Promise<EmailReadStart>;
|
|
68
|
+
read(cursor: string, { limit }?: EmailReadOptions): Promise<EmailReadBatch>;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ProviderConfigurationState } from '../../ProviderConfiguration';
|
|
2
|
+
import { type EmailRecipient, type EmailSendAdapter, type EmailSendParams, type EmailSendResult } from '../EmailSend';
|
|
3
|
+
export declare const RESEND_EMAIL_URL = "https://api.resend.com/emails";
|
|
4
|
+
export type ResendEmailSenderConfig = {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** The default sender, on a domain verified in Resend. */
|
|
7
|
+
from?: EmailRecipient;
|
|
8
|
+
/** The `fetch` to use (a proxy, a test). */
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Sends with Resend (CR-130). The key is a secret: use it on a server, not in a browser bundle.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ResendEmailSender implements EmailSendAdapter {
|
|
15
|
+
private readonly config;
|
|
16
|
+
constructor(config: ResendEmailSenderConfig);
|
|
17
|
+
getConfigurationState(): ProviderConfigurationState;
|
|
18
|
+
isConfigured(): boolean;
|
|
19
|
+
send(params: EmailSendParams): Promise<EmailSendResult>;
|
|
20
|
+
}
|
|
@@ -5,12 +5,13 @@ import type { AIProviderAdapter } from './ai/AIProvider';
|
|
|
5
5
|
import type { DataProviderAdapter } from './data/DataProvider';
|
|
6
6
|
import type { StorageProviderAdapter } from './storage/StorageProvider';
|
|
7
7
|
import type { AuthProviderAdapter } from './auth/AuthProvider';
|
|
8
|
-
import type {
|
|
8
|
+
import type { EmailSendAdapter } from './email/EmailSend';
|
|
9
|
+
import type { EmailReadAdapter } from './email/EmailRead';
|
|
9
10
|
import type { AIConfig, DropboxConfig, FirebaseConfig, GitHubAuthConfig, GoogleOAuth2, GoogleServiceAccount, SupabaseConfig } from '../Config';
|
|
10
11
|
import type { ProviderService } from './ProviderRegistryContext';
|
|
11
|
-
/** The
|
|
12
|
+
/** The 7 built-in categories — alias of ProviderService (ProviderRegistryContext.tsx), derived from ProviderAdapterMap so the two can't drift. */
|
|
12
13
|
export type ServiceCategory = ProviderService;
|
|
13
|
-
type AnyAdapter = DataProviderAdapter | StorageProviderAdapter | AuthProviderAdapter |
|
|
14
|
+
type AnyAdapter = DataProviderAdapter | StorageProviderAdapter | AuthProviderAdapter | EmailSendAdapter | EmailReadAdapter | AIProviderAdapter | CredentialsAdapter;
|
|
14
15
|
export interface DriverDescriptor<TConfig = unknown> {
|
|
15
16
|
service: ServiceCategory;
|
|
16
17
|
create: (config: TConfig) => AnyAdapter;
|
|
@@ -38,14 +39,15 @@ export declare const PROVIDER_MANIFESTS: Record<string, DriverManifest<any>>;
|
|
|
38
39
|
export type DataDriverName = 'dbRealtime' | 'firestoreDb' | 'supabaseDb' | 'mock';
|
|
39
40
|
export type StorageDriverName = 'firestorage' | 'supabaseStorage';
|
|
40
41
|
export type AuthDriverName = 'googleAuth' | 'firebaseAuth' | 'dropboxAuth' | 'supabaseAuth' | 'githubAuth' | 'mockAuth';
|
|
41
|
-
export type
|
|
42
|
+
export type EmailSendDriverName = 'gmail';
|
|
42
43
|
export type AIDriverName = 'openai' | 'openrouter' | 'opencode' | 'opencode-go' | 'openai-compatible' | 'deepseek' | 'gemini' | 'anthropic' | 'mistral' | 'cloudflare' | 'groq';
|
|
43
44
|
export type CredentialsDriverName = 'googleServiceAccount';
|
|
44
45
|
export type ServicesConfig = {
|
|
45
46
|
data?: DataDriverName | string;
|
|
46
47
|
storage?: StorageDriverName | string;
|
|
47
48
|
auth?: AuthDriverName | string;
|
|
48
|
-
|
|
49
|
+
emailSend?: EmailSendDriverName | string;
|
|
50
|
+
emailRead?: string;
|
|
49
51
|
ai?: AIDriverName | string;
|
|
50
52
|
credentials?: CredentialsDriverName | string;
|
|
51
53
|
};
|
package/dist/vite.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./logHeader-CUsdmGAo.js"),t=require("./server-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./logHeader-CUsdmGAo.js"),t=require("./server-CDheNgME.js");let n=require("node:fs/promises"),r=require("node:path");r=e.r(r);var i=`x-llmnative-proxy`,a=`/api/proxy`,o=async e=>{let t=[];for await(let n of e)t.push(Buffer.isBuffer(n)?n:Buffer.from(n));return t.length===0?void 0:Buffer.concat(t)};function s(e){return e.replace(/[^a-zA-Z0-9_-]/g,``).slice(0,128)||`unknown`}function c(e){if(!e.trim())return`(empty body)`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}async function l(e,t,i,a,o,l){try{await(0,n.mkdir)(e.dir,{recursive:!0});let u=[``,`=`.repeat(80),`Turn @ ${new Date().toISOString()}`,`Target: ${i}`,`--- REQUEST BODY ---`,c(a),`--- RESPONSE BODY (status ${o}) ---`,c(l),`=`.repeat(80),``].join(`
|
|
2
2
|
`);await(0,n.appendFile)(r.default.join(e.dir,`${s(t)}.txt`),u,`utf-8`)}catch(e){console.warn(`[llmnative-dev-proxy] Failed to write LLM log:`,e)}}var u=async(n,r,a,s,c)=>{let u=new URL(n.url||`/`,`http://localhost`).searchParams.get(`url`);if(n.headers[i]!==`1`){r.statusCode=403,r.setHeader(`Content-Type`,`application/json`),r.end(JSON.stringify({error:`Proxy access denied.`}));return}if(!u){r.statusCode=400,r.setHeader(`Content-Type`,`application/json`),r.end(JSON.stringify({error:`Missing "url" query parameter.`}));return}try{let d=new URL(u);if(d.pathname.startsWith(a)&&[`localhost`,`127.0.0.1`].includes(d.hostname)){r.statusCode=508,r.setHeader(`Content-Type`,`application/json`),r.end(JSON.stringify({error:`Recursive proxy target detected.`,target:u}));return}let f=await o(n),p=n.headers[e.t],m=new Headers,h=new Set([i,e.t,`host`,`origin`,`referer`,`content-length`,`transfer-encoding`,`connection`]);Object.entries(n.headers).forEach(([e,t])=>{t&&!h.has(e.toLowerCase())&&m.set(e,Array.isArray(t)?t.join(`, `):t)});let g=await t.t({url:u,headers:Object.fromEntries(m)},c??(()=>void 0));if(!g.ok){r.statusCode=g.status,r.setHeader(`Content-Type`,`application/json`),r.end(JSON.stringify({error:g.error,provider:g.provider}));return}let _=await fetch(g.url,{method:n.method||`GET`,headers:new Headers(g.headers),body:f&&![`GET`,`HEAD`].includes((n.method||`GET`).toUpperCase())?Uint8Array.from(f):void 0,redirect:`follow`}),v=Buffer.from(await _.arrayBuffer());s?.enabled&&typeof p==`string`&&p&&l(s,p,u,f?.toString(`utf-8`)??``,_.status,v.toString(`utf-8`)),r.statusCode=_.status,_.headers.forEach((e,t)=>{t.toLowerCase()!==`content-encoding`&&r.setHeader(t,e)}),r.end(v)}catch(e){r.statusCode=502,r.setHeader(`Content-Type`,`application/json`),r.end(JSON.stringify({error:e instanceof Error?e.message:`Proxy request failed.`}))}},d=(e=a,t,n)=>({name:`llmnative-dev-proxy`,configureServer(r){r.middlewares.use(e,(r,i)=>{u(r,i,e,t,n)})},configurePreviewServer(r){r.middlewares.use(e,(r,i)=>{u(r,i,e,t,n)})}});exports.PROXY_PATH=a,exports.createProxyPlugin=d;
|
|
3
3
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./logHeader-Busbc8OO.mjs";
|
|
2
|
-
import { t } from "./server-
|
|
2
|
+
import { t } from "./server-B430eH0y.mjs";
|
|
3
3
|
import { appendFile as n, mkdir as r } from "node:fs/promises";
|
|
4
4
|
import i from "node:path";
|
|
5
5
|
//#region src/providers/proxy/vite.ts
|