@lunora/ai 1.0.0-alpha.66 → 1.0.0-alpha.68

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 CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-DYRXBfIT.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-DYRXBfIT.mjs";
1
+ import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-eaM7juQg.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_TOKEN_ENV, type f as AiBindingLike, type g as AiGatewayMetadata, type h as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, i as buildAiGatewayMetadataFields, r as resolveAiGateway } from "./packem_shared/types.d-eaM7juQg.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-DYRXBfIT.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-DYRXBfIT.js";
1
+ import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-eaM7juQg.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_TOKEN_ENV, type f as AiBindingLike, type g as AiGatewayMetadata, type h as AiGatewayOptions, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, i as buildAiGatewayMetadataFields, r as resolveAiGateway } from "./packem_shared/types.d-eaM7juQg.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 o}from"./packem_shared/createAi-DIJS_f7H.mjs";import{AI_GATEWAY_ACCOUNT_ID_ENV as r,AI_GATEWAY_ID_ENV as A,AI_GATEWAY_TOKEN_ENV as _,buildAiGatewayMetadataFields as l,resolveAiGateway as m}from"./packem_shared/AI_GATEWAY_ACCOUNT_ID_ENV-9ptmPAYP.mjs";import{DEFAULT_MODEL_PRICES as E,estimateModelCost as T,lookupModelPrice as d}from"./packem_shared/DEFAULT_MODEL_PRICES-Q8uxdiuV.mjs";import{embed as x,embedMany as I,generateObject as c,generateText as f,hasToolCall as p,jsonSchema as b,streamObject as C,streamText as G,tool as M}from"ai";import{createWorkersAI as O}from"workers-ai-provider";export{r as AI_GATEWAY_ACCOUNT_ID_ENV,A as AI_GATEWAY_ID_ENV,_ as AI_GATEWAY_TOKEN_ENV,E as DEFAULT_MODEL_PRICES,l as buildAiGatewayMetadataFields,o as createAi,O as createWorkersAI,x as embed,I as embedMany,T as estimateModelCost,c as generateObject,f as generateText,p as hasToolCall,b as jsonSchema,d as lookupModelPrice,m as resolveAiGateway,C as streamObject,G as streamText,M as tool};
1
+ import{default as o}from"./packem_shared/createAi-CwY7eL7P.mjs";import{AI_DEFAULT_EMBEDDING_MODEL_ENV as r,AI_DEFAULT_MODEL_ENV as A,AI_GATEWAY_ACCOUNT_ID_ENV as _,AI_GATEWAY_ID_ENV as E,AI_GATEWAY_TOKEN_ENV as l,buildAiGatewayMetadataFields as m,resolveAiGateway as T}from"./packem_shared/AI_DEFAULT_EMBEDDING_MODEL_ENV-mi9Aaq1z.mjs";import{DEFAULT_MODEL_PRICES as D,estimateModelCost as I,lookupModelPrice as d}from"./packem_shared/DEFAULT_MODEL_PRICES-Q8uxdiuV.mjs";import{embed as N,embedMany as i,generateObject as x,generateText as O,hasToolCall as c,jsonSchema as f,streamObject as p,streamText as G,tool as L}from"ai";import{createWorkersAI as C}from"workers-ai-provider";export{r as AI_DEFAULT_EMBEDDING_MODEL_ENV,A as AI_DEFAULT_MODEL_ENV,_ as AI_GATEWAY_ACCOUNT_ID_ENV,E as AI_GATEWAY_ID_ENV,l as AI_GATEWAY_TOKEN_ENV,D as DEFAULT_MODEL_PRICES,m as buildAiGatewayMetadataFields,o as createAi,C as createWorkersAI,N as embed,i as embedMany,I as estimateModelCost,x as generateObject,O as generateText,c as hasToolCall,f as jsonSchema,d as lookupModelPrice,T as resolveAiGateway,p as streamObject,G as streamText,L as tool};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -63,6 +63,30 @@ interface ResolvedAiGateway {
63
63
  */
64
64
  headers: Record<string, string>;
65
65
  }
66
+ /**
67
+ * Env var carrying the default Workers AI **language** model id, used by
68
+ * `ctx.ai.model()` when it is called with no argument.
69
+ *
70
+ * This exists because `env` is the only configuration seam `ctx.ai` has. The
71
+ * generated shard constructs the facade as `createAi({ binding, env, metadata })`
72
+ * with those three fields fixed, so `LunoraAiOptions.defaultModel` — the field
73
+ * `model()` reads — was unreachable from an app: `ctx.ai.model()` with no
74
+ * argument threw, always. Reading the default off `env` puts it back in the
75
+ * app's hands (a wrangler `vars` entry or `.dev.vars` line) without a new
76
+ * constructor argument codegen would have to learn to emit.
77
+ *
78
+ * An explicit `defaultModel` option still wins — the env var is
79
+ * the fallback, exactly as with the gateway vars above.
80
+ */
81
+ declare const AI_DEFAULT_MODEL_ENV = "LUNORA_AI_DEFAULT_MODEL";
82
+ /**
83
+ * Env var carrying the default Workers AI **embedding** model id, used by
84
+ * `ctx.ai.embeddingModel()` with no argument — and so by `defineRag`, whose
85
+ * `embeddingModel` is documented as optional and resolves through exactly that
86
+ * call. Separate from {@link AI_DEFAULT_MODEL_ENV} because a language-model id
87
+ * and an embedding-model id are never interchangeable.
88
+ */
89
+ declare const AI_DEFAULT_EMBEDDING_MODEL_ENV = "LUNORA_AI_DEFAULT_EMBEDDING_MODEL";
66
90
  /** Env var naming the Cloudflare account that owns the gateway. */
67
91
  declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
68
92
  /** Env var naming the AI Gateway id (the gateway's slug). */
@@ -158,21 +182,29 @@ interface LunoraAiOptions {
158
182
  * id belong to different Workers AI families and are never interchangeable —
159
183
  * reusing the language-model default here would defer a wrong-family error to
160
184
  * inference time. Has no effect on bring-your-own providers.
185
+ *
186
+ * Falls back to `LUNORA_AI_DEFAULT_EMBEDDING_MODEL` in {@link LunoraAiOptions.env}
187
+ * — which is how an app sets it, since the generated `ctx.ai` is constructed
188
+ * with a fixed `{ binding, env, metadata }`.
161
189
  */
162
190
  defaultEmbeddingModel?: string;
163
191
  /**
164
192
  * Default Workers AI **language** model id used by `model()` when no explicit
165
193
  * model is passed. For embeddings, set `defaultEmbeddingModel` instead.
166
194
  * Has no effect on bring-your-own providers.
195
+ *
196
+ * Falls back to `LUNORA_AI_DEFAULT_MODEL` in {@link LunoraAiOptions.env} — the
197
+ * seam a Lunora app actually has (see `defaultEmbeddingModel`).
167
198
  */
168
199
  defaultModel?: string;
169
200
  /**
170
201
  * The Worker `env`, read for opt-in Cloudflare AI Gateway routing (the
171
- * `LUNORA_AI_GATEWAY_*` vars, via `resolveAiGateway`). When it configures a
172
- * gateway and no explicit {@link LunoraAiOptions.gateway} is given, the
173
- * Workers AI provider is routed through that gateway so token + dollar-cost
174
- * telemetry is computed on the app's behalf. Unset, or with no gateway vars,
175
- * behavior is unchanged (calls go straight to Workers AI).
202
+ * `LUNORA_AI_GATEWAY_*` vars, via `resolveAiGateway`) and for the default
203
+ * model ids (`LUNORA_AI_DEFAULT_MODEL` / `LUNORA_AI_DEFAULT_EMBEDDING_MODEL`).
204
+ * When it configures a gateway and no explicit {@link LunoraAiOptions.gateway}
205
+ * is given, the Workers AI provider is routed through that gateway so token +
206
+ * dollar-cost telemetry is computed on the app's behalf. Unset, or with no
207
+ * gateway vars, behavior is unchanged (calls go straight to Workers AI).
176
208
  */
177
209
  env?: Record<string, unknown>;
178
210
  /**
@@ -236,4 +268,4 @@ interface LunoraAi {
236
268
  /** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
237
269
  workersai: WorkersAiProviderLike;
238
270
  }
239
- 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 };
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, AI_GATEWAY_TOKEN_ENV as e, AiBindingLike as f, AiGatewayMetadata as g, AiGatewayOptions as h, buildAiGatewayMetadataFields as i, resolveAiGateway as r };
@@ -63,6 +63,30 @@ interface ResolvedAiGateway {
63
63
  */
64
64
  headers: Record<string, string>;
65
65
  }
66
+ /**
67
+ * Env var carrying the default Workers AI **language** model id, used by
68
+ * `ctx.ai.model()` when it is called with no argument.
69
+ *
70
+ * This exists because `env` is the only configuration seam `ctx.ai` has. The
71
+ * generated shard constructs the facade as `createAi({ binding, env, metadata })`
72
+ * with those three fields fixed, so `LunoraAiOptions.defaultModel` — the field
73
+ * `model()` reads — was unreachable from an app: `ctx.ai.model()` with no
74
+ * argument threw, always. Reading the default off `env` puts it back in the
75
+ * app's hands (a wrangler `vars` entry or `.dev.vars` line) without a new
76
+ * constructor argument codegen would have to learn to emit.
77
+ *
78
+ * An explicit `defaultModel` option still wins — the env var is
79
+ * the fallback, exactly as with the gateway vars above.
80
+ */
81
+ declare const AI_DEFAULT_MODEL_ENV = "LUNORA_AI_DEFAULT_MODEL";
82
+ /**
83
+ * Env var carrying the default Workers AI **embedding** model id, used by
84
+ * `ctx.ai.embeddingModel()` with no argument — and so by `defineRag`, whose
85
+ * `embeddingModel` is documented as optional and resolves through exactly that
86
+ * call. Separate from {@link AI_DEFAULT_MODEL_ENV} because a language-model id
87
+ * and an embedding-model id are never interchangeable.
88
+ */
89
+ declare const AI_DEFAULT_EMBEDDING_MODEL_ENV = "LUNORA_AI_DEFAULT_EMBEDDING_MODEL";
66
90
  /** Env var naming the Cloudflare account that owns the gateway. */
67
91
  declare const AI_GATEWAY_ACCOUNT_ID_ENV = "LUNORA_AI_GATEWAY_ACCOUNT_ID";
68
92
  /** Env var naming the AI Gateway id (the gateway's slug). */
@@ -158,21 +182,29 @@ interface LunoraAiOptions {
158
182
  * id belong to different Workers AI families and are never interchangeable —
159
183
  * reusing the language-model default here would defer a wrong-family error to
160
184
  * inference time. Has no effect on bring-your-own providers.
185
+ *
186
+ * Falls back to `LUNORA_AI_DEFAULT_EMBEDDING_MODEL` in {@link LunoraAiOptions.env}
187
+ * — which is how an app sets it, since the generated `ctx.ai` is constructed
188
+ * with a fixed `{ binding, env, metadata }`.
161
189
  */
162
190
  defaultEmbeddingModel?: string;
163
191
  /**
164
192
  * Default Workers AI **language** model id used by `model()` when no explicit
165
193
  * model is passed. For embeddings, set `defaultEmbeddingModel` instead.
166
194
  * Has no effect on bring-your-own providers.
195
+ *
196
+ * Falls back to `LUNORA_AI_DEFAULT_MODEL` in {@link LunoraAiOptions.env} — the
197
+ * seam a Lunora app actually has (see `defaultEmbeddingModel`).
167
198
  */
168
199
  defaultModel?: string;
169
200
  /**
170
201
  * The Worker `env`, read for opt-in Cloudflare AI Gateway routing (the
171
- * `LUNORA_AI_GATEWAY_*` vars, via `resolveAiGateway`). When it configures a
172
- * gateway and no explicit {@link LunoraAiOptions.gateway} is given, the
173
- * Workers AI provider is routed through that gateway so token + dollar-cost
174
- * telemetry is computed on the app's behalf. Unset, or with no gateway vars,
175
- * behavior is unchanged (calls go straight to Workers AI).
202
+ * `LUNORA_AI_GATEWAY_*` vars, via `resolveAiGateway`) and for the default
203
+ * model ids (`LUNORA_AI_DEFAULT_MODEL` / `LUNORA_AI_DEFAULT_EMBEDDING_MODEL`).
204
+ * When it configures a gateway and no explicit {@link LunoraAiOptions.gateway}
205
+ * is given, the Workers AI provider is routed through that gateway so token +
206
+ * dollar-cost telemetry is computed on the app's behalf. Unset, or with no
207
+ * gateway vars, behavior is unchanged (calls go straight to Workers AI).
176
208
  */
177
209
  env?: Record<string, unknown>;
178
210
  /**
@@ -236,4 +268,4 @@ interface LunoraAi {
236
268
  /** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
237
269
  workersai: WorkersAiProviderLike;
238
270
  }
239
- 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 };
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, AI_GATEWAY_TOKEN_ENV as e, AiBindingLike as f, AiGatewayMetadata as g, AiGatewayOptions as h, buildAiGatewayMetadataFields as i, resolveAiGateway as r };
@@ -1,5 +1,5 @@
1
1
  import { Tool } from 'ai';
2
- import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-DYRXBfIT.mjs";
2
+ import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-eaM7juQg.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
@@ -443,7 +443,14 @@ interface RagConfig {
443
443
  /**
444
444
  * Embedding model, declared once so index + retrieve embed identically: a
445
445
  * Workers AI id (e.g. `@cf/baai/bge-base-en-v1.5`) or any AI SDK
446
- * `EmbeddingModel`. Falls back to `createAi`'s `defaultModel` when omitted.
446
+ * `EmbeddingModel`.
447
+ *
448
+ * Omitting it resolves through `ai.embeddingModel(undefined)`, which falls
449
+ * back to `createAi`'s `defaultEmbeddingModel` — NOT `defaultModel`, which
450
+ * this said before and which would be a language-model id in an
451
+ * embedding-model slot. On the generated `ctx.ai` that default comes from
452
+ * `LUNORA_AI_DEFAULT_EMBEDDING_MODEL` in the Worker env; with neither set,
453
+ * the first index/retrieve throws.
447
454
  */
448
455
  embeddingModel?: EmbeddingModelInput;
449
456
  /**
@@ -1,5 +1,5 @@
1
1
  import { Tool } from 'ai';
2
- import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-DYRXBfIT.js";
2
+ import { E as EmbeddingModelInput, a as LunoraAi } from "../packem_shared/types.d-eaM7juQg.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
@@ -443,7 +443,14 @@ interface RagConfig {
443
443
  /**
444
444
  * Embedding model, declared once so index + retrieve embed identically: a
445
445
  * Workers AI id (e.g. `@cf/baai/bge-base-en-v1.5`) or any AI SDK
446
- * `EmbeddingModel`. Falls back to `createAi`'s `defaultModel` when omitted.
446
+ * `EmbeddingModel`.
447
+ *
448
+ * Omitting it resolves through `ai.embeddingModel(undefined)`, which falls
449
+ * back to `createAi`'s `defaultEmbeddingModel` — NOT `defaultModel`, which
450
+ * this said before and which would be a language-model id in an
451
+ * embedding-model slot. On the generated `ctx.ai` that default comes from
452
+ * `LUNORA_AI_DEFAULT_EMBEDDING_MODEL` in the Worker env; with neither set,
453
+ * the first index/retrieve throws.
447
454
  */
448
455
  embeddingModel?: EmbeddingModelInput;
449
456
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/ai",
3
- "version": "1.0.0-alpha.66",
3
+ "version": "1.0.0-alpha.68",
4
4
  "description": "Workers AI helper for Lunora: provider-agnostic AI SDK access from functions, Workers AI by default",
5
5
  "keywords": [
6
6
  "ai",
@@ -53,7 +53,7 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@lunora/errors": "1.0.0-alpha.26",
56
+ "@lunora/errors": "1.0.0-alpha.28",
57
57
  "ai": "7.0.59",
58
58
  "workers-ai-provider": "4.0.0"
59
59
  },
@@ -1 +0,0 @@
1
- const a=(t,o)=>{const e=t[o];return typeof e=="string"&&e.length>0?e:void 0};let d=!1;const u=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},f=t=>{const o=u(t);return o===void 0?void 0:JSON.stringify(o)},h="LUNORA_AI_GATEWAY_ACCOUNT_ID",g="LUNORA_AI_GATEWAY_ID",A="LUNORA_AI_GATEWAY_TOKEN",I=(t,o,e="byo-provider")=>{const n=a(t,h),i=a(t,g);if(n===void 0||i===void 0)return;const s=a(t,A),r={};s!==void 0&&(r["cf-aig-authorization"]=`Bearer ${s}`,e==="workers-ai-binding"&&!d&&(d=!0,console.warn(`[lunora:ai] ${A} 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=f(o);return c!==void 0&&(r["cf-aig-metadata"]=c),{accountId:n,baseURL:`https://gateway.ai.cloudflare.com/v1/${n}/${i}`,gatewayId:i,headers:r}};export{h as AI_GATEWAY_ACCOUNT_ID_ENV,g as AI_GATEWAY_ID_ENV,A as AI_GATEWAY_TOKEN_ENV,u as buildAiGatewayMetadataFields,I as resolveAiGateway};
@@ -1 +0,0 @@
1
- import{LunoraError as t}from"@lunora/errors";import{createWorkersAI as b}from"workers-ai-provider";import{buildAiGatewayMetadataFields as p,resolveAiGateway as A}from"./AI_GATEWAY_ACCOUNT_ID_ENV-9ptmPAYP.mjs";const I=(i,o,l)=>{const d=p(l);if(i!==void 0)return d!==void 0&&i.metadata===void 0?{...i,metadata:d}:i;if(o===void 0)return;const n=A(o,l,"workers-ai-binding");if(n!==void 0)return d===void 0?{id:n.gatewayId}:{id:n.gatewayId,metadata:d}},L=i=>{const{binding:o,defaultEmbeddingModel:l,defaultModel:d,env:n,gateway:f,metadata:c,provider:u}=i;if(!u&&!o)throw new t("INTERNAL","@lunora/ai: createAi requires a `binding` (env.AI) or a pre-built `provider`");const s=I(f,n,c),a=u??b({binding:o,gateway:s}),g=e=>{if(e===void 0){if(!d)throw new t("INTERNAL","@lunora/ai: no model supplied and no `defaultModel` configured — pass a model id or an AI SDK model");return a(d)}return typeof e=="string"?a(e):e},v=e=>{const r=a.textEmbeddingModel;if(typeof r!="function")throw new t("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(a,e)};return{embeddingModel:e=>{if(typeof e=="object")return e;const r=e??l;if(!r)throw new t("INTERNAL","@lunora/ai: no embedding model supplied and no `defaultEmbeddingModel` configured — pass an embedding model id or an AI SDK EmbeddingModel");return v(r)},model:g,run:async(e,r,m)=>{if(!o)throw new t("INTERNAL","@lunora/ai: ai.run requires the `binding` (env.AI) — it is unavailable when only a custom `provider` was supplied");const w=s!==void 0&&m?.gateway===void 0?{...m,gateway:s}:m;return o.run(e,r,w)},workersai:a}};export{L as default};