@lunora/ai 1.0.0-alpha.104 → 1.0.0-alpha.105
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/createAi-D76ClNVB.mjs +1 -0
- package/dist/packem_shared/{types.d-BNOWTjHf.d.mts → types.d-ChtZguP_.d.mts} +33 -3
- package/dist/packem_shared/{types.d-BNOWTjHf.d.ts → types.d-ChtZguP_.d.ts} +33 -3
- package/dist/rag/index.d.mts +1 -1
- package/dist/rag/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/createAi-CdiXSCUA.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_METADATA_MAX_KEYS, f as AI_GATEWAY_TAGS_ENV, g as AI_GATEWAY_TOKEN_ENV, h as AI_PROXY_TOKEN_ENV, i as AI_PROXY_URL_ENV, type j as AiBindingLike, type k as AiGatewayMetadata, type l as AiGatewayOptions, type m as AiMetrics, type n as
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-ChtZguP_.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, h as AI_PROXY_TOKEN_ENV, i as AI_PROXY_URL_ENV, type j as AiBindingLike, type k as AiGatewayMetadata, type l as AiGatewayOptions, type m as AiMetrics, type n as AiModelOptions, type o as AiRunOptions, type p as AiSpan, type q as AiTelemetry, type r as AiTracer, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, s as buildAiGatewayMetadataFields, t as readAiGatewayEnvTags, u as resolveAiGateway } from "./packem_shared/types.d-ChtZguP_.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_METADATA_MAX_KEYS, f as AI_GATEWAY_TAGS_ENV, g as AI_GATEWAY_TOKEN_ENV, h as AI_PROXY_TOKEN_ENV, i as AI_PROXY_URL_ENV, type j as AiBindingLike, type k as AiGatewayMetadata, type l as AiGatewayOptions, type m as AiMetrics, type n as
|
|
1
|
+
import { L as LunoraAiOptions, a as LunoraAi } from "./packem_shared/types.d-ChtZguP_.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, h as AI_PROXY_TOKEN_ENV, i as AI_PROXY_URL_ENV, type j as AiBindingLike, type k as AiGatewayMetadata, type l as AiGatewayOptions, type m as AiMetrics, type n as AiModelOptions, type o as AiRunOptions, type p as AiSpan, type q as AiTelemetry, type r as AiTracer, type E as EmbeddingModelInput, type M as ModelInput, type R as ResolvedAiGateway, type W as WorkersAiProviderLike, s as buildAiGatewayMetadataFields, t as readAiGatewayEnvTags, u as resolveAiGateway } from "./packem_shared/types.d-ChtZguP_.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 _}from"./packem_shared/createAi-
|
|
1
|
+
import{default as _}from"./packem_shared/createAi-D76ClNVB.mjs";import{AI_DEFAULT_EMBEDDING_MODEL_ENV as t,AI_DEFAULT_MODEL_ENV as a,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 N,AI_PROXY_TOKEN_ENV as l,AI_PROXY_URL_ENV as m,buildAiGatewayMetadataFields as s,readAiGatewayEnvTags as D,resolveAiGateway as G}from"./packem_shared/AI_DEFAULT_EMBEDDING_MODEL_ENV-IwcHZiKj.mjs";import{DEFAULT_MODEL_PRICES as O,estimateModelCost as d,lookupModelPrice as i}from"./packem_shared/DEFAULT_MODEL_PRICES-CIJLs1Ah.mjs";import{embed as Y,embedMany as x,generateObject as L,generateText as c,hasToolCall as f,jsonSchema as p,streamObject as W,streamText as b,tool as n}from"ai";import{createWorkersAI as U}from"workers-ai-provider";export{t as AI_DEFAULT_EMBEDDING_MODEL_ENV,a 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,N as AI_GATEWAY_TOKEN_ENV,l as AI_PROXY_TOKEN_ENV,m as AI_PROXY_URL_ENV,O as DEFAULT_MODEL_PRICES,s as buildAiGatewayMetadataFields,_ as createAi,U as createWorkersAI,Y as embed,x as embedMany,d as estimateModelCost,L as generateObject,c as generateText,f as hasToolCall,p as jsonSchema,i as lookupModelPrice,D as readAiGatewayEnvTags,G as resolveAiGateway,W as streamObject,b as streamText,n as tool};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createOpenAI as S}from"@ai-sdk/openai";import{LunoraError as E}from"@lunora/errors";import{createWorkersAI as $}from"workers-ai-provider";import{anthropic as C}from"workers-ai-provider/anthropic";import{openai as W}from"workers-ai-provider/openai";import{buildAiGatewayMetadataFields as D,readEnv as A,AI_DEFAULT_MODEL_ENV as M,AI_DEFAULT_EMBEDDING_MODEL_ENV as I,AI_PROXY_URL_ENV as h,AI_PROXY_TOKEN_ENV as R,readAiGatewayEnvTags as j,AI_GATEWAY_ID_ENV as B,warnIgnoredBindingToken as V}from"./AI_DEFAULT_EMBEDDING_MODEL_ENV-IwcHZiKj.mjs";import{wrapLanguageModel as Y}from"ai";import{m as F,r as T}from"./usage-GPnTSqR8.mjs";import"./DEFAULT_MODEL_PRICES-CIJLs1Ah.mjs";const K={setAttribute:()=>{},setAttributes:()=>{}},O=async(e,t)=>t(O,K),q=(e,{metrics:t,trace:n=O})=>{const a={"gen_ai.operation.name":"chat","gen_ai.request.model":e};return{wrapGenerate:async({doGenerate:o})=>n("ai.generate",async(u,m)=>{const g=await o();return T(e,g,m,t),g},a),wrapStream:async({doStream:o})=>{const u=(w,s)=>{const c=w.stream.getReader();let l={};return{...w,stream:new ReadableStream({cancel:async f=>{s({outcome:l}),await c.cancel(f)},pull:async f=>{let v;try{v=await c.read()}catch(y){s({error:y,failed:!0,outcome:l}),f.error(y);return}if(v.done){s({outcome:l}),f.close();return}v.value.type==="finish"&&(l={providerMetadata:v.value.providerMetadata,usage:v.value.usage}),f.enqueue(v.value)}})}},m=Promise.withResolvers(),g=Promise.withResolvers();return n("ai.stream",async(w,s)=>{m.resolve(u(await o(),g.resolve));const c=await g.promise;if(T(e,c.outcome,s,t),c.failed===!0)throw c.error},a).catch(m.reject),m.promise}}},L=(e,t,n)=>{let a=e;return t!==void 0&&typeof e!="string"&&(a=Y({middleware:q(n??F(e)??"unknown",t),model:e})),a},X=[W,C],N=e=>!e.startsWith("@")&&e.includes("/"),b=e=>{throw new E("INTERNAL",`@lunora/ai: ${e} needs the \`AI\` binding (env.AI). Add an \`ai\` binding to wrangler.jsonc, or set ${h} to an OpenAI-compatible proxy for "<provider>/<model>" slugs.`)},P=()=>b("this model id");P.textEmbeddingModel=()=>b("this embedding model id");const H=3040,Z=/^(?:[A-Z]\w*:\s*)?3040\s*:/iu,z=e=>e?.code===H||e instanceof Error&&Z.test(e.message),J=new Set(["127.0.0.1","[::1]","localhost"]),Q=e=>{const t=A(e,h);if(t===void 0)return;const n=A(e,R),a=URL.canParse(t)?new URL(t):void 0;let o;if(a===void 0?o=`${h} is not a valid URL`:n!==void 0&&a.protocol!=="https:"&&!J.has(a.hostname)&&(o=`${h} (${a.origin}) is not HTTPS, so ${R} would travel in cleartext — use an https:// URL`),o!==void 0){const u=()=>{throw new E("INTERNAL",`@lunora/ai: ${o}`)};return{chat:u,embedding:u}}return S({apiKey:n??"",baseURL:t,name:"lunora-proxy"})},ee=(e,t)=>{const n=e===void 0?void 0:j(e);return n===void 0?t:{...t,tags:{...n,...t?.tags}}},te=(e,t,n)=>{const a=D(n);if(e!==void 0)return a!==void 0&&e.metadata===void 0?{...e,metadata:a}:e;if(t===void 0)return;const o=A(t,B);if(o!==void 0)return V(t),a===void 0?{id:o}:{id:o,metadata:a}},ve=e=>{const{binding:t,defaultEmbeddingModel:n,defaultModel:a,env:o,gateway:u,metadata:m,provider:g,telemetry:w}=e,s=Q(o),c=ee(o,m),l=te(u,o,c),f=u?.metadata===void 0?D(c):void 0,v=a??A(o,M),y=n??A(o,I),p=g??(t?$({binding:t,gateway:l,providers:X}):P),x=(r,i)=>N(r)?s!==void 0?s.chat(r):f===void 0?p(r):p(r,{metadata:f}):i?.rejectIfBusy===void 0?p(r):p(r,{rejectIfBusy:i.rejectIfBusy}),U=(r,i)=>{const d=r??v;if(d===void 0||d==="")throw new E("INTERNAL",`@lunora/ai: no model supplied and no default configured — pass a model id, or set ${M} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return typeof d=="string"?L(x(d,i),w,d):L(d,w)},k=r=>{if(s!==void 0&&N(r))return s.embedding(r);const i=p.textEmbeddingModel;if(typeof i!="function")throw new E("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 i.call(p,r)};return{embeddingModel:r=>{if(typeof r=="object")return r;const i=r??y;if(!i)throw new E("INTERNAL",`@lunora/ai: no embedding model supplied and no default configured — pass an embedding model id or an AI SDK EmbeddingModel, or set ${I} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return k(i)},model:U,run:async(r,i,d)=>{if(!t)return b("ai.run");const G=l!==void 0&&d?.gateway===void 0?{...d,gateway:l}:d;try{return await t.run(r,i,G)}catch(_){throw z(_)?new E("RATE_LIMITED",`@lunora/ai: Workers AI has no free capacity for ${r} (error 3040) — retry later`,{cause:_}):_}},workersai:p}};export{ve as default};
|
|
@@ -216,6 +216,36 @@ interface AiGatewayOptions {
|
|
|
216
216
|
*/
|
|
217
217
|
metadata?: Record<string, string>;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Options for the raw `ctx.ai.run(...)` passthrough — the Workers AI binding's
|
|
221
|
+
* third argument. Unlisted keys are forwarded to the binding unchanged.
|
|
222
|
+
* @experimental
|
|
223
|
+
*/
|
|
224
|
+
interface AiRunOptions {
|
|
225
|
+
[key: string]: unknown;
|
|
226
|
+
/** Route this call through a Cloudflare AI Gateway. Defaults to the gateway `createAi` resolved. */
|
|
227
|
+
gateway?: AiGatewayOptions;
|
|
228
|
+
/**
|
|
229
|
+
* Fail at once instead of waiting in the Workers AI capacity queue when no
|
|
230
|
+
* capacity is free. The rejection surfaces as a `LunoraError` with code
|
|
231
|
+
* `RATE_LIMITED` (Workers AI error `3040`, HTTP 429).
|
|
232
|
+
*/
|
|
233
|
+
rejectIfBusy?: boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Per-call settings for `ctx.ai.model(...)`. Applied to Workers AI model ids
|
|
237
|
+
* (`@cf/…`) only; a gateway slug or a bring-your-own model ignores them.
|
|
238
|
+
* @experimental
|
|
239
|
+
*/
|
|
240
|
+
interface AiModelOptions {
|
|
241
|
+
/**
|
|
242
|
+
* Fail at once instead of waiting in the Workers AI capacity queue. The
|
|
243
|
+
* provider reports the rejection as an AI SDK `APICallError` with
|
|
244
|
+
* `statusCode: 429`, which the AI SDK retries unless the call sets
|
|
245
|
+
* `maxRetries: 0`.
|
|
246
|
+
*/
|
|
247
|
+
rejectIfBusy?: boolean;
|
|
248
|
+
}
|
|
219
249
|
/**
|
|
220
250
|
* Structural slice of the span handle `ctx.trace` hands its body — enough to
|
|
221
251
|
* attach a model call's usage once it is known. Declared here rather than
|
|
@@ -360,15 +390,15 @@ interface LunoraAi {
|
|
|
360
390
|
* provider key in the app) or, with `LUNORA_AI_PROXY_URL` set, to that
|
|
361
391
|
* OpenAI-compatible proxy; an object → passthrough.
|
|
362
392
|
*/
|
|
363
|
-
model: (model?: ModelInput) => LanguageModel;
|
|
393
|
+
model: (model?: ModelInput, options?: AiModelOptions) => LanguageModel;
|
|
364
394
|
/**
|
|
365
395
|
* Raw Workers AI binding passthrough (void-style `ai.run`). Bypasses the AI
|
|
366
396
|
* SDK entirely — useful for Workers-AI-only model families (image, ASR,
|
|
367
397
|
* translation) not surfaced through the provider. Throws if no binding was
|
|
368
398
|
* supplied.
|
|
369
399
|
*/
|
|
370
|
-
run: (model: string, inputs: Record<string, unknown>, options?:
|
|
400
|
+
run: (model: string, inputs: Record<string, unknown>, options?: AiRunOptions) => Promise<unknown>;
|
|
371
401
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
372
402
|
workersai: WorkersAiProviderLike;
|
|
373
403
|
}
|
|
374
|
-
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, AI_PROXY_TOKEN_ENV as h, AI_PROXY_URL_ENV as i, AiBindingLike as j, AiGatewayMetadata as k, AiGatewayOptions as l, AiMetrics as m,
|
|
404
|
+
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, AI_PROXY_TOKEN_ENV as h, AI_PROXY_URL_ENV as i, AiBindingLike as j, AiGatewayMetadata as k, AiGatewayOptions as l, AiMetrics as m, AiModelOptions as n, AiRunOptions as o, AiSpan as p, AiTelemetry as q, AiTracer as r, buildAiGatewayMetadataFields as s, readAiGatewayEnvTags as t, resolveAiGateway as u };
|
|
@@ -216,6 +216,36 @@ interface AiGatewayOptions {
|
|
|
216
216
|
*/
|
|
217
217
|
metadata?: Record<string, string>;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Options for the raw `ctx.ai.run(...)` passthrough — the Workers AI binding's
|
|
221
|
+
* third argument. Unlisted keys are forwarded to the binding unchanged.
|
|
222
|
+
* @experimental
|
|
223
|
+
*/
|
|
224
|
+
interface AiRunOptions {
|
|
225
|
+
[key: string]: unknown;
|
|
226
|
+
/** Route this call through a Cloudflare AI Gateway. Defaults to the gateway `createAi` resolved. */
|
|
227
|
+
gateway?: AiGatewayOptions;
|
|
228
|
+
/**
|
|
229
|
+
* Fail at once instead of waiting in the Workers AI capacity queue when no
|
|
230
|
+
* capacity is free. The rejection surfaces as a `LunoraError` with code
|
|
231
|
+
* `RATE_LIMITED` (Workers AI error `3040`, HTTP 429).
|
|
232
|
+
*/
|
|
233
|
+
rejectIfBusy?: boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Per-call settings for `ctx.ai.model(...)`. Applied to Workers AI model ids
|
|
237
|
+
* (`@cf/…`) only; a gateway slug or a bring-your-own model ignores them.
|
|
238
|
+
* @experimental
|
|
239
|
+
*/
|
|
240
|
+
interface AiModelOptions {
|
|
241
|
+
/**
|
|
242
|
+
* Fail at once instead of waiting in the Workers AI capacity queue. The
|
|
243
|
+
* provider reports the rejection as an AI SDK `APICallError` with
|
|
244
|
+
* `statusCode: 429`, which the AI SDK retries unless the call sets
|
|
245
|
+
* `maxRetries: 0`.
|
|
246
|
+
*/
|
|
247
|
+
rejectIfBusy?: boolean;
|
|
248
|
+
}
|
|
219
249
|
/**
|
|
220
250
|
* Structural slice of the span handle `ctx.trace` hands its body — enough to
|
|
221
251
|
* attach a model call's usage once it is known. Declared here rather than
|
|
@@ -360,15 +390,15 @@ interface LunoraAi {
|
|
|
360
390
|
* provider key in the app) or, with `LUNORA_AI_PROXY_URL` set, to that
|
|
361
391
|
* OpenAI-compatible proxy; an object → passthrough.
|
|
362
392
|
*/
|
|
363
|
-
model: (model?: ModelInput) => LanguageModel;
|
|
393
|
+
model: (model?: ModelInput, options?: AiModelOptions) => LanguageModel;
|
|
364
394
|
/**
|
|
365
395
|
* Raw Workers AI binding passthrough (void-style `ai.run`). Bypasses the AI
|
|
366
396
|
* SDK entirely — useful for Workers-AI-only model families (image, ASR,
|
|
367
397
|
* translation) not surfaced through the provider. Throws if no binding was
|
|
368
398
|
* supplied.
|
|
369
399
|
*/
|
|
370
|
-
run: (model: string, inputs: Record<string, unknown>, options?:
|
|
400
|
+
run: (model: string, inputs: Record<string, unknown>, options?: AiRunOptions) => Promise<unknown>;
|
|
371
401
|
/** The underlying Workers AI provider — `ai.workersai("@cf/...")` for a raw model. */
|
|
372
402
|
workersai: WorkersAiProviderLike;
|
|
373
403
|
}
|
|
374
|
-
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, AI_PROXY_TOKEN_ENV as h, AI_PROXY_URL_ENV as i, AiBindingLike as j, AiGatewayMetadata as k, AiGatewayOptions as l, AiMetrics as m,
|
|
404
|
+
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, AI_PROXY_TOKEN_ENV as h, AI_PROXY_URL_ENV as i, AiBindingLike as j, AiGatewayMetadata as k, AiGatewayOptions as l, AiMetrics as m, AiModelOptions as n, AiRunOptions as o, AiSpan as p, AiTelemetry as q, AiTracer as r, buildAiGatewayMetadataFields as s, readAiGatewayEnvTags as t, resolveAiGateway as u };
|
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-ChtZguP_.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-ChtZguP_.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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/ai",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.105",
|
|
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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@ai-sdk/anthropic": "4.0.49",
|
|
57
57
|
"@ai-sdk/openai": "4.0.60",
|
|
58
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
58
|
+
"@lunora/errors": "1.0.0-alpha.48",
|
|
59
59
|
"ai": "7.0.93",
|
|
60
60
|
"workers-ai-provider": "4.0.0"
|
|
61
61
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createOpenAI as G}from"@ai-sdk/openai";import{LunoraError as w}from"@lunora/errors";import{createWorkersAI as $}from"workers-ai-provider";import{anthropic as S}from"workers-ai-provider/anthropic";import{openai as W}from"workers-ai-provider/openai";import{buildAiGatewayMetadataFields as T,readEnv as A,AI_DEFAULT_MODEL_ENV as M,AI_DEFAULT_EMBEDDING_MODEL_ENV as _,AI_PROXY_URL_ENV as b,AI_PROXY_TOKEN_ENV as R,readAiGatewayEnvTags as V,AI_GATEWAY_ID_ENV as F,warnIgnoredBindingToken as K}from"./AI_DEFAULT_EMBEDDING_MODEL_ENV-IwcHZiKj.mjs";import{wrapLanguageModel as q}from"ai";import{m as Y,r as I}from"./usage-GPnTSqR8.mjs";import"./DEFAULT_MODEL_PRICES-CIJLs1Ah.mjs";const j={setAttribute:()=>{},setAttributes:()=>{}},O=async(e,t)=>t(O,j),B=(e,{metrics:t,trace:a=O})=>{const o={"gen_ai.operation.name":"chat","gen_ai.request.model":e};return{wrapGenerate:async({doGenerate:r})=>a("ai.generate",async(c,v)=>{const f=await r();return I(e,f,v,t),f},o),wrapStream:async({doStream:r})=>{const c=(g,s)=>{const d=g.stream.getReader();let u={};return{...g,stream:new ReadableStream({cancel:async l=>{s({outcome:u}),await d.cancel(l)},pull:async l=>{let m;try{m=await d.read()}catch(E){s({error:E,failed:!0,outcome:u}),l.error(E);return}if(m.done){s({outcome:u}),l.close();return}m.value.type==="finish"&&(u={providerMetadata:m.value.providerMetadata,usage:m.value.usage}),l.enqueue(m.value)}})}},v=Promise.withResolvers(),f=Promise.withResolvers();return a("ai.stream",async(g,s)=>{v.resolve(c(await r(),f.resolve));const d=await f.promise;if(I(e,d.outcome,s,t),d.failed===!0)throw d.error},o).catch(v.reject),v.promise}}},L=(e,t,a)=>{let o=e;return t!==void 0&&typeof e!="string"&&(o=q({middleware:B(a??Y(e)??"unknown",t),model:e})),o},H=[W,S],N=e=>!e.startsWith("@")&&e.includes("/"),y=e=>{throw new w("INTERNAL",`@lunora/ai: ${e} needs the \`AI\` binding (env.AI). Add an \`ai\` binding to wrangler.jsonc, or set ${b} to an OpenAI-compatible proxy for "<provider>/<model>" slugs.`)},x=()=>y("this model id");x.textEmbeddingModel=()=>y("this embedding model id");const X=new Set(["127.0.0.1","[::1]","localhost"]),C=e=>{const t=A(e,b);if(t===void 0)return;const a=A(e,R),o=URL.canParse(t)?new URL(t):void 0;let r;if(o===void 0?r=`${b} is not a valid URL`:a!==void 0&&o.protocol!=="https:"&&!X.has(o.hostname)&&(r=`${b} (${o.origin}) is not HTTPS, so ${R} would travel in cleartext — use an https:// URL`),r!==void 0){const c=()=>{throw new w("INTERNAL",`@lunora/ai: ${r}`)};return{chat:c,embedding:c}}return G({apiKey:a??"",baseURL:t,name:"lunora-proxy"})},z=(e,t)=>{const a=e===void 0?void 0:V(e);return a===void 0?t:{...t,tags:{...a,...t?.tags}}},J=(e,t,a)=>{const o=T(a);if(e!==void 0)return o!==void 0&&e.metadata===void 0?{...e,metadata:o}:e;if(t===void 0)return;const r=A(t,F);if(r!==void 0)return K(t),o===void 0?{id:r}:{id:r,metadata:o}},ce=e=>{const{binding:t,defaultEmbeddingModel:a,defaultModel:o,env:r,gateway:c,metadata:v,provider:f,telemetry:g}=e,s=C(r),d=z(r,v),u=J(c,r,d),l=c?.metadata===void 0?T(d):void 0,m=o??A(r,M),E=a??A(r,_),p=f??(t?$({binding:t,gateway:u,providers:H}):x),D=n=>N(n)?s!==void 0?s.chat(n):l===void 0?p(n):p(n,{metadata:l}):p(n),P=n=>{const i=n??m;if(i===void 0||i==="")throw new w("INTERNAL",`@lunora/ai: no model supplied and no default configured — pass a model id, or set ${M} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return typeof i=="string"?L(D(i),g,i):L(i,g)},U=n=>{if(s!==void 0&&N(n))return s.embedding(n);const i=p.textEmbeddingModel;if(typeof i!="function")throw new w("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 i.call(p,n)};return{embeddingModel:n=>{if(typeof n=="object")return n;const i=n??E;if(!i)throw new w("INTERNAL",`@lunora/ai: no embedding model supplied and no default configured — pass an embedding model id or an AI SDK EmbeddingModel, or set ${_} in the Worker env (wrangler \`vars\` / \`.dev.vars\`)`);return U(i)},model:P,run:async(n,i,h)=>{if(!t)return y("ai.run");const k=u!==void 0&&h?.gateway===void 0?{...h,gateway:u}:h;return t.run(n,i,k)},workersai:p}};export{ce as default};
|