@lunora/ai 1.0.0-alpha.23 → 1.0.0-alpha.24
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/index.d.mts +3 -65
- package/dist/index.d.ts +3 -65
- package/dist/index.mjs +2 -2
- package/dist/packem_shared/{AI_GATEWAY_ACCOUNT_ID_ENV-2CS2QFH7.mjs → AI_GATEWAY_ACCOUNT_ID_ENV-CIAjehQF.mjs} +7 -3
- package/dist/packem_shared/{createAi-Dx7n-UJm.mjs → createAi-Cep3l8Rk.mjs} +11 -7
- package/dist/packem_shared/{types.d-DGmh5Hq4.d.mts → types.d-F_Q8R8L3.d.mts} +87 -1
- package/dist/packem_shared/{types.d-DGmh5Hq4.d.ts → types.d-F_Q8R8L3.d.ts} +87 -1
- package/dist/rag/index.d.mts +1 -1
- package/dist/rag/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-
|
|
2
|
-
export
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-F_Q8R8L3.mjs";
|
|
2
|
+
export { A as AI_GATEWAY_ACCOUNT_ID_ENV, b as AI_GATEWAY_ID_ENV, c as AI_GATEWAY_TOKEN_ENV, type d as AiBindingLike, type e as AiGatewayMetadata, type f as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, g as buildAiGatewayMetadataFields, r as resolveAiGateway } from "./packem_shared/types.d-F_Q8R8L3.mjs";
|
|
3
3
|
export { type EmbeddingModel, type LanguageModel, embed, embedMany, generateObject, generateText, hasToolCall, jsonSchema, streamObject, streamText, tool } from 'ai';
|
|
4
4
|
export { createWorkersAI } from 'workers-ai-provider';
|
|
5
5
|
/**
|
|
@@ -25,66 +25,4 @@ export { createWorkersAI } from 'workers-ai-provider';
|
|
|
25
25
|
* @experimental
|
|
26
26
|
*/
|
|
27
27
|
declare const createAi: (options: LunoraAiOptions) => LunoraAi;
|
|
28
|
-
|
|
29
|
-
* Correlation metadata folded into the `cf-aig-metadata` request header so a
|
|
30
|
-
* gateway log entry can be tied back to the Lunora function + trace that made
|
|
31
|
-
* the call. Every field is optional — only defined ones are sent.
|
|
32
|
-
* @experimental
|
|
33
|
-
*/
|
|
34
|
-
interface AiGatewayMetadata {
|
|
35
|
-
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
36
|
-
functionPath?: string;
|
|
37
|
-
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
38
|
-
traceId?: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The resolved AI Gateway coordinates.
|
|
42
|
-
*
|
|
43
|
-
* `gatewayId`/`accountId` drive the Workers AI provider's native `gateway` option
|
|
44
|
-
* (Cloudflare routes the binding call internally). `baseURL` + `headers` are for
|
|
45
|
-
* bring-your-own AI SDK providers (`@ai-sdk/openai`, …): append the provider
|
|
46
|
-
* slug to `baseURL` and spread `headers` into the provider config, e.g.
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const gw = resolveAiGateway(env);
|
|
50
|
-
* const openai = createOpenAI(gw ? { baseURL: `${gw.baseURL}/openai`, headers: gw.headers } : {});
|
|
51
|
-
* ```
|
|
52
|
-
* @experimental
|
|
53
|
-
*/
|
|
54
|
-
interface ResolvedAiGateway {
|
|
55
|
-
/** The Cloudflare account id owning the gateway. */
|
|
56
|
-
accountId: string;
|
|
57
|
-
/**
|
|
58
|
-
* The universal gateway base URL:
|
|
59
|
-
* `https://gateway.ai.cloudflare.com/v1/{account}/{gateway}`. Append the
|
|
60
|
-
* provider slug (`/openai`, `/anthropic`, `/workers-ai`, …) per provider.
|
|
61
|
-
*/
|
|
62
|
-
baseURL: string;
|
|
63
|
-
/** The gateway id (slug). */
|
|
64
|
-
gatewayId: string;
|
|
65
|
-
/**
|
|
66
|
-
* Request headers for a gateway-routed call: `cf-aig-authorization` when the
|
|
67
|
-
* gateway is authenticated, and `cf-aig-metadata` when correlation metadata
|
|
68
|
-
* was supplied. Empty object when neither applies.
|
|
69
|
-
*/
|
|
70
|
-
headers: Record<string, string>;
|
|
71
|
-
}
|
|
72
|
-
/** Env var naming the Cloudflare account that owns the gateway. */
|
|
73
|
-
declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
|
|
74
|
-
/** Env var naming the AI Gateway id (the gateway's slug). */
|
|
75
|
-
declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
76
|
-
/** Env var carrying the gateway's authentication token (only for authenticated gateways). */
|
|
77
|
-
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
78
|
-
/**
|
|
79
|
-
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
80
|
-
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
81
|
-
* and `LUNORA_AI_GATEWAY_ID` must be present). Opt-in and backward-compatible:
|
|
82
|
-
* an unconfigured app gets `undefined` and every caller keeps its direct-provider
|
|
83
|
-
* behavior.
|
|
84
|
-
*
|
|
85
|
-
* Pass optional {@link AiGatewayMetadata} to fold a `cf-aig-metadata` correlation
|
|
86
|
-
* header into `headers` — only its defined fields are sent.
|
|
87
|
-
* @experimental
|
|
88
|
-
*/
|
|
89
|
-
declare const resolveAiGateway: (env: Record<string, unknown>, metadata?: AiGatewayMetadata) => ResolvedAiGateway | undefined;
|
|
90
|
-
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, type AiGatewayMetadata, type LunoraAi, type LunoraAiOptions, type ResolvedAiGateway, createAi, resolveAiGateway };
|
|
28
|
+
export { type LunoraAi, type LunoraAiOptions, createAi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-
|
|
2
|
-
export
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-F_Q8R8L3.js";
|
|
2
|
+
export { A as AI_GATEWAY_ACCOUNT_ID_ENV, b as AI_GATEWAY_ID_ENV, c as AI_GATEWAY_TOKEN_ENV, type d as AiBindingLike, type e as AiGatewayMetadata, type f as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, g as buildAiGatewayMetadataFields, r as resolveAiGateway } from "./packem_shared/types.d-F_Q8R8L3.js";
|
|
3
3
|
export { type EmbeddingModel, type LanguageModel, embed, embedMany, generateObject, generateText, hasToolCall, jsonSchema, streamObject, streamText, tool } from 'ai';
|
|
4
4
|
export { createWorkersAI } from 'workers-ai-provider';
|
|
5
5
|
/**
|
|
@@ -25,66 +25,4 @@ export { createWorkersAI } from 'workers-ai-provider';
|
|
|
25
25
|
* @experimental
|
|
26
26
|
*/
|
|
27
27
|
declare const createAi: (options: LunoraAiOptions) => LunoraAi;
|
|
28
|
-
|
|
29
|
-
* Correlation metadata folded into the `cf-aig-metadata` request header so a
|
|
30
|
-
* gateway log entry can be tied back to the Lunora function + trace that made
|
|
31
|
-
* the call. Every field is optional — only defined ones are sent.
|
|
32
|
-
* @experimental
|
|
33
|
-
*/
|
|
34
|
-
interface AiGatewayMetadata {
|
|
35
|
-
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
36
|
-
functionPath?: string;
|
|
37
|
-
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
38
|
-
traceId?: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The resolved AI Gateway coordinates.
|
|
42
|
-
*
|
|
43
|
-
* `gatewayId`/`accountId` drive the Workers AI provider's native `gateway` option
|
|
44
|
-
* (Cloudflare routes the binding call internally). `baseURL` + `headers` are for
|
|
45
|
-
* bring-your-own AI SDK providers (`@ai-sdk/openai`, …): append the provider
|
|
46
|
-
* slug to `baseURL` and spread `headers` into the provider config, e.g.
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const gw = resolveAiGateway(env);
|
|
50
|
-
* const openai = createOpenAI(gw ? { baseURL: `${gw.baseURL}/openai`, headers: gw.headers } : {});
|
|
51
|
-
* ```
|
|
52
|
-
* @experimental
|
|
53
|
-
*/
|
|
54
|
-
interface ResolvedAiGateway {
|
|
55
|
-
/** The Cloudflare account id owning the gateway. */
|
|
56
|
-
accountId: string;
|
|
57
|
-
/**
|
|
58
|
-
* The universal gateway base URL:
|
|
59
|
-
* `https://gateway.ai.cloudflare.com/v1/{account}/{gateway}`. Append the
|
|
60
|
-
* provider slug (`/openai`, `/anthropic`, `/workers-ai`, …) per provider.
|
|
61
|
-
*/
|
|
62
|
-
baseURL: string;
|
|
63
|
-
/** The gateway id (slug). */
|
|
64
|
-
gatewayId: string;
|
|
65
|
-
/**
|
|
66
|
-
* Request headers for a gateway-routed call: `cf-aig-authorization` when the
|
|
67
|
-
* gateway is authenticated, and `cf-aig-metadata` when correlation metadata
|
|
68
|
-
* was supplied. Empty object when neither applies.
|
|
69
|
-
*/
|
|
70
|
-
headers: Record<string, string>;
|
|
71
|
-
}
|
|
72
|
-
/** Env var naming the Cloudflare account that owns the gateway. */
|
|
73
|
-
declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
|
|
74
|
-
/** Env var naming the AI Gateway id (the gateway's slug). */
|
|
75
|
-
declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
76
|
-
/** Env var carrying the gateway's authentication token (only for authenticated gateways). */
|
|
77
|
-
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
78
|
-
/**
|
|
79
|
-
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
80
|
-
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
81
|
-
* and `LUNORA_AI_GATEWAY_ID` must be present). Opt-in and backward-compatible:
|
|
82
|
-
* an unconfigured app gets `undefined` and every caller keeps its direct-provider
|
|
83
|
-
* behavior.
|
|
84
|
-
*
|
|
85
|
-
* Pass optional {@link AiGatewayMetadata} to fold a `cf-aig-metadata` correlation
|
|
86
|
-
* header into `headers` — only its defined fields are sent.
|
|
87
|
-
* @experimental
|
|
88
|
-
*/
|
|
89
|
-
declare const resolveAiGateway: (env: Record<string, unknown>, metadata?: AiGatewayMetadata) => ResolvedAiGateway | undefined;
|
|
90
|
-
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, type AiGatewayMetadata, type LunoraAi, type LunoraAiOptions, type ResolvedAiGateway, createAi, resolveAiGateway };
|
|
28
|
+
export { type LunoraAi, type LunoraAiOptions, createAi };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as createAi } from './packem_shared/createAi-
|
|
2
|
-
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, resolveAiGateway } from './packem_shared/AI_GATEWAY_ACCOUNT_ID_ENV-
|
|
1
|
+
export { default as createAi } from './packem_shared/createAi-Cep3l8Rk.mjs';
|
|
2
|
+
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, buildAiGatewayMetadataFields, resolveAiGateway } from './packem_shared/AI_GATEWAY_ACCOUNT_ID_ENV-CIAjehQF.mjs';
|
|
3
3
|
export { embed, embedMany, generateObject, generateText, hasToolCall, jsonSchema, streamObject, streamText, tool } from 'ai';
|
|
4
4
|
export { createWorkersAI } from 'workers-ai-provider';
|
|
@@ -2,7 +2,7 @@ const readEnv = (env, key) => {
|
|
|
2
2
|
const value = env[key];
|
|
3
3
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
4
4
|
};
|
|
5
|
-
const
|
|
5
|
+
const buildAiGatewayMetadataFields = (metadata) => {
|
|
6
6
|
if (metadata === void 0) {
|
|
7
7
|
return void 0;
|
|
8
8
|
}
|
|
@@ -13,7 +13,11 @@ const encodeMetadata = (metadata) => {
|
|
|
13
13
|
if (typeof metadata.traceId === "string" && metadata.traceId.length > 0) {
|
|
14
14
|
fields["traceId"] = metadata.traceId;
|
|
15
15
|
}
|
|
16
|
-
return Object.keys(fields).length > 0 ?
|
|
16
|
+
return Object.keys(fields).length > 0 ? fields : void 0;
|
|
17
|
+
};
|
|
18
|
+
const encodeMetadata = (metadata) => {
|
|
19
|
+
const fields = buildAiGatewayMetadataFields(metadata);
|
|
20
|
+
return fields === void 0 ? void 0 : JSON.stringify(fields);
|
|
17
21
|
};
|
|
18
22
|
const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
|
|
19
23
|
const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
@@ -41,4 +45,4 @@ const resolveAiGateway = (env, metadata) => {
|
|
|
41
45
|
};
|
|
42
46
|
};
|
|
43
47
|
|
|
44
|
-
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, resolveAiGateway };
|
|
48
|
+
export { AI_GATEWAY_ACCOUNT_ID_ENV, AI_GATEWAY_ID_ENV, AI_GATEWAY_TOKEN_ENV, buildAiGatewayMetadataFields, resolveAiGateway };
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { LunoraError } from '@lunora/errors';
|
|
2
2
|
import { createWorkersAI } from 'workers-ai-provider';
|
|
3
|
-
import { resolveAiGateway } from './AI_GATEWAY_ACCOUNT_ID_ENV-
|
|
3
|
+
import { buildAiGatewayMetadataFields, resolveAiGateway } from './AI_GATEWAY_ACCOUNT_ID_ENV-CIAjehQF.mjs';
|
|
4
4
|
|
|
5
|
-
const resolveGatewayOption = (gateway, env) => {
|
|
5
|
+
const resolveGatewayOption = (gateway, env, metadata) => {
|
|
6
|
+
const metadataFields = buildAiGatewayMetadataFields(metadata);
|
|
6
7
|
if (gateway !== void 0) {
|
|
7
|
-
return gateway;
|
|
8
|
+
return metadataFields !== void 0 && gateway.metadata === void 0 ? { ...gateway, metadata: metadataFields } : gateway;
|
|
8
9
|
}
|
|
9
10
|
if (env === void 0) {
|
|
10
11
|
return void 0;
|
|
11
12
|
}
|
|
12
|
-
const resolved = resolveAiGateway(env);
|
|
13
|
-
|
|
13
|
+
const resolved = resolveAiGateway(env, metadata);
|
|
14
|
+
if (resolved === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return metadataFields === void 0 ? { id: resolved.gatewayId } : { id: resolved.gatewayId, metadata: metadataFields };
|
|
14
18
|
};
|
|
15
19
|
const buildProvider = (binding, gateway) => createWorkersAI({ binding, gateway });
|
|
16
20
|
const createAi = (options) => {
|
|
17
|
-
const { binding, defaultEmbeddingModel, defaultModel, env, gateway, provider } = options;
|
|
21
|
+
const { binding, defaultEmbeddingModel, defaultModel, env, gateway, metadata, provider } = options;
|
|
18
22
|
if (!provider && !binding) {
|
|
19
23
|
throw new LunoraError("INTERNAL", "@lunora/ai: createAi requires a `binding` (env.AI) or a pre-built `provider`");
|
|
20
24
|
}
|
|
21
|
-
const resolvedGateway = resolveGatewayOption(gateway, env);
|
|
25
|
+
const resolvedGateway = resolveGatewayOption(gateway, env, metadata);
|
|
22
26
|
const workersai = provider ?? buildProvider(binding, resolvedGateway);
|
|
23
27
|
const model = (input) => {
|
|
24
28
|
if (input === void 0) {
|
|
@@ -1,4 +1,75 @@
|
|
|
1
1
|
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Project {@link AiGatewayMetadata} to a plain string-map of only its defined,
|
|
4
|
+
* non-empty fields, or `undefined` when nothing is set. This is the shared source
|
|
5
|
+
* of truth behind both gateway-correlation forms: the `cf-aig-metadata` HTTP
|
|
6
|
+
* header (bring-your-own providers) and the Workers AI binding's native
|
|
7
|
+
* `gateway.metadata` option — both encode the same `{ functionPath, traceId }`.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
declare const buildAiGatewayMetadataFields: (metadata: AiGatewayMetadata | undefined) => Record<string, string> | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Correlation metadata folded into the `cf-aig-metadata` request header so a
|
|
13
|
+
* gateway log entry can be tied back to the Lunora function + trace that made
|
|
14
|
+
* the call. Every field is optional — only defined ones are sent.
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
interface AiGatewayMetadata {
|
|
18
|
+
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
19
|
+
functionPath?: string;
|
|
20
|
+
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
21
|
+
traceId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The resolved AI Gateway coordinates.
|
|
25
|
+
*
|
|
26
|
+
* `gatewayId`/`accountId` drive the Workers AI provider's native `gateway` option
|
|
27
|
+
* (Cloudflare routes the binding call internally). `baseURL` + `headers` are for
|
|
28
|
+
* bring-your-own AI SDK providers (`@ai-sdk/openai`, …): append the provider
|
|
29
|
+
* slug to `baseURL` and spread `headers` into the provider config, e.g.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const gw = resolveAiGateway(env);
|
|
33
|
+
* const openai = createOpenAI(gw ? { baseURL: `${gw.baseURL}/openai`, headers: gw.headers } : {});
|
|
34
|
+
* ```
|
|
35
|
+
* @experimental
|
|
36
|
+
*/
|
|
37
|
+
interface ResolvedAiGateway {
|
|
38
|
+
/** The Cloudflare account id owning the gateway. */
|
|
39
|
+
accountId: string;
|
|
40
|
+
/**
|
|
41
|
+
* The universal gateway base URL:
|
|
42
|
+
* `https://gateway.ai.cloudflare.com/v1/{account}/{gateway}`. Append the
|
|
43
|
+
* provider slug (`/openai`, `/anthropic`, `/workers-ai`, …) per provider.
|
|
44
|
+
*/
|
|
45
|
+
baseURL: string;
|
|
46
|
+
/** The gateway id (slug). */
|
|
47
|
+
gatewayId: string;
|
|
48
|
+
/**
|
|
49
|
+
* Request headers for a gateway-routed call: `cf-aig-authorization` when the
|
|
50
|
+
* gateway is authenticated, and `cf-aig-metadata` when correlation metadata
|
|
51
|
+
* was supplied. Empty object when neither applies.
|
|
52
|
+
*/
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
/** Env var naming the Cloudflare account that owns the gateway. */
|
|
56
|
+
declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
|
|
57
|
+
/** Env var naming the AI Gateway id (the gateway's slug). */
|
|
58
|
+
declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
59
|
+
/** Env var carrying the gateway's authentication token (only for authenticated gateways). */
|
|
60
|
+
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
63
|
+
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
64
|
+
* and `LUNORA_AI_GATEWAY_ID` must be present). Opt-in and backward-compatible:
|
|
65
|
+
* an unconfigured app gets `undefined` and every caller keeps its direct-provider
|
|
66
|
+
* behavior.
|
|
67
|
+
*
|
|
68
|
+
* Pass optional {@link AiGatewayMetadata} to fold a `cf-aig-metadata` correlation
|
|
69
|
+
* header into `headers` — only its defined fields are sent.
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
72
|
+
declare const resolveAiGateway: (env: Record<string, unknown>, metadata?: AiGatewayMetadata) => ResolvedAiGateway | undefined;
|
|
2
73
|
/**
|
|
3
74
|
* Structural projection of the Cloudflare Workers `AI` binding (`env.AI`).
|
|
4
75
|
* Declared locally so unit tests can pass a plain-object double and the real
|
|
@@ -30,6 +101,12 @@ interface WorkersAiProviderLike {
|
|
|
30
101
|
interface AiGatewayOptions {
|
|
31
102
|
[key: string]: unknown;
|
|
32
103
|
id: string;
|
|
104
|
+
/**
|
|
105
|
+
* Custom correlation metadata surfaced in the AI Gateway logs (Cloudflare's
|
|
106
|
+
* native `gateway.metadata`). `@lunora/ai` folds `{ functionPath, traceId }`
|
|
107
|
+
* here from {@link LunoraAiOptions.metadata} when a gateway is configured.
|
|
108
|
+
*/
|
|
109
|
+
metadata?: Record<string, string>;
|
|
33
110
|
}
|
|
34
111
|
/**
|
|
35
112
|
* `LunoraAiOptions` is part of the experimental `@lunora/ai` API and may change without a major version bump.
|
|
@@ -71,6 +148,15 @@ interface LunoraAiOptions {
|
|
|
71
148
|
* value wins over anything derived from {@link LunoraAiOptions.env}.
|
|
72
149
|
*/
|
|
73
150
|
gateway?: AiGatewayOptions;
|
|
151
|
+
/**
|
|
152
|
+
* Correlation metadata folded into the active gateway call (the Workers AI
|
|
153
|
+
* binding's native `gateway.metadata`) so an AI Gateway log entry ties back
|
|
154
|
+
* to the Lunora function + trace that made it. Only applied when a gateway is
|
|
155
|
+
* actually configured (explicit or env-derived) and only its defined fields
|
|
156
|
+
* are sent — absent otherwise, so behavior is unchanged. The generated
|
|
157
|
+
* `ctx.ai` facade threads `{ functionPath, traceId }` here automatically.
|
|
158
|
+
*/
|
|
159
|
+
metadata?: AiGatewayMetadata;
|
|
74
160
|
/**
|
|
75
161
|
* Pre-built Workers AI provider. When omitted, one is constructed from
|
|
76
162
|
* `binding` via `createWorkersAI`. Supplying it directly is the seam used by
|
|
@@ -118,4 +204,4 @@ interface LunoraAi {
|
|
|
118
204
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
119
205
|
workersai: WorkersAiProviderLike;
|
|
120
206
|
}
|
|
121
|
-
export {
|
|
207
|
+
export { AI_GATEWAY_ACCOUNT_ID_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_GATEWAY_ID_ENV as b, AI_GATEWAY_TOKEN_ENV as c, AiBindingLike as d, AiGatewayMetadata as e, AiGatewayOptions as f, buildAiGatewayMetadataFields as g, resolveAiGateway as r };
|
|
@@ -1,4 +1,75 @@
|
|
|
1
1
|
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Project {@link AiGatewayMetadata} to a plain string-map of only its defined,
|
|
4
|
+
* non-empty fields, or `undefined` when nothing is set. This is the shared source
|
|
5
|
+
* of truth behind both gateway-correlation forms: the `cf-aig-metadata` HTTP
|
|
6
|
+
* header (bring-your-own providers) and the Workers AI binding's native
|
|
7
|
+
* `gateway.metadata` option — both encode the same `{ functionPath, traceId }`.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
declare const buildAiGatewayMetadataFields: (metadata: AiGatewayMetadata | undefined) => Record<string, string> | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Correlation metadata folded into the `cf-aig-metadata` request header so a
|
|
13
|
+
* gateway log entry can be tied back to the Lunora function + trace that made
|
|
14
|
+
* the call. Every field is optional — only defined ones are sent.
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
interface AiGatewayMetadata {
|
|
18
|
+
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
19
|
+
functionPath?: string;
|
|
20
|
+
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
21
|
+
traceId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The resolved AI Gateway coordinates.
|
|
25
|
+
*
|
|
26
|
+
* `gatewayId`/`accountId` drive the Workers AI provider's native `gateway` option
|
|
27
|
+
* (Cloudflare routes the binding call internally). `baseURL` + `headers` are for
|
|
28
|
+
* bring-your-own AI SDK providers (`@ai-sdk/openai`, …): append the provider
|
|
29
|
+
* slug to `baseURL` and spread `headers` into the provider config, e.g.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const gw = resolveAiGateway(env);
|
|
33
|
+
* const openai = createOpenAI(gw ? { baseURL: `${gw.baseURL}/openai`, headers: gw.headers } : {});
|
|
34
|
+
* ```
|
|
35
|
+
* @experimental
|
|
36
|
+
*/
|
|
37
|
+
interface ResolvedAiGateway {
|
|
38
|
+
/** The Cloudflare account id owning the gateway. */
|
|
39
|
+
accountId: string;
|
|
40
|
+
/**
|
|
41
|
+
* The universal gateway base URL:
|
|
42
|
+
* `https://gateway.ai.cloudflare.com/v1/{account}/{gateway}`. Append the
|
|
43
|
+
* provider slug (`/openai`, `/anthropic`, `/workers-ai`, …) per provider.
|
|
44
|
+
*/
|
|
45
|
+
baseURL: string;
|
|
46
|
+
/** The gateway id (slug). */
|
|
47
|
+
gatewayId: string;
|
|
48
|
+
/**
|
|
49
|
+
* Request headers for a gateway-routed call: `cf-aig-authorization` when the
|
|
50
|
+
* gateway is authenticated, and `cf-aig-metadata` when correlation metadata
|
|
51
|
+
* was supplied. Empty object when neither applies.
|
|
52
|
+
*/
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
/** Env var naming the Cloudflare account that owns the gateway. */
|
|
56
|
+
declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
|
|
57
|
+
/** Env var naming the AI Gateway id (the gateway's slug). */
|
|
58
|
+
declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
59
|
+
/** Env var carrying the gateway's authentication token (only for authenticated gateways). */
|
|
60
|
+
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
63
|
+
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
64
|
+
* and `LUNORA_AI_GATEWAY_ID` must be present). Opt-in and backward-compatible:
|
|
65
|
+
* an unconfigured app gets `undefined` and every caller keeps its direct-provider
|
|
66
|
+
* behavior.
|
|
67
|
+
*
|
|
68
|
+
* Pass optional {@link AiGatewayMetadata} to fold a `cf-aig-metadata` correlation
|
|
69
|
+
* header into `headers` — only its defined fields are sent.
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
72
|
+
declare const resolveAiGateway: (env: Record<string, unknown>, metadata?: AiGatewayMetadata) => ResolvedAiGateway | undefined;
|
|
2
73
|
/**
|
|
3
74
|
* Structural projection of the Cloudflare Workers `AI` binding (`env.AI`).
|
|
4
75
|
* Declared locally so unit tests can pass a plain-object double and the real
|
|
@@ -30,6 +101,12 @@ interface WorkersAiProviderLike {
|
|
|
30
101
|
interface AiGatewayOptions {
|
|
31
102
|
[key: string]: unknown;
|
|
32
103
|
id: string;
|
|
104
|
+
/**
|
|
105
|
+
* Custom correlation metadata surfaced in the AI Gateway logs (Cloudflare's
|
|
106
|
+
* native `gateway.metadata`). `@lunora/ai` folds `{ functionPath, traceId }`
|
|
107
|
+
* here from {@link LunoraAiOptions.metadata} when a gateway is configured.
|
|
108
|
+
*/
|
|
109
|
+
metadata?: Record<string, string>;
|
|
33
110
|
}
|
|
34
111
|
/**
|
|
35
112
|
* `LunoraAiOptions` is part of the experimental `@lunora/ai` API and may change without a major version bump.
|
|
@@ -71,6 +148,15 @@ interface LunoraAiOptions {
|
|
|
71
148
|
* value wins over anything derived from {@link LunoraAiOptions.env}.
|
|
72
149
|
*/
|
|
73
150
|
gateway?: AiGatewayOptions;
|
|
151
|
+
/**
|
|
152
|
+
* Correlation metadata folded into the active gateway call (the Workers AI
|
|
153
|
+
* binding's native `gateway.metadata`) so an AI Gateway log entry ties back
|
|
154
|
+
* to the Lunora function + trace that made it. Only applied when a gateway is
|
|
155
|
+
* actually configured (explicit or env-derived) and only its defined fields
|
|
156
|
+
* are sent — absent otherwise, so behavior is unchanged. The generated
|
|
157
|
+
* `ctx.ai` facade threads `{ functionPath, traceId }` here automatically.
|
|
158
|
+
*/
|
|
159
|
+
metadata?: AiGatewayMetadata;
|
|
74
160
|
/**
|
|
75
161
|
* Pre-built Workers AI provider. When omitted, one is constructed from
|
|
76
162
|
* `binding` via `createWorkersAI`. Supplying it directly is the seam used by
|
|
@@ -118,4 +204,4 @@ interface LunoraAi {
|
|
|
118
204
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
119
205
|
workersai: WorkersAiProviderLike;
|
|
120
206
|
}
|
|
121
|
-
export {
|
|
207
|
+
export { AI_GATEWAY_ACCOUNT_ID_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_GATEWAY_ID_ENV as b, AI_GATEWAY_TOKEN_ENV as c, AiBindingLike as d, AiGatewayMetadata as e, AiGatewayOptions as f, buildAiGatewayMetadataFields as g, resolveAiGateway as r };
|
package/dist/rag/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from 'ai';
|
|
2
|
-
import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-
|
|
2
|
+
import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-F_Q8R8L3.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Built-in fixed-window chunker: split into `size`-char windows overlapping by
|
|
5
5
|
* `overlap` chars. Deliberately simple and deterministic — the zero-config
|
package/dist/rag/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from 'ai';
|
|
2
|
-
import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-
|
|
2
|
+
import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-F_Q8R8L3.js";
|
|
3
3
|
/**
|
|
4
4
|
* Built-in fixed-window chunker: split into `size`-char windows overlapping by
|
|
5
5
|
* `overlap` chars. Deliberately simple and deterministic — the zero-config
|