@lunora/ai 1.0.0-alpha.85 → 1.0.0-alpha.86
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/AI_DEFAULT_EMBEDDING_MODEL_ENV-BEAzcoBw.mjs +1 -0
- package/dist/packem_shared/createAi-CHSAfN98.mjs +1 -0
- package/dist/packem_shared/{types.d-eaM7juQg.d.mts → types.d-D3U2budn.d.mts} +40 -1
- package/dist/packem_shared/{types.d-eaM7juQg.d.ts → types.d-D3U2budn.d.ts} +40 -1
- package/dist/rag/index.d.mts +1 -1
- package/dist/rag/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/AI_DEFAULT_EMBEDDING_MODEL_ENV-mi9Aaq1z.mjs +0 -1
- package/dist/packem_shared/createAi-CwY7eL7P.mjs +0 -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 { A as AI_DEFAULT_EMBEDDING_MODEL_ENV, b as AI_DEFAULT_MODEL_ENV, c as AI_GATEWAY_ACCOUNT_ID_ENV, d as AI_GATEWAY_ID_ENV, e as AI_GATEWAY_TOKEN_ENV, type
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-D3U2budn.mjs";
|
|
2
|
+
export { A as AI_DEFAULT_EMBEDDING_MODEL_ENV, b as AI_DEFAULT_MODEL_ENV, c as AI_GATEWAY_ACCOUNT_ID_ENV, d as AI_GATEWAY_ID_ENV, e as AI_GATEWAY_METADATA_MAX_KEYS, f as AI_GATEWAY_TAGS_ENV, g as AI_GATEWAY_TOKEN_ENV, type h as AiBindingLike, type i as AiGatewayMetadata, type j as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, k as buildAiGatewayMetadataFields, r as readAiGatewayEnvTags, l as resolveAiGateway } from "./packem_shared/types.d-D3U2budn.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
|
/**
|
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 { A as AI_DEFAULT_EMBEDDING_MODEL_ENV, b as AI_DEFAULT_MODEL_ENV, c as AI_GATEWAY_ACCOUNT_ID_ENV, d as AI_GATEWAY_ID_ENV, e as AI_GATEWAY_TOKEN_ENV, type
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-D3U2budn.js";
|
|
2
|
+
export { A as AI_DEFAULT_EMBEDDING_MODEL_ENV, b as AI_DEFAULT_MODEL_ENV, c as AI_GATEWAY_ACCOUNT_ID_ENV, d as AI_GATEWAY_ID_ENV, e as AI_GATEWAY_METADATA_MAX_KEYS, f as AI_GATEWAY_TAGS_ENV, g as AI_GATEWAY_TOKEN_ENV, type h as AiBindingLike, type i as AiGatewayMetadata, type j as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, k as buildAiGatewayMetadataFields, r as readAiGatewayEnvTags, l as resolveAiGateway } from "./packem_shared/types.d-D3U2budn.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
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as
|
|
1
|
+
import{default as _}from"./packem_shared/createAi-CHSAfN98.mjs";import{AI_DEFAULT_EMBEDDING_MODEL_ENV as a,AI_DEFAULT_MODEL_ENV as E,AI_GATEWAY_ACCOUNT_ID_ENV as o,AI_GATEWAY_ID_ENV as r,AI_GATEWAY_METADATA_MAX_KEYS as T,AI_GATEWAY_TAGS_ENV as I,AI_GATEWAY_TOKEN_ENV as l,buildAiGatewayMetadataFields as m,readAiGatewayEnvTags as s,resolveAiGateway as D}from"./packem_shared/AI_DEFAULT_EMBEDDING_MODEL_ENV-BEAzcoBw.mjs";import{DEFAULT_MODEL_PRICES as M,estimateModelCost as d,lookupModelPrice as N}from"./packem_shared/DEFAULT_MODEL_PRICES-Q8uxdiuV.mjs";import{embed as x,embedMany as O,generateObject as c,generateText as f,hasToolCall as p,jsonSchema as L,streamObject as V,streamText as W,tool as Y}from"ai";import{createWorkersAI as n}from"workers-ai-provider";export{a as AI_DEFAULT_EMBEDDING_MODEL_ENV,E as AI_DEFAULT_MODEL_ENV,o as AI_GATEWAY_ACCOUNT_ID_ENV,r as AI_GATEWAY_ID_ENV,T as AI_GATEWAY_METADATA_MAX_KEYS,I as AI_GATEWAY_TAGS_ENV,l as AI_GATEWAY_TOKEN_ENV,M as DEFAULT_MODEL_PRICES,m as buildAiGatewayMetadataFields,_ as createAi,n as createWorkersAI,x as embed,O as embedMany,d as estimateModelCost,c as generateObject,f as generateText,p as hasToolCall,L as jsonSchema,N as lookupModelPrice,s as readAiGatewayEnvTags,D as resolveAiGateway,V as streamObject,W as streamText,Y as tool};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=(t,e)=>{if(t===void 0)return;const o=t[e];return typeof o=="string"&&o.length>0?o:void 0};let A=!1,d=!1;const f=5,l=t=>{if(t===void 0)return;const e={};for(const[n,r]of Object.entries(t.tags??{}))typeof r=="string"&&r.length>0&&n.length>0&&(e[n]=r);typeof t.functionPath=="string"&&t.functionPath.length>0&&(e.functionPath=t.functionPath),typeof t.traceId=="string"&&t.traceId.length>0&&(e.traceId=t.traceId);const o=Object.keys(e);if(o.length===0)return;if(o.length<=f)return e;const i=o.slice(-f);return Object.fromEntries(i.map(n=>[n,e[n]]))},E=t=>{const e=l(t);return e===void 0?void 0:JSON.stringify(e)},I="LUNORA_AI_DEFAULT_MODEL",y="LUNORA_AI_DEFAULT_EMBEDDING_MODEL",g="LUNORA_AI_GATEWAY_ACCOUNT_ID",h="LUNORA_AI_GATEWAY_ID",_="LUNORA_AI_GATEWAY_TOKEN",u="LUNORA_AI_GATEWAY_TAGS",T=t=>{const e=a(t,u);if(e!==void 0)try{const o=JSON.parse(e);if(typeof o!="object"||o===null||Array.isArray(o))throw new TypeError("expected a JSON object");const i={};for(const[n,r]of Object.entries(o))typeof r=="string"&&r.length>0&&(i[n]=r);return Object.keys(i).length>0?i:void 0}catch{d||(d=!0,console.warn(`[lunora:ai] ${u} is not a flat JSON object of strings — AI Gateway tags from it are ignored.`));return}},v=(t,e,o="byo-provider")=>{const i=a(t,g),n=a(t,h);if(i===void 0||n===void 0)return;const r=a(t,_),s={};r!==void 0&&(s["cf-aig-authorization"]=`Bearer ${r}`,o==="workers-ai-binding"&&!A&&(A=!0,console.warn(`[lunora:ai] ${_} is set, but the Workers AI binding cannot send a gateway auth token — Cloudflare's native gateway option has no authorization field. The token is ignored on this path; use a bring-your-own AI SDK provider (which sends cf-aig-authorization), or make the AI Gateway unauthenticated for Workers AI.`)));const c=E(e);return c!==void 0&&(s["cf-aig-metadata"]=c),{accountId:i,baseURL:`https://gateway.ai.cloudflare.com/v1/${i}/${n}`,gatewayId:n,headers:s}};export{y as AI_DEFAULT_EMBEDDING_MODEL_ENV,I as AI_DEFAULT_MODEL_ENV,g as AI_GATEWAY_ACCOUNT_ID_ENV,h as AI_GATEWAY_ID_ENV,f as AI_GATEWAY_METADATA_MAX_KEYS,u as AI_GATEWAY_TAGS_ENV,_ as AI_GATEWAY_TOKEN_ENV,l as buildAiGatewayMetadataFields,T as readAiGatewayEnvTags,a as readEnv,v as resolveAiGateway};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{createWorkersAI as M}from"workers-ai-provider";import{readEnv as g,AI_DEFAULT_MODEL_ENV as w,AI_DEFAULT_EMBEDDING_MODEL_ENV as E,readAiGatewayEnvTags as y,buildAiGatewayMetadataFields as N,resolveAiGateway as h}from"./AI_DEFAULT_EMBEDDING_MODEL_ENV-BEAzcoBw.mjs";const D=(d,o,n)=>{const v=o===void 0?void 0:y(o),a=v===void 0?n:{...n,tags:{...v,...n?.tags}},t=N(a);if(d!==void 0)return t!==void 0&&d.metadata===void 0?{...d,metadata:t}:d;if(o===void 0)return;const i=h(o,a,"workers-ai-binding");if(i!==void 0)return t===void 0?{id:i.gatewayId}:{id:i.gatewayId,metadata:t}},R=d=>{const{binding:o,defaultEmbeddingModel:n,defaultModel:v,env:a,gateway:t,metadata:i,provider:c}=d;if(!c&&!o)throw new l("INTERNAL","@lunora/ai: createAi requires a `binding` (env.AI) or a pre-built `provider`");const f=D(t,a,i),m=v??g(a,w),b=n??g(a,E),s=c??M({binding:o,gateway:f}),A=e=>{if(e===void 0){if(!m)throw new l("INTERNAL",`@lunora/ai: no model supplied and no default configured — pass a model id, or set ${w} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return s(m)}return typeof e=="string"?s(e):e},p=e=>{const r=s.textEmbeddingModel;if(typeof r!="function")throw new l("INTERNAL","@lunora/ai: the Workers AI provider does not expose `textEmbeddingModel`; pass an AI SDK EmbeddingModel (e.g. from @ai-sdk/openai) to embed()");return r.call(s,e)};return{embeddingModel:e=>{if(typeof e=="object")return e;const r=e??b;if(!r)throw new l("INTERNAL",`@lunora/ai: no embedding model supplied and no default configured — pass an embedding model id or an AI SDK EmbeddingModel, or set ${E} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return p(r)},model:A,run:async(e,r,u)=>{if(!o)throw new l("INTERNAL","@lunora/ai: ai.run requires the `binding` (env.AI) — it is unavailable when only a custom `provider` was supplied");const I=f!==void 0&&u?.gateway===void 0?{...u,gateway:f}:u;return o.run(e,r,I)},workersai:s}};export{R as default};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* AI Gateway's hard limit on `cf-aig-metadata` keys. Exceeding it makes the
|
|
4
|
+
* gateway reject the metadata object entirely, so the builder trims to this
|
|
5
|
+
* rather than sending something that will be thrown away.
|
|
6
|
+
*/
|
|
7
|
+
declare const AI_GATEWAY_METADATA_MAX_KEYS = 5;
|
|
2
8
|
/**
|
|
3
9
|
* Project {@link AiGatewayMetadata} to a plain string-map of only its defined,
|
|
4
10
|
* non-empty fields, or `undefined` when nothing is set. This is the shared source
|
|
@@ -28,6 +34,21 @@ type AiGatewayConsumer = "byo-provider" | "workers-ai-binding";
|
|
|
28
34
|
interface AiGatewayMetadata {
|
|
29
35
|
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
30
36
|
functionPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* App-supplied correlation tags — what the app slices its own AI spend by:
|
|
39
|
+
* feature, plan, tenant, a hashed user id. AI Gateway's cost filtering can
|
|
40
|
+
* only group by keys that were sent WITH the call, so a tag not set here is
|
|
41
|
+
* a question that cannot be asked later.
|
|
42
|
+
*
|
|
43
|
+
* Merged under the built-in fields, which win on a key collision, and
|
|
44
|
+
* trimmed to AI Gateway's {@link AI_GATEWAY_METADATA_MAX_KEYS}-key limit —
|
|
45
|
+
* over it, the gateway rejects the metadata outright and the correlation is
|
|
46
|
+
* lost rather than truncated.
|
|
47
|
+
*
|
|
48
|
+
* Values should stay low-cardinality for the same reason a route label
|
|
49
|
+
* does: a raw user id per call makes every call its own group. Hash it.
|
|
50
|
+
*/
|
|
51
|
+
tags?: Record<string, string>;
|
|
31
52
|
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
32
53
|
traceId?: string;
|
|
33
54
|
}
|
|
@@ -107,6 +128,24 @@ declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
|
107
128
|
* set on the binding path.
|
|
108
129
|
*/
|
|
109
130
|
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
131
|
+
/**
|
|
132
|
+
* Env var carrying deployment-scoped AI Gateway tags as a flat JSON object of
|
|
133
|
+
* string values, e.g. `{"app":"checkout","env":"prod"}`.
|
|
134
|
+
*
|
|
135
|
+
* Deployment-scoped because that is the dimension you cannot recover in code:
|
|
136
|
+
* AI Gateway can only filter cost by keys that were sent WITH the call, and
|
|
137
|
+
* "which environment / which app spent this" is fixed at deploy time. Per-call
|
|
138
|
+
* tags (feature, hashed user) go through {@link AiGatewayMetadata.tags}
|
|
139
|
+
* instead. A malformed value is ignored with a warning rather than failing the
|
|
140
|
+
* call — telemetry configuration must not take inference down.
|
|
141
|
+
*/
|
|
142
|
+
declare const AI_GATEWAY_TAGS_ENV = "LUNORA_AI_GATEWAY_TAGS";
|
|
143
|
+
/**
|
|
144
|
+
* Parse {@link AI_GATEWAY_TAGS_ENV} into tag fields. Non-string values are
|
|
145
|
+
* dropped rather than coerced — a number silently becoming `"1"` is a worse
|
|
146
|
+
* outcome than the tag being absent and visibly so.
|
|
147
|
+
*/
|
|
148
|
+
declare const readAiGatewayEnvTags: (env: Record<string, unknown>) => Record<string, string> | undefined;
|
|
110
149
|
/**
|
|
111
150
|
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
112
151
|
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
@@ -268,4 +307,4 @@ interface LunoraAi {
|
|
|
268
307
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
269
308
|
workersai: WorkersAiProviderLike;
|
|
270
309
|
}
|
|
271
|
-
export { AI_DEFAULT_EMBEDDING_MODEL_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_DEFAULT_MODEL_ENV as b, AI_GATEWAY_ACCOUNT_ID_ENV as c, AI_GATEWAY_ID_ENV as d,
|
|
310
|
+
export { AI_DEFAULT_EMBEDDING_MODEL_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_DEFAULT_MODEL_ENV as b, AI_GATEWAY_ACCOUNT_ID_ENV as c, AI_GATEWAY_ID_ENV as d, AI_GATEWAY_METADATA_MAX_KEYS as e, AI_GATEWAY_TAGS_ENV as f, AI_GATEWAY_TOKEN_ENV as g, AiBindingLike as h, AiGatewayMetadata as i, AiGatewayOptions as j, buildAiGatewayMetadataFields as k, resolveAiGateway as l, readAiGatewayEnvTags as r };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* AI Gateway's hard limit on `cf-aig-metadata` keys. Exceeding it makes the
|
|
4
|
+
* gateway reject the metadata object entirely, so the builder trims to this
|
|
5
|
+
* rather than sending something that will be thrown away.
|
|
6
|
+
*/
|
|
7
|
+
declare const AI_GATEWAY_METADATA_MAX_KEYS = 5;
|
|
2
8
|
/**
|
|
3
9
|
* Project {@link AiGatewayMetadata} to a plain string-map of only its defined,
|
|
4
10
|
* non-empty fields, or `undefined` when nothing is set. This is the shared source
|
|
@@ -28,6 +34,21 @@ type AiGatewayConsumer = "byo-provider" | "workers-ai-binding";
|
|
|
28
34
|
interface AiGatewayMetadata {
|
|
29
35
|
/** The Lunora function path that issued the model call (e.g. `messages:send`). */
|
|
30
36
|
functionPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* App-supplied correlation tags — what the app slices its own AI spend by:
|
|
39
|
+
* feature, plan, tenant, a hashed user id. AI Gateway's cost filtering can
|
|
40
|
+
* only group by keys that were sent WITH the call, so a tag not set here is
|
|
41
|
+
* a question that cannot be asked later.
|
|
42
|
+
*
|
|
43
|
+
* Merged under the built-in fields, which win on a key collision, and
|
|
44
|
+
* trimmed to AI Gateway's {@link AI_GATEWAY_METADATA_MAX_KEYS}-key limit —
|
|
45
|
+
* over it, the gateway rejects the metadata outright and the correlation is
|
|
46
|
+
* lost rather than truncated.
|
|
47
|
+
*
|
|
48
|
+
* Values should stay low-cardinality for the same reason a route label
|
|
49
|
+
* does: a raw user id per call makes every call its own group. Hash it.
|
|
50
|
+
*/
|
|
51
|
+
tags?: Record<string, string>;
|
|
31
52
|
/** The 32-hex trace id the call belongs to, so the gateway log joins the trace. */
|
|
32
53
|
traceId?: string;
|
|
33
54
|
}
|
|
@@ -107,6 +128,24 @@ declare const AI_GATEWAY_ID_ENV = "LUNORA_AI_GATEWAY_ID";
|
|
|
107
128
|
* set on the binding path.
|
|
108
129
|
*/
|
|
109
130
|
declare const AI_GATEWAY_TOKEN_ENV = "LUNORA_AI_GATEWAY_TOKEN";
|
|
131
|
+
/**
|
|
132
|
+
* Env var carrying deployment-scoped AI Gateway tags as a flat JSON object of
|
|
133
|
+
* string values, e.g. `{"app":"checkout","env":"prod"}`.
|
|
134
|
+
*
|
|
135
|
+
* Deployment-scoped because that is the dimension you cannot recover in code:
|
|
136
|
+
* AI Gateway can only filter cost by keys that were sent WITH the call, and
|
|
137
|
+
* "which environment / which app spent this" is fixed at deploy time. Per-call
|
|
138
|
+
* tags (feature, hashed user) go through {@link AiGatewayMetadata.tags}
|
|
139
|
+
* instead. A malformed value is ignored with a warning rather than failing the
|
|
140
|
+
* call — telemetry configuration must not take inference down.
|
|
141
|
+
*/
|
|
142
|
+
declare const AI_GATEWAY_TAGS_ENV = "LUNORA_AI_GATEWAY_TAGS";
|
|
143
|
+
/**
|
|
144
|
+
* Parse {@link AI_GATEWAY_TAGS_ENV} into tag fields. Non-string values are
|
|
145
|
+
* dropped rather than coerced — a number silently becoming `"1"` is a worse
|
|
146
|
+
* outcome than the tag being absent and visibly so.
|
|
147
|
+
*/
|
|
148
|
+
declare const readAiGatewayEnvTags: (env: Record<string, unknown>) => Record<string, string> | undefined;
|
|
110
149
|
/**
|
|
111
150
|
* Resolve the Cloudflare AI Gateway coordinates from the Worker `env`, or
|
|
112
151
|
* `undefined` when the gateway is not configured (both `LUNORA_AI_GATEWAY_ACCOUNT_ID`
|
|
@@ -268,4 +307,4 @@ interface LunoraAi {
|
|
|
268
307
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
269
308
|
workersai: WorkersAiProviderLike;
|
|
270
309
|
}
|
|
271
|
-
export { AI_DEFAULT_EMBEDDING_MODEL_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_DEFAULT_MODEL_ENV as b, AI_GATEWAY_ACCOUNT_ID_ENV as c, AI_GATEWAY_ID_ENV as d,
|
|
310
|
+
export { AI_DEFAULT_EMBEDDING_MODEL_ENV as A, EmbeddingModelInput as E, LunoraAiOptions as L, ModelInput as M, ResolvedAiGateway as R, WorkersAiProviderLike as W, LunoraAi as a, AI_DEFAULT_MODEL_ENV as b, AI_GATEWAY_ACCOUNT_ID_ENV as c, AI_GATEWAY_ID_ENV as d, AI_GATEWAY_METADATA_MAX_KEYS as e, AI_GATEWAY_TAGS_ENV as f, AI_GATEWAY_TOKEN_ENV as g, AiBindingLike as h, AiGatewayMetadata as i, AiGatewayOptions as j, buildAiGatewayMetadataFields as k, resolveAiGateway as l, readAiGatewayEnvTags 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-D3U2budn.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-D3U2budn.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
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const a=(t,o)=>{if(t===void 0)return;const n=t[o];return typeof n=="string"&&n.length>0?n:void 0};let c=!1;const _=t=>{if(t===void 0)return;const o={};return typeof t.functionPath=="string"&&t.functionPath.length>0&&(o.functionPath=t.functionPath),typeof t.traceId=="string"&&t.traceId.length>0&&(o.traceId=t.traceId),Object.keys(o).length>0?o:void 0},u=t=>{const o=_(t);return o===void 0?void 0:JSON.stringify(o)},I="LUNORA_AI_DEFAULT_MODEL",h="LUNORA_AI_DEFAULT_EMBEDDING_MODEL",f="LUNORA_AI_GATEWAY_ACCOUNT_ID",E="LUNORA_AI_GATEWAY_ID",d="LUNORA_AI_GATEWAY_TOKEN",g=(t,o,n="byo-provider")=>{const e=a(t,f),i=a(t,E);if(e===void 0||i===void 0)return;const s=a(t,d),r={};s!==void 0&&(r["cf-aig-authorization"]=`Bearer ${s}`,n==="workers-ai-binding"&&!c&&(c=!0,console.warn(`[lunora:ai] ${d} is set, but the Workers AI binding cannot send a gateway auth token — Cloudflare's native gateway option has no authorization field. The token is ignored on this path; use a bring-your-own AI SDK provider (which sends cf-aig-authorization), or make the AI Gateway unauthenticated for Workers AI.`)));const A=u(o);return A!==void 0&&(r["cf-aig-metadata"]=A),{accountId:e,baseURL:`https://gateway.ai.cloudflare.com/v1/${e}/${i}`,gatewayId:i,headers:r}};export{h as AI_DEFAULT_EMBEDDING_MODEL_ENV,I as AI_DEFAULT_MODEL_ENV,f as AI_GATEWAY_ACCOUNT_ID_ENV,E as AI_GATEWAY_ID_ENV,d as AI_GATEWAY_TOKEN_ENV,_ as buildAiGatewayMetadataFields,a as readEnv,g as resolveAiGateway};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";import{createWorkersAI as M}from"workers-ai-provider";import{readEnv as m,AI_DEFAULT_MODEL_ENV as c,AI_DEFAULT_EMBEDDING_MODEL_ENV as g,buildAiGatewayMetadataFields as y,resolveAiGateway as N}from"./AI_DEFAULT_EMBEDDING_MODEL_ENV-mi9Aaq1z.mjs";const h=(n,o,s)=>{const a=y(s);if(n!==void 0)return a!==void 0&&n.metadata===void 0?{...n,metadata:a}:n;if(o===void 0)return;const r=N(o,s,"workers-ai-binding");if(r!==void 0)return a===void 0?{id:r.gatewayId}:{id:r.gatewayId,metadata:a}},G=n=>{const{binding:o,defaultEmbeddingModel:s,defaultModel:a,env:r,gateway:w,metadata:E,provider:u}=n;if(!u&&!o)throw new i("INTERNAL","@lunora/ai: createAi requires a `binding` (env.AI) or a pre-built `provider`");const l=h(w,r,E),f=a??m(r,c),b=s??m(r,g),t=u??M({binding:o,gateway:l}),A=e=>{if(e===void 0){if(!f)throw new i("INTERNAL",`@lunora/ai: no model supplied and no default configured — pass a model id, or set ${c} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return t(f)}return typeof e=="string"?t(e):e},p=e=>{const d=t.textEmbeddingModel;if(typeof d!="function")throw new i("INTERNAL","@lunora/ai: the Workers AI provider does not expose `textEmbeddingModel`; pass an AI SDK EmbeddingModel (e.g. from @ai-sdk/openai) to embed()");return d.call(t,e)};return{embeddingModel:e=>{if(typeof e=="object")return e;const d=e??b;if(!d)throw new i("INTERNAL",`@lunora/ai: no embedding model supplied and no default configured — pass an embedding model id or an AI SDK EmbeddingModel, or set ${g} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return p(d)},model:A,run:async(e,d,v)=>{if(!o)throw new i("INTERNAL","@lunora/ai: ai.run requires the `binding` (env.AI) — it is unavailable when only a custom `provider` was supplied");const I=l!==void 0&&v?.gateway===void 0?{...v,gateway:l}:v;return o.run(e,d,I)},workersai:t}};export{G as default};
|