@aexol/spectral 0.9.212 → 0.9.216
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/generated-images.d.ts +180 -0
- package/dist/backend/generated-images.d.ts.map +1 -0
- package/dist/backend/generated-images.js +483 -0
- package/dist/backend/machine-routing.d.ts +25 -0
- package/dist/backend/machine-routing.d.ts.map +1 -0
- package/dist/backend/machine-routing.js +35 -0
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/logout.js +4 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +20 -2
- package/dist/extensions/browser/browser-service.d.ts +75 -1
- package/dist/extensions/browser/browser-service.d.ts.map +1 -1
- package/dist/extensions/browser/browser-service.js +600 -34
- package/dist/extensions/browser/index.d.ts +10 -4
- package/dist/extensions/browser/index.d.ts.map +1 -1
- package/dist/extensions/browser/index.js +44 -5
- package/dist/extensions/browser/stream/stream-tool.d.ts +10 -0
- package/dist/extensions/browser/stream/stream-tool.d.ts.map +1 -1
- package/dist/extensions/browser/stream/stream-tool.js +42 -14
- package/dist/extensions/browser/tools/core.d.ts.map +1 -1
- package/dist/extensions/browser/tools/core.js +63 -2
- package/dist/extensions/desktop-control/index.d.ts +55 -0
- package/dist/extensions/desktop-control/index.d.ts.map +1 -0
- package/dist/extensions/desktop-control/index.js +633 -0
- package/dist/extensions/desktop-control/keys.d.ts +33 -0
- package/dist/extensions/desktop-control/keys.d.ts.map +1 -0
- package/dist/extensions/desktop-control/keys.js +170 -0
- package/dist/extensions/desktop-control/linux.d.ts +26 -0
- package/dist/extensions/desktop-control/linux.d.ts.map +1 -0
- package/dist/extensions/desktop-control/linux.js +195 -0
- package/dist/extensions/desktop-control/macos.d.ts +53 -0
- package/dist/extensions/desktop-control/macos.d.ts.map +1 -0
- package/dist/extensions/desktop-control/macos.js +382 -0
- package/dist/extensions/desktop-control/safety.d.ts +89 -0
- package/dist/extensions/desktop-control/safety.d.ts.map +1 -0
- package/dist/extensions/desktop-control/safety.js +157 -0
- package/dist/extensions/desktop-control/types.d.ts +79 -0
- package/dist/extensions/desktop-control/types.d.ts.map +1 -0
- package/dist/extensions/desktop-control/types.js +10 -0
- package/dist/extensions/desktop-control/windows.d.ts +31 -0
- package/dist/extensions/desktop-control/windows.d.ts.map +1 -0
- package/dist/extensions/desktop-control/windows.js +276 -0
- package/dist/extensions/desktop-screenshot/index.d.ts +103 -0
- package/dist/extensions/desktop-screenshot/index.d.ts.map +1 -1
- package/dist/extensions/desktop-screenshot/index.js +363 -17
- package/dist/extensions/image-generation/index.d.ts.map +1 -1
- package/dist/extensions/image-generation/index.js +133 -34
- package/dist/extensions/seo/index.d.ts.map +1 -1
- package/dist/extensions/seo/index.js +4 -0
- package/dist/extensions/seo/tools/backend-bridge.d.ts +4 -0
- package/dist/extensions/seo/tools/backend-bridge.d.ts.map +1 -0
- package/dist/extensions/seo/tools/backend-bridge.js +378 -0
- package/dist/extensions/seo/tools/full-audit.d.ts +2 -0
- package/dist/extensions/seo/tools/full-audit.d.ts.map +1 -1
- package/dist/extensions/seo/tools/full-audit.js +1 -1
- package/dist/extensions/seo/tools/report.d.ts +10 -0
- package/dist/extensions/seo/tools/report.d.ts.map +1 -1
- package/dist/extensions/seo/tools/report.js +1 -1
- package/dist/extensions/spectral-vision-fallback.d.ts.map +1 -1
- package/dist/extensions/spectral-vision-fallback.js +11 -1
- package/dist/generated/zeus/const.d.ts.map +1 -1
- package/dist/generated/zeus/const.js +121 -4
- package/dist/generated/zeus/index.d.ts +527 -0
- package/dist/generated/zeus/index.d.ts.map +1 -1
- package/dist/mcp/tool-registrar.d.ts.map +1 -1
- package/dist/mcp/tool-registrar.js +5 -2
- package/dist/mcp/types.d.ts +5 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/relay/dispatcher.d.ts +12 -1
- package/dist/relay/dispatcher.d.ts.map +1 -1
- package/dist/relay/dispatcher.js +44 -42
- package/dist/sdk/ai/providers/faux.js +1 -1
- package/dist/sdk/ai/providers/openai-completions.d.ts.map +1 -1
- package/dist/sdk/ai/providers/openai-completions.js +69 -16
- package/dist/sdk/ai/providers/openrouter-images.d.ts.map +1 -1
- package/dist/sdk/ai/providers/openrouter-images.js +58 -9
- package/dist/sdk/ai/providers/simple-options.d.ts.map +1 -1
- package/dist/sdk/ai/providers/simple-options.js +2 -0
- package/dist/sdk/ai/types.d.ts +37 -1
- package/dist/sdk/ai/types.d.ts.map +1 -1
- package/dist/sdk/ai/utils/hosted-image-resolver.d.ts +60 -0
- package/dist/sdk/ai/utils/hosted-image-resolver.d.ts.map +1 -0
- package/dist/sdk/ai/utils/hosted-image-resolver.js +75 -0
- package/dist/sdk/ai/utils/image-source.d.ts +168 -0
- package/dist/sdk/ai/utils/image-source.d.ts.map +1 -0
- package/dist/sdk/ai/utils/image-source.js +487 -0
- package/dist/sdk/coding-agent/core/extensions/native-extensions.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/extensions/native-extensions.js +14 -0
- package/dist/sdk/coding-agent/core/extensions/types.d.ts +9 -0
- package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/system-prompt.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/system-prompt.js +15 -9
- package/dist/sdk/coding-agent/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/sdk/coding-agent/modes/rpc/rpc-mode.js +16 -3
- package/dist/sdk/coding-agent/utils/image-resize.d.ts.map +1 -1
- package/dist/sdk/coding-agent/utils/image-resize.js +7 -3
- package/dist/server/agent-bridge.d.ts +14 -0
- package/dist/server/agent-bridge.d.ts.map +1 -1
- package/dist/server/agent-bridge.js +105 -26
- package/dist/server/handlers/queue.d.ts.map +1 -1
- package/dist/server/handlers/queue.js +11 -34
- package/dist/server/image-attachments.d.ts +109 -0
- package/dist/server/image-attachments.d.ts.map +1 -0
- package/dist/server/image-attachments.js +195 -0
- package/dist/server/session-stream.d.ts +67 -0
- package/dist/server/session-stream.d.ts.map +1 -1
- package/dist/server/session-stream.js +222 -23
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js +10 -31
- package/dist/server/ui/terminal-confirm.d.ts +145 -0
- package/dist/server/ui/terminal-confirm.d.ts.map +1 -0
- package/dist/server/ui/terminal-confirm.js +333 -0
- package/dist/server/wire.d.ts +30 -5
- package/dist/server/wire.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wiring for backend-hosted images in provider requests.
|
|
3
|
+
*
|
|
4
|
+
* The backend serves conversation images from S3 behind
|
|
5
|
+
* `GET /generated-images/<id>`, which is AUTH-GATED: an LLM provider
|
|
6
|
+
* (OpenAI, Anthropic, OpenRouter, ...) fetching that url anonymously gets a
|
|
7
|
+
* 401 and the image is silently dropped. `GET /generated-images/<id>/url`
|
|
8
|
+
* — behind the machine JWT — returns a presigned S3 url that anyone can
|
|
9
|
+
* fetch, so that is what we hand to the provider.
|
|
10
|
+
*
|
|
11
|
+
* `resolveBackendRouting()` supplies both the backend url and the machine
|
|
12
|
+
* JWT. It is lazy (config + machine store are only read when a hosted image
|
|
13
|
+
* is actually present) and memoized per resolver instance, and it degrades to
|
|
14
|
+
* `null` when the CLI is not logged in — in which case every hook here is a
|
|
15
|
+
* no-op and behaviour falls back to whatever it was before.
|
|
16
|
+
*
|
|
17
|
+
* @module @spectral/ai/utils/hosted-image-resolver
|
|
18
|
+
*/
|
|
19
|
+
export interface BackendHostedImageResolverOptions {
|
|
20
|
+
/** Diagnostics sink — resolution failures are silent without it. */
|
|
21
|
+
onWarn?: (message: string) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Explicit backend base url (or a lazy getter for it). Wins over the url
|
|
24
|
+
* from `resolveBackendRouting()`, so per-request overrides keep working;
|
|
25
|
+
* used to resolve backend-relative image urls (`/generated-images/<id>`).
|
|
26
|
+
*/
|
|
27
|
+
baseUrl?: string | (() => string | undefined | Promise<string | undefined>);
|
|
28
|
+
}
|
|
29
|
+
export interface BackendHostedImageResolver {
|
|
30
|
+
/**
|
|
31
|
+
* Swap a hosted url for a presigned one. Returns `null` when the url is
|
|
32
|
+
* not resolvable (not logged in, foreign origin, backend error, ...) so
|
|
33
|
+
* the caller can fall back to downloading + inlining the bytes itself.
|
|
34
|
+
*/
|
|
35
|
+
resolveHostedUrl: (url: string, options?: {
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}) => Promise<string | null>;
|
|
39
|
+
/**
|
|
40
|
+
* `Authorization: Bearer <machine JWT>` for downloading the image bytes
|
|
41
|
+
* from our own backend. Only ever attached to hosted backend urls.
|
|
42
|
+
*/
|
|
43
|
+
authHeaders: () => Promise<Record<string, string> | undefined>;
|
|
44
|
+
/** Backend base url for resolving backend-relative image urls. */
|
|
45
|
+
baseUrl: () => Promise<string | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* The backend url `resolveHostedUrl` authenticates against — i.e. the
|
|
48
|
+
* origin an absolute image url has to match to be considered ours.
|
|
49
|
+
* `undefined` when the CLI is not logged in (nothing is resolvable then).
|
|
50
|
+
*/
|
|
51
|
+
backendUrl: () => Promise<string | undefined>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build the hosted-image hooks for a single request.
|
|
55
|
+
*
|
|
56
|
+
* Cheap to construct: nothing is read from disk/config until one of the
|
|
57
|
+
* returned functions is actually awaited.
|
|
58
|
+
*/
|
|
59
|
+
export declare function backendHostedImageResolver(options?: BackendHostedImageResolverOptions): BackendHostedImageResolver;
|
|
60
|
+
//# sourceMappingURL=hosted-image-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-image-resolver.d.ts","sourceRoot":"","sources":["../../../../src/sdk/ai/utils/hosted-image-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,WAAW,iCAAiC;IACjD,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,0BAA0B;IAC1C;;;;OAIG;IACH,gBAAgB,EAAE,CACjB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAClD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5B;;;OAGG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IAC/D,kEAAkE;IAClE,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC3C;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,GAAE,iCAAsC,GAC7C,0BAA0B,CA6C5B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared wiring for backend-hosted images in provider requests.
|
|
3
|
+
*
|
|
4
|
+
* The backend serves conversation images from S3 behind
|
|
5
|
+
* `GET /generated-images/<id>`, which is AUTH-GATED: an LLM provider
|
|
6
|
+
* (OpenAI, Anthropic, OpenRouter, ...) fetching that url anonymously gets a
|
|
7
|
+
* 401 and the image is silently dropped. `GET /generated-images/<id>/url`
|
|
8
|
+
* — behind the machine JWT — returns a presigned S3 url that anyone can
|
|
9
|
+
* fetch, so that is what we hand to the provider.
|
|
10
|
+
*
|
|
11
|
+
* `resolveBackendRouting()` supplies both the backend url and the machine
|
|
12
|
+
* JWT. It is lazy (config + machine store are only read when a hosted image
|
|
13
|
+
* is actually present) and memoized per resolver instance, and it degrades to
|
|
14
|
+
* `null` when the CLI is not logged in — in which case every hook here is a
|
|
15
|
+
* no-op and behaviour falls back to whatever it was before.
|
|
16
|
+
*
|
|
17
|
+
* @module @spectral/ai/utils/hosted-image-resolver
|
|
18
|
+
*/
|
|
19
|
+
import { isHostedImageUrl, resolveHostedImageUrl } from "../../../backend/generated-images.js";
|
|
20
|
+
import { resolveBackendRouting } from "../../../backend/machine-routing.js";
|
|
21
|
+
/**
|
|
22
|
+
* Build the hosted-image hooks for a single request.
|
|
23
|
+
*
|
|
24
|
+
* Cheap to construct: nothing is read from disk/config until one of the
|
|
25
|
+
* returned functions is actually awaited.
|
|
26
|
+
*/
|
|
27
|
+
export function backendHostedImageResolver(options = {}) {
|
|
28
|
+
const { onWarn, baseUrl } = options;
|
|
29
|
+
let routing;
|
|
30
|
+
// Memoized so a context with five hosted images reads the machine store
|
|
31
|
+
// once, and text-only requests never touch it at all.
|
|
32
|
+
const getRouting = () => (routing ??= resolveBackendRouting().catch(() => null));
|
|
33
|
+
const resolveExplicitBaseUrl = async () => {
|
|
34
|
+
if (baseUrl === undefined)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (typeof baseUrl === "string")
|
|
37
|
+
return baseUrl.trim() || undefined;
|
|
38
|
+
try {
|
|
39
|
+
const value = await baseUrl();
|
|
40
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
resolveHostedUrl: async (url, options) => {
|
|
48
|
+
const resolved = await getRouting();
|
|
49
|
+
if (!resolved)
|
|
50
|
+
return null;
|
|
51
|
+
// SECURITY: never send the machine JWT to (or mint a presigned url
|
|
52
|
+
// for) a host that is not our backend — a third-party url must not
|
|
53
|
+
// be able to impersonate `/generated-images/<id>`.
|
|
54
|
+
if (!isHostedImageUrl(url, resolved.backendUrl)) {
|
|
55
|
+
onWarn?.(`Refusing to resolve a hosted image url for a foreign origin: ${url}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const result = await resolveHostedImageUrl({
|
|
59
|
+
backendUrl: resolved.backendUrl,
|
|
60
|
+
token: resolved.machineJwt,
|
|
61
|
+
url,
|
|
62
|
+
signal: options?.signal,
|
|
63
|
+
timeoutMs: options?.timeoutMs,
|
|
64
|
+
onWarn,
|
|
65
|
+
});
|
|
66
|
+
return result?.url ?? null;
|
|
67
|
+
},
|
|
68
|
+
authHeaders: async () => {
|
|
69
|
+
const resolved = await getRouting();
|
|
70
|
+
return resolved ? { Authorization: `Bearer ${resolved.machineJwt}` } : undefined;
|
|
71
|
+
},
|
|
72
|
+
baseUrl: async () => (await resolveExplicitBaseUrl()) ?? (await getRouting())?.backendUrl,
|
|
73
|
+
backendUrl: async () => (await getRouting())?.backendUrl,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image source resolution for provider serialization.
|
|
3
|
+
*
|
|
4
|
+
* `ImageContent` can now carry either inline base64 (`data`) or a hosted
|
|
5
|
+
* `url`. Providers (OpenRouter, AWS Bedrock, OpenAI, ...) can only fetch
|
|
6
|
+
* images from PUBLIC urls — a `http://localhost:9002/...` MinIO url in dev is
|
|
7
|
+
* unreachable for them. This module resolves an `ImageContent` block into
|
|
8
|
+
* something a provider can actually consume:
|
|
9
|
+
*
|
|
10
|
+
* - `data` present -> `data:<mimeType>;base64,<data>` (unchanged, legacy safe)
|
|
11
|
+
* - `url` public -> passed through as-is (no base64 in the context!)
|
|
12
|
+
* - `url` backend-hosted -> swapped for a presigned, headerless-fetchable
|
|
13
|
+
* url (`/generated-images/<id>` is what the
|
|
14
|
+
* backend returns; it is AUTH-GATED, so handing
|
|
15
|
+
* it to a provider only yields a 401)
|
|
16
|
+
* - `url` relative -> resolved against the backend base url first
|
|
17
|
+
* - `url` local/private -> fetched and inlined **at send time only**
|
|
18
|
+
*
|
|
19
|
+
* The inlining is deliberately scoped to a single request: the fetched bytes
|
|
20
|
+
* are written into a throw-away copy of the message list, never back into the
|
|
21
|
+
* session, so base64 never accumulates in persisted history.
|
|
22
|
+
*
|
|
23
|
+
* @module @spectral/ai/utils/image-source
|
|
24
|
+
*/
|
|
25
|
+
import type { Context, ImageContent } from "../types.js";
|
|
26
|
+
/** Don't inline absurd payloads — 25 MiB of base64 would blow the request. */
|
|
27
|
+
export declare const DEFAULT_MAX_INLINE_BYTES: number;
|
|
28
|
+
/** Timeout for fetching a local image that has to be inlined. */
|
|
29
|
+
export declare const DEFAULT_INLINE_FETCH_TIMEOUT_MS = 15000;
|
|
30
|
+
export interface ResolveImageOptions {
|
|
31
|
+
/** Abort the inline fetch (e.g. when the request is cancelled). */
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
maxInlineBytes?: number;
|
|
35
|
+
/** Injectable for tests / alternative runtimes. */
|
|
36
|
+
fetchImpl?: typeof fetch;
|
|
37
|
+
/**
|
|
38
|
+
* Base url (usually the backend url) used to turn a relative image url
|
|
39
|
+
* (`/generated-images/<id>`) into an absolute one. May be a lazy getter so
|
|
40
|
+
* callers only pay the cost (e.g. reading config) when a relative url is
|
|
41
|
+
* actually present.
|
|
42
|
+
*/
|
|
43
|
+
baseUrl?: string | (() => string | undefined | Promise<string | undefined>);
|
|
44
|
+
/**
|
|
45
|
+
* Exchange a backend-hosted image url (`/generated-images/<id>`) for a
|
|
46
|
+
* short-lived presigned url that the provider can fetch WITHOUT any
|
|
47
|
+
* Authorization header (see `resolveHostedImageUrl` in
|
|
48
|
+
* `backend/generated-images.ts`).
|
|
49
|
+
*
|
|
50
|
+
* Return `null`/`undefined` to fall back to the download+inline path.
|
|
51
|
+
* Only ever called for urls where `isHostedBackendImageUrl()` is true —
|
|
52
|
+
* i.e. relative urls and absolute urls on the backend origin.
|
|
53
|
+
*/
|
|
54
|
+
resolveHostedUrl?: (url: string, options?: {
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
}) => Promise<string | null | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Headers (in practice `Authorization: Bearer <machine JWT>`) used when the
|
|
60
|
+
* image bytes have to be downloaded for inlining. May be a lazy getter so
|
|
61
|
+
* the credentials are only read when a hosted image is actually present.
|
|
62
|
+
*
|
|
63
|
+
* SECURITY: these are only ever attached to a backend-hosted image url —
|
|
64
|
+
* never to a third-party host the credentials were not issued for.
|
|
65
|
+
*/
|
|
66
|
+
authHeaders?: Record<string, string> | (() => Promise<Record<string, string> | undefined>);
|
|
67
|
+
onWarn?: (message: string) => void;
|
|
68
|
+
}
|
|
69
|
+
export interface ResolvedImageSource {
|
|
70
|
+
/** Value to place in `image_url.url` (data URI or http(s) url). */
|
|
71
|
+
url: string;
|
|
72
|
+
/** True when the bytes were fetched and base64-inlined. */
|
|
73
|
+
inlined: boolean;
|
|
74
|
+
mimeType: string;
|
|
75
|
+
/**
|
|
76
|
+
* Raw base64 payload WITHOUT the `data:` prefix, matching the
|
|
77
|
+
* `ImageContent.data` contract. Only set when the bytes are known
|
|
78
|
+
* (inline `data` present, or fetched from a local url).
|
|
79
|
+
*/
|
|
80
|
+
data?: string;
|
|
81
|
+
/**
|
|
82
|
+
* True when `url` is a presigned url returned by `resolveHostedUrl` (i.e.
|
|
83
|
+
* it replaced an auth-gated `/generated-images/<id>` reference).
|
|
84
|
+
*/
|
|
85
|
+
hostedResolved?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* True when `rawUrl` has no scheme, i.e. it is relative and therefore
|
|
89
|
+
* unusable for a provider until it is joined with a base url.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isRelativeImageUrl(rawUrl: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Join a relative image url (`/generated-images/<id>`) with the backend base
|
|
94
|
+
* url. Absolute urls and missing base urls are returned untouched.
|
|
95
|
+
*/
|
|
96
|
+
export declare function resolveImageUrlAgainstBase(rawUrl: string, baseUrl?: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* True when a provider is unlikely to be able to fetch this URL itself and
|
|
99
|
+
* the image must therefore be inlined as base64 before sending.
|
|
100
|
+
*
|
|
101
|
+
* Covers: localhost, `*.local`, `*.localhost`, loopback IPs (v4 + v6),
|
|
102
|
+
* RFC1918 private ranges, link-local and CGNAT ranges, and non-http(s)
|
|
103
|
+
* schemes (except `data:`/`blob:` which need no fetch at all), plus
|
|
104
|
+
* container/metadata/reserved hosts and relative urls that still need to be
|
|
105
|
+
* resolved against a base url.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isLocalOrPrivateImageUrl(rawUrl: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* True for a backend-hosted image reference, either backend-relative
|
|
110
|
+
* (`/generated-images/<id>`) or absolute
|
|
111
|
+
* (`https://api.aexol.ai/generated-images/<id>`).
|
|
112
|
+
*
|
|
113
|
+
* `backendUrl` is REQUIRED to accept an ABSOLUTE url: without it there is no
|
|
114
|
+
* origin to compare against, and a foreign host that happens to expose
|
|
115
|
+
* `/generated-images/<id>` must never be treated as ours (that would send the
|
|
116
|
+
* machine JWT to it, and would let it swap in a presigned url of one of our
|
|
117
|
+
* tenant's images). Relative urls are always accepted — they can only ever be
|
|
118
|
+
* resolved against the backend base url.
|
|
119
|
+
*
|
|
120
|
+
* Those endpoints are auth-gated: a provider fetching them without an
|
|
121
|
+
* `Authorization` header gets a 401 and never sees the image.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isHostedBackendImageUrl(rawUrl: string, backendUrl?: string | null): boolean;
|
|
124
|
+
export declare function hasInlineImageData(image: ImageContent): image is ImageContent & {
|
|
125
|
+
data: string;
|
|
126
|
+
};
|
|
127
|
+
/** Build a `data:` URI from base64 payload + mime type (idempotent). */
|
|
128
|
+
export declare function dataUriForImage(data: string, mimeType: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* `ImageContent.data` is base64 WITHOUT a `data:` prefix, but legacy
|
|
131
|
+
* sessions may carry a full data URI. Strip it so consumers doing
|
|
132
|
+
* `Buffer.from(data, "base64")` get real bytes.
|
|
133
|
+
*/
|
|
134
|
+
export declare function base64FromImageData(data: string): string;
|
|
135
|
+
/**
|
|
136
|
+
* Resolve an image block into a provider-sendable url.
|
|
137
|
+
*
|
|
138
|
+
* Returns `null` when the block carries neither data nor url (nothing sendable).
|
|
139
|
+
* Local/private urls are fetched and inlined; failures fall back to the raw
|
|
140
|
+
* url so the caller still emits *something* rather than dropping the image.
|
|
141
|
+
*/
|
|
142
|
+
export declare function resolveImageForProvider(image: ImageContent, options?: ResolveImageOptions): Promise<ResolvedImageSource | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Pre-pass used right before a request is built: any image block that only has
|
|
145
|
+
* a local/private `url` gets its bytes fetched and attached as `data` on a
|
|
146
|
+
* throw-away copy of the context.
|
|
147
|
+
*
|
|
148
|
+
* The returned context is a shallow clone (messages copied, unchanged messages
|
|
149
|
+
* shared by reference) and is discarded after the single request completes, so
|
|
150
|
+
* base64 never lands in session history. When there is nothing to inline the
|
|
151
|
+
* original context object is returned unchanged.
|
|
152
|
+
*/
|
|
153
|
+
export declare function resolveImagesForContext(context: Context, options?: ResolveImageOptions): Promise<Context>;
|
|
154
|
+
/**
|
|
155
|
+
* Same as `resolveImagesForContext` but for the images API input list.
|
|
156
|
+
*/
|
|
157
|
+
export declare function resolveImagesForInput(input: Array<{
|
|
158
|
+
type: string;
|
|
159
|
+
}>, options?: ResolveImageOptions): Promise<Array<{
|
|
160
|
+
type: string;
|
|
161
|
+
}>>;
|
|
162
|
+
/**
|
|
163
|
+
* Synchronous serializer used inside the (sync) param builders: after the
|
|
164
|
+
* `resolveImagesForContext` pre-pass there should be nothing local left, so
|
|
165
|
+
* this only has to choose between an existing `data` payload and a public url.
|
|
166
|
+
*/
|
|
167
|
+
export declare function imageSourceUrlForProvider(image: ImageContent, baseUrl?: string): string | undefined;
|
|
168
|
+
//# sourceMappingURL=image-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-source.d.ts","sourceRoot":"","sources":["../../../../src/sdk/ai/utils/image-source.ts"],"names":[],"mappings":"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"}
|