@lunora/server 1.0.0-alpha.26 → 1.0.0-alpha.261

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.
Files changed (102) hide show
  1. package/LICENSE.md +213 -0
  2. package/README.md +18 -12
  3. package/dist/data-model.d.mts +392 -170
  4. package/dist/data-model.d.ts +392 -170
  5. package/dist/data-model.mjs +0 -1
  6. package/dist/drizzle.mjs +1 -1
  7. package/dist/in-process.d.mts +101 -0
  8. package/dist/in-process.d.ts +101 -0
  9. package/dist/in-process.mjs +1 -0
  10. package/dist/index.d.mts +3913 -1591
  11. package/dist/index.d.ts +3913 -1591
  12. package/dist/index.mjs +1 -29
  13. package/dist/otel.d.mts +597 -0
  14. package/dist/otel.d.ts +597 -0
  15. package/dist/otel.mjs +1 -0
  16. package/dist/packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-DU87Okaj.mjs +1 -0
  17. package/dist/packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs +1 -0
  18. package/dist/packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-DHn50G0w.mjs +1 -0
  19. package/dist/packem_shared/LunoraEnvError-bkdMu_-N.mjs +4 -0
  20. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-BtGG52OZ.mjs +1 -0
  21. package/dist/packem_shared/allowAll-DkRAgItV.mjs +1 -0
  22. package/dist/packem_shared/apply-output-C5wZ5EAL.mjs +1 -0
  23. package/dist/packem_shared/asBucketStorage-DoGYOjq3.mjs +1 -0
  24. package/dist/packem_shared/assertShapesDeclareReadPolicies-CHqQ2eDy.mjs +1 -0
  25. package/dist/packem_shared/beginDeferredDeletes-DhwFBbvs.mjs +1 -0
  26. package/dist/packem_shared/beginDeferredSchedules-C7QLYr6C.mjs +1 -0
  27. package/dist/packem_shared/bindOrm-D5mVDvbi.mjs +1 -0
  28. package/dist/packem_shared/buildMaskRegistry-DpWMtalG.mjs +1 -0
  29. package/dist/packem_shared/compose-middleware-BK9FlblN.mjs +1 -0
  30. package/dist/packem_shared/composePluginMiddleware-Cvl_EFSm.mjs +1 -0
  31. package/dist/packem_shared/context-identity-B2XYGA0B.mjs +1 -0
  32. package/dist/packem_shared/createPolicyDsl-BZa6SqLJ.mjs +1 -0
  33. package/dist/packem_shared/createSecrets-D6rLB42U.mjs +1 -0
  34. package/dist/packem_shared/createServices-IJvoqi0e.mjs +1 -0
  35. package/dist/packem_shared/defineAggregateIndex-Ds7prVoi.mjs +1 -0
  36. package/dist/packem_shared/defineIdentity-DwkNKwYa.mjs +1 -0
  37. package/dist/packem_shared/defineIdentityGuard-Bt8N65Zs.mjs +1 -0
  38. package/dist/packem_shared/defineLiveStream-BmMpdotv.mjs +1 -0
  39. package/dist/packem_shared/defineMigration-CXOS0Bvq.mjs +1 -0
  40. package/dist/packem_shared/defineModule-OecXWM3U.mjs +1 -0
  41. package/dist/packem_shared/defineMutator-DlLFSWbO.mjs +1 -0
  42. package/dist/packem_shared/defineRoom-CoGi-xwm.mjs +1 -0
  43. package/dist/packem_shared/defineShape-CjBBjn-S.mjs +1 -0
  44. package/dist/packem_shared/defineStorageRule-Dv4nJE0H.mjs +1 -0
  45. package/dist/packem_shared/defineWebSocket-BHoy6_ox.mjs +1 -0
  46. package/dist/packem_shared/fnv1a-D3ueNTWB.mjs +1 -0
  47. package/dist/packem_shared/functions-QFoBUe9t.mjs +1 -0
  48. package/dist/packem_shared/httpAction-DuAVtPa_.mjs +1 -0
  49. package/dist/packem_shared/initLunora-DH7k24N0.mjs +1 -0
  50. package/dist/packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs +1 -0
  51. package/dist/packem_shared/isSafeHeaderValue-DswDADFy.mjs +6 -0
  52. package/dist/packem_shared/mask-BFPGwDqW.mjs +1 -0
  53. package/dist/packem_shared/middleware-mzWrOTEE.mjs +1 -0
  54. package/dist/packem_shared/onConnect-BLRoOpv2.mjs +1 -0
  55. package/dist/packem_shared/onQueryChange-iuLzmyPs.mjs +1 -0
  56. package/dist/packem_shared/onWhisper-CfDbFLQh.mjs +1 -0
  57. package/dist/packem_shared/platformAdmin-kczXQme8.mjs +1 -0
  58. package/dist/packem_shared/plugin-D0ogWCbA.mjs +1 -0
  59. package/dist/packem_shared/policy-tag-V0lqFzgS.mjs +1 -0
  60. package/dist/packem_shared/protectPublic-Bi5_95aP.mjs +1 -0
  61. package/dist/packem_shared/rls-CJ-lKTG6.mjs +1 -0
  62. package/dist/packem_shared/run-middleware-BefYq7Xd.mjs +1 -0
  63. package/dist/packem_shared/serveStorageObject-CLz3qhNI.mjs +1 -0
  64. package/dist/packem_shared/storageRules-5NQpFz_N.mjs +1 -0
  65. package/dist/packem_shared/types.d-B7FLdYUD.d.mts +148 -0
  66. package/dist/packem_shared/types.d-BCtjbIzl.d.ts +148 -0
  67. package/dist/packem_shared/types.d-BOnXpMCp.d.mts +2961 -0
  68. package/dist/packem_shared/types.d-BOnXpMCp.d.ts +2961 -0
  69. package/dist/rls/testing.d.mts +42 -34
  70. package/dist/rls/testing.d.ts +42 -34
  71. package/dist/rls/testing.mjs +1 -49
  72. package/dist/types.d.mts +2 -1335
  73. package/dist/types.d.ts +2 -1335
  74. package/dist/types.mjs +0 -31
  75. package/package.json +27 -7
  76. package/dist/packem_shared/LunoraEnvError-BGmd1Qs0.mjs +0 -187
  77. package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +0 -9
  78. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-Cv1UPaJj.mjs +0 -114
  79. package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
  80. package/dist/packem_shared/bindOrm-Bfgl7f-Q.mjs +0 -146
  81. package/dist/packem_shared/buildRlsReadRegistry-D54vUQe4.mjs +0 -107
  82. package/dist/packem_shared/composePluginMiddleware-z62dttBo.mjs +0 -103
  83. package/dist/packem_shared/createPolicyDsl-By3QB4he.mjs +0 -32
  84. package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +0 -58
  85. package/dist/packem_shared/defineAggregateIndex-DTULzh09.mjs +0 -333
  86. package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +0 -35
  87. package/dist/packem_shared/defineMigration-Hx01yIht.mjs +0 -10
  88. package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
  89. package/dist/packem_shared/defineShape-C5scNOrf.mjs +0 -18
  90. package/dist/packem_shared/defineStorageRule-B5nL4Z1P.mjs +0 -23
  91. package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
  92. package/dist/packem_shared/httpAction-DCXoYPIk.mjs +0 -355
  93. package/dist/packem_shared/initLunora-CmMVk4i7.mjs +0 -107
  94. package/dist/packem_shared/mask-DSBtA3qp.mjs +0 -314
  95. package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
  96. package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
  97. package/dist/packem_shared/protectPublic-BlcGpiRc.mjs +0 -15
  98. package/dist/packem_shared/rls-B_ZWgslr.mjs +0 -595
  99. package/dist/packem_shared/run-middleware-I6EiQfxL.mjs +0 -20
  100. package/dist/packem_shared/storageRules-6QxzDOcx.mjs +0 -88
  101. package/dist/packem_shared/types.d-BB3pjV0m.d.mts +0 -141
  102. package/dist/packem_shared/types.d-Cxl6ndhm.d.ts +0 -141
package/dist/index.mjs CHANGED
@@ -1,29 +1 @@
1
- export { default as asBucketStorage } from './packem_shared/asBucketStorage-Cnxd9y2q.mjs';
2
- export { initLunora } from './packem_shared/initLunora-CmMVk4i7.mjs';
3
- export { createSecrets } from './packem_shared/createSecrets-DwaR2rNG.mjs';
4
- export { LunoraEnvError, defineEnv, redactSecrets } from './packem_shared/LunoraEnvError-BGmd1Qs0.mjs';
5
- export { LunoraError } from './packem_shared/LunoraError-WbxmrpxR.mjs';
6
- export { bindOrm, bindTableFacade } from './packem_shared/bindOrm-Bfgl7f-Q.mjs';
7
- export { httpAction, httpRoute, httpRouter, isSafeHeaderValue, serveStorageObject } from './packem_shared/httpAction-DCXoYPIk.mjs';
8
- export { defineIdentity } from './packem_shared/defineIdentity-DiX4zM9x.mjs';
9
- export { onConnect, onDisconnect } from './packem_shared/onConnect-CIPXKPyw.mjs';
10
- export { defineMigration } from './packem_shared/defineMigration-Hx01yIht.mjs';
11
- export { defineMutator } from './packem_shared/defineMutator-EIXAWhs9.mjs';
12
- export { composePluginMiddleware, defineComponent, definePlugin, defineSchemaExtension, installPlugins, mergeSchemaExtension } from './packem_shared/composePluginMiddleware-z62dttBo.mjs';
13
- export { PRESENCE_DEFAULT_TTL_MS, PRESENCE_TABLE, definePresence, presenceExtension } from './packem_shared/PRESENCE_DEFAULT_TTL_MS-Cv1UPaJj.mjs';
14
- export { protectPublic } from './packem_shared/protectPublic-BlcGpiRc.mjs';
15
- export { defineAggregateIndex, defineRankIndex, defineSchema, defineTable, defineVectorIndex } from './packem_shared/defineAggregateIndex-DTULzh09.mjs';
16
- export { defineShape } from './packem_shared/defineShape-C5scNOrf.mjs';
17
- export { anyApi } from './types.mjs';
18
- export { cronJobs } from '@lunora/scheduler';
19
- export { ValidationError, v } from '@lunora/values';
20
- export { buildRlsReadRegistry, composeShapeReadWhere } from './packem_shared/buildRlsReadRegistry-D54vUQe4.mjs';
21
- export { createPolicyDsl, definePermission, definePolicies, definePolicy, defineRole } from './packem_shared/createPolicyDsl-By3QB4he.mjs';
22
- export { defineStorageRule, defineStorageRules } from './packem_shared/defineStorageRule-B5nL4Z1P.mjs';
23
- export { mask } from './packem_shared/mask-DSBtA3qp.mjs';
24
- export { rls } from './packem_shared/rls-B_ZWgslr.mjs';
25
- export { storageRules } from './packem_shared/storageRules-6QxzDOcx.mjs';
26
-
27
- const VERSION = "0.0.0";
28
-
29
- export { VERSION };
1
+ import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as i,actionCacheExtension as n,cacheKeyFor as f,defineActionCache as a}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-DU87Okaj.mjs";import{initLunora as s}from"./packem_shared/initLunora-DH7k24N0.mjs";import{isPerDispatchMiddleware as p,tagPerDispatchMiddleware as x}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as l}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as S,flushDeferredDeletes as u,withDeferredDeletes as h}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as T,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-C7QLYr6C.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as A,DOCUMENT_HISTORY_TABLE as L,defineDocumentHistory as I,documentHistoryExtension as _}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-DHn50G0w.mjs";import{LunoraEnvError as M,defineEnv as P,redactSecrets as b}from"./packem_shared/LunoraEnvError-bkdMu_-N.mjs";import{bindOrm as F,bindTableFacade as v,defineLazyFacade as O}from"./packem_shared/bindOrm-D5mVDvbi.mjs";import{httpAction as N,httpRoute as k,httpRouter as w,lastEventId as U,sseEvent as B}from"./packem_shared/httpAction-DuAVtPa_.mjs";import{serveStorageObject as W}from"./packem_shared/serveStorageObject-CLz3qhNI.mjs";import{defineIdentity as Y}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{default as G}from"./packem_shared/defineIdentityGuard-Bt8N65Zs.mjs";import{onConnect as K,onDisconnect as Q,onShardInit as X}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as Z,DEFAULT_MAX_LIMIT as $,clampLimit as ee,defineListArgs as re}from"./packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs";import{defineLiveStream as te,liveStreamRouter as ie}from"./packem_shared/defineLiveStream-BmMpdotv.mjs";import{defineMigration as fe}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as de}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as me}from"./packem_shared/defineMutator-DlLFSWbO.mjs";import{platformAdmin as xe}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as le,d as Ee,a as Se,b as ue,e as he,f as De,g as Te,h as ge,i as Re,j as Ae,k as Le,m as Ie}from"./packem_shared/plugin-D0ogWCbA.mjs";import{PRESENCE_DEFAULT_TTL_MS as Ce,PRESENCE_TABLE as Me,definePresence as Pe,presenceExtension as be}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-BtGG52OZ.mjs";import{protectPublic as Fe}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as Oe}from"./packem_shared/onQueryChange-iuLzmyPs.mjs";import{defineRoom as Ne}from"./packem_shared/defineRoom-CoGi-xwm.mjs";import{createServices as we}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as Be}from"./packem_shared/defineShape-CjBBjn-S.mjs";import{defineWebSocket as We}from"./packem_shared/defineWebSocket-BHoy6_ox.mjs";import{onWhisper as Ye}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as Ge}from"@lunora/errors";import{cronJobs as Ke}from"@lunora/scheduler";import{ValidationError as Xe,v as qe}from"@lunora/values";import{allowAll as $e,deny as er,isDeny as rr,toWhereInput as or}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as ir}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as fr,buildRlsReadRegistry as ar,composeShapeReadWhere as dr}from"./packem_shared/assertShapesDeclareReadPolicies-CHqQ2eDy.mjs";import{buildMaskRegistry as mr}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as xr,definePermission as cr,definePolicies as lr,definePolicy as Er,defineRole as Sr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as hr,defineStorageRules as Dr}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{isSafeHeaderValue as gr}from"./packem_shared/isSafeHeaderValue-DswDADFy.mjs";import{mask as Ar}from"./packem_shared/mask-BFPGwDqW.mjs";import{r as Ir}from"./packem_shared/middleware-mzWrOTEE.mjs";import{storageRules as Cr}from"./packem_shared/storageRules-5NQpFz_N.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,i as ACTION_CACHE_TABLE,Z as DEFAULT_LIMIT,$ as DEFAULT_MAX_LIMIT,A as DOCUMENT_HISTORY_REDACTED_FIELDS,L as DOCUMENT_HISTORY_TABLE,M as LunoraEnvError,Ge as LunoraError,Ce as PRESENCE_DEFAULT_TTL_MS,Me as PRESENCE_TABLE,e as VERSION,Xe as ValidationError,n as actionCacheExtension,$e as allowAll,ir as asBucketStorage,fr as assertShapesDeclareReadPolicies,S as beginDeferredDeletes,T as beginDeferredSchedules,F as bindOrm,v as bindTableFacade,mr as buildMaskRegistry,ar as buildRlsReadRegistry,f as cacheKeyFor,ee as clampLimit,le as composePluginMiddleware,dr as composeShapeReadWhere,xr as createPolicyDsl,l as createSecrets,we as createServices,Ke as cronJobs,a as defineActionCache,Ee as defineAggregateIndex,Se as defineComponent,I as defineDocumentHistory,P as defineEnv,Y as defineIdentity,G as defineIdentityGuard,O as defineLazyFacade,re as defineListArgs,te as defineLiveStream,fe as defineMigration,de as defineModule,me as defineMutator,cr as definePermission,ue as definePlugin,lr as definePolicies,Er as definePolicy,Pe as definePresence,he as defineRankIndex,Sr as defineRole,Ne as defineRoom,De as defineSchema,Te as defineSchemaExtension,Be as defineShape,hr as defineStorageRule,Dr as defineStorageRules,ge as defineTable,Re as defineVectorIndex,We as defineWebSocket,er as deny,_ as documentHistoryExtension,u as flushDeferredDeletes,N as httpAction,k as httpRoute,w as httpRouter,Ae as indexFieldsFromSchema,s as initLunora,Le as installPlugins,rr as isDeny,p as isPerDispatchMiddleware,gr as isSafeHeaderValue,U as lastEventId,ie as liveStreamRouter,Ar as mask,Ie as mergeSchemaExtension,K as onConnect,Q as onDisconnect,Oe as onQueryChange,X as onShardInit,Ye as onWhisper,xe as platformAdmin,be as presenceExtension,Fe as protectPublic,b as redactSecrets,Ir as rls,W as serveStorageObject,B as sseEvent,Cr as storageRules,x as tagPerDispatchMiddleware,or as toWhereInput,qe as v,h as withDeferredDeletes,g as withDeferredSchedules};
@@ -0,0 +1,597 @@
1
+ /**
2
+ * `@lunora/server/otel` — hand a Lunora `ctx` to anything that speaks
3
+ * `@opentelemetry/api`.
4
+ *
5
+ * **The problem.** Lunora's tracing is hand-rolled and zero-dependency, which is
6
+ * the right call for a runtime that has to boot in a Workers isolate. The cost
7
+ * is that a library instrumented against `@opentelemetry/api` — the Vercel AI
8
+ * SDK's `experimental_telemetry`, a database driver's instrumentation, an
9
+ * in-house shared package — cannot see Lunora's trace. Its spans go to whatever
10
+ * global provider is registered, which in a Worker is the no-op one. They vanish.
11
+ *
12
+ * **The fix.** {@link createOtelTracer} adapts a `ctx` into an OTel `Tracer`, so
13
+ * the library's spans become real `ctx.trace` spans in the request's trace:
14
+ *
15
+ * ```ts
16
+ * import { createOtelTracer } from "@lunora/server/otel";
17
+ *
18
+ * export const summarize = action.action(async ({ args, ctx }) =>
19
+ * generateText({
20
+ * model: openai("gpt-4o"),
21
+ * prompt: args.prompt,
22
+ * experimental_telemetry: { isEnabled: true, tracer: createOtelTracer(ctx) },
23
+ * }),
24
+ * );
25
+ * ```
26
+ *
27
+ * **Why passing the tracer explicitly is the supported path.** OTel's ambient
28
+ * `context` API (`trace.getActiveSpan()`, implicit parenting inside
29
+ * `startActiveSpan`) needs `AsyncLocalStorage` to track the current span across
30
+ * `await`s. Durable Objects run under a slimmer compatibility profile than
31
+ * `nodejs_compat`, and `@lunora/do` deliberately avoids ALS for that reason —
32
+ * the same reason `ctx.trace` threads its parent explicitly instead of keeping
33
+ * an ambient stack. So this bridge implements the `Tracer` surface faithfully
34
+ * and parents each span to the `Context` its caller THREADED (falling back to
35
+ * the dispatch when none was), never to a dynamically-scoped "current" span:
36
+ * nesting is flatter than a full SDK would give for a library that relies on
37
+ * ambient context, but every span lands in the right trace, under the parent it
38
+ * was told about, with the right timings, and none are lost. See
39
+ * {@link createOtelTracer} for the precise semantics.
40
+ *
41
+ * `@opentelemetry/api` is a PEER dependency: it keeps a module-global registry,
42
+ * so a second copy in the tree would silently split it.
43
+ */
44
+ import { a as SpanHandle, L as LunoraTracer } from "./packem_shared/types.d-BOnXpMCp.mjs";
45
+ import '@lunora/values';
46
+ /**
47
+ * @since 1.0.0
48
+ */
49
+ interface Context {
50
+ /**
51
+ * Get a value from the context.
52
+ *
53
+ * @param key key which identifies a context value
54
+ */
55
+ getValue(key: symbol): unknown;
56
+ /**
57
+ * Create a new context which inherits from this context and has
58
+ * the given key set to the given value.
59
+ *
60
+ * @param key context key for which to set the value
61
+ * @param value value to set for the given key
62
+ */
63
+ setValue(key: symbol, value: unknown): Context;
64
+ /**
65
+ * Return a new context which inherits from this context but does
66
+ * not contain a value for the given key.
67
+ *
68
+ * @param key context key for which to clear a value
69
+ */
70
+ deleteValue(key: symbol): Context;
71
+ }
72
+ /**
73
+ * Attributes is a map from string to attribute values.
74
+ *
75
+ * Note: only the own enumerable keys are counted as valid attribute keys.
76
+ *
77
+ * @since 1.3.0
78
+ */
79
+ interface Attributes {
80
+ [attributeKey: string]: AttributeValue | undefined;
81
+ }
82
+ /**
83
+ * Attribute values may be any non-nullish primitive value except an object.
84
+ *
85
+ * null or undefined attribute values are invalid and will result in undefined behavior.
86
+ *
87
+ * @since 1.3.0
88
+ */
89
+ type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
90
+ interface ExceptionWithCode {
91
+ code: string | number;
92
+ name?: string;
93
+ message?: string;
94
+ stack?: string;
95
+ }
96
+ interface ExceptionWithMessage {
97
+ code?: string | number;
98
+ message: string;
99
+ name?: string;
100
+ stack?: string;
101
+ }
102
+ interface ExceptionWithName {
103
+ code?: string | number;
104
+ message?: string;
105
+ name: string;
106
+ stack?: string;
107
+ }
108
+ /**
109
+ * Defines Exception.
110
+ *
111
+ * string or an object with one of (message or name or code) and optional stack
112
+ *
113
+ * @since 1.0.0
114
+ */
115
+ type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
116
+ /**
117
+ * Defines High-Resolution Time.
118
+ *
119
+ * The first number, HrTime[0], is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
120
+ * The second number, HrTime[1], represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
121
+ * For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
122
+ * The first number is calculated by converting and truncating the Epoch time in milliseconds to seconds:
123
+ * HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
124
+ * The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
125
+ * HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
126
+ * This is represented in HrTime format as [1609504210, 150000000].
127
+ *
128
+ * @since 1.0.0
129
+ */
130
+ type HrTime = [number, number];
131
+ /**
132
+ * Defines TimeInput.
133
+ *
134
+ * hrtime, epoch milliseconds, performance.now() or Date
135
+ *
136
+ * @since 1.0.0
137
+ */
138
+ type TimeInput = HrTime | number | Date;
139
+ /**
140
+ * @deprecated please use {@link Attributes}
141
+ * @since 1.0.0
142
+ */
143
+ type SpanAttributes = Attributes;
144
+ /**
145
+ * @deprecated please use {@link AttributeValue}
146
+ * @since 1.0.0
147
+ */
148
+ type SpanAttributeValue = AttributeValue;
149
+ /**
150
+ * @since 1.0.0
151
+ */
152
+ interface TraceState {
153
+ /**
154
+ * Create a new TraceState which inherits from this TraceState and has the
155
+ * given key set.
156
+ * The new entry will always be added in the front of the list of states.
157
+ *
158
+ * @param key key of the TraceState entry.
159
+ * @param value value of the TraceState entry.
160
+ */
161
+ set(key: string, value: string): TraceState;
162
+ /**
163
+ * Return a new TraceState which inherits from this TraceState but does not
164
+ * contain the given key.
165
+ *
166
+ * @param key the key for the TraceState entry to be removed.
167
+ */
168
+ unset(key: string): TraceState;
169
+ /**
170
+ * Returns the value to which the specified key is mapped, or `undefined` if
171
+ * this map contains no mapping for the key.
172
+ *
173
+ * @param key with which the specified value is to be associated.
174
+ * @returns the value to which the specified key is mapped, or `undefined` if
175
+ * this map contains no mapping for the key.
176
+ */
177
+ get(key: string): string | undefined;
178
+ /**
179
+ * Serializes the TraceState to a `list` as defined below. The `list` is a
180
+ * series of `list-members` separated by commas `,`, and a list-member is a
181
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
182
+ * surrounding `list-members` are ignored. There can be a maximum of 32
183
+ * `list-members` in a `list`.
184
+ *
185
+ * @returns the serialized string.
186
+ */
187
+ serialize(): string;
188
+ }
189
+ /**
190
+ * A SpanContext represents the portion of a {@link Span} which must be
191
+ * serialized and propagated along side of a {@link Baggage}.
192
+ *
193
+ * @since 1.0.0
194
+ */
195
+ interface SpanContext {
196
+ /**
197
+ * The ID of the trace that this span belongs to. It is worldwide unique
198
+ * with practically sufficient probability by being made as 16 randomly
199
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
200
+ * 128 bits.
201
+ */
202
+ traceId: string;
203
+ /**
204
+ * The ID of the Span. It is globally unique with practically sufficient
205
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
206
+ * lowercase hex characters corresponding to 64 bits.
207
+ */
208
+ spanId: string;
209
+ /**
210
+ * Only true if the SpanContext was propagated from a remote parent.
211
+ */
212
+ isRemote?: boolean;
213
+ /**
214
+ * Trace flags to propagate.
215
+ *
216
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
217
+ * sampled or not. When set, the least significant bit documents that the
218
+ * caller may have recorded trace data. A caller who does not record trace
219
+ * data out-of-band leaves this flag unset.
220
+ *
221
+ * see {@link TraceFlags} for valid flag values.
222
+ */
223
+ traceFlags: number;
224
+ /**
225
+ * Tracing-system-specific info to propagate.
226
+ *
227
+ * The tracestate field value is a `list` as defined below. The `list` is a
228
+ * series of `list-members` separated by commas `,`, and a list-member is a
229
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
230
+ * surrounding `list-members` are ignored. There can be a maximum of 32
231
+ * `list-members` in a `list`.
232
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
233
+ *
234
+ * Examples:
235
+ * Single tracing system (generic format):
236
+ * tracestate: rojo=00f067aa0ba902b7
237
+ * Multiple tracing systems (with different formatting):
238
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
239
+ */
240
+ traceState?: TraceState;
241
+ }
242
+ /**
243
+ * @since 1.0.0
244
+ */
245
+ interface SpanStatus {
246
+ /** The status code of this message. */
247
+ code: SpanStatusCode;
248
+ /** A developer-facing error message. */
249
+ message?: string;
250
+ }
251
+ /**
252
+ * An enumeration of status codes.
253
+ *
254
+ * @since 1.0.0
255
+ */
256
+ declare enum SpanStatusCode {
257
+ /**
258
+ * The default status.
259
+ */
260
+ UNSET = 0,
261
+ /**
262
+ * The operation has been validated by an Application developer or
263
+ * Operator to have completed successfully.
264
+ */
265
+ OK = 1,
266
+ /**
267
+ * The operation contains an error.
268
+ */
269
+ ERROR = 2
270
+ }
271
+ /**
272
+ * A pointer from the current {@link Span} to another span in the same trace or
273
+ * in a different trace.
274
+ * Few examples of Link usage.
275
+ * 1. Batch Processing: A batch of elements may contain elements associated
276
+ * with one or more traces/spans. Since there can only be one parent
277
+ * SpanContext, Link is used to keep reference to SpanContext of all
278
+ * elements in the batch.
279
+ * 2. Public Endpoint: A SpanContext in incoming client request on a public
280
+ * endpoint is untrusted from service provider perspective. In such case it
281
+ * is advisable to start a new trace with appropriate sampling decision.
282
+ * However, it is desirable to associate incoming SpanContext to new trace
283
+ * initiated on service provider side so two traces (from Client and from
284
+ * Service Provider) can be correlated.
285
+ *
286
+ * @since 1.0.0
287
+ */
288
+ interface Link {
289
+ /** The {@link SpanContext} of a linked span. */
290
+ context: SpanContext;
291
+ /** A set of {@link SpanAttributes} on the link. */
292
+ attributes?: SpanAttributes;
293
+ /** Count of attributes of the link that were dropped due to collection limits */
294
+ droppedAttributesCount?: number;
295
+ }
296
+ /**
297
+ * An interface that represents a span. A span represents a single operation
298
+ * within a trace. Examples of span might include remote procedure calls or a
299
+ * in-process function calls to sub-components. A Trace has a single, top-level
300
+ * "root" Span that in turn may have zero or more child Spans, which in turn
301
+ * may have children.
302
+ *
303
+ * Spans are created by the {@link Tracer.startSpan} method.
304
+ *
305
+ * @since 1.0.0
306
+ */
307
+ interface Span {
308
+ /**
309
+ * Returns the {@link SpanContext} object associated with this Span.
310
+ *
311
+ * Get an immutable, serializable identifier for this span that can be used
312
+ * to create new child spans. Returned SpanContext is usable even after the
313
+ * span ends.
314
+ *
315
+ * @returns the SpanContext object associated with this Span.
316
+ */
317
+ spanContext(): SpanContext;
318
+ /**
319
+ * Sets an attribute to the span.
320
+ *
321
+ * Sets a single Attribute with the key and value passed as arguments.
322
+ *
323
+ * @param key the key for this attribute.
324
+ * @param value the value for this attribute. Setting a value null or
325
+ * undefined is invalid and will result in undefined behavior.
326
+ */
327
+ setAttribute(key: string, value: SpanAttributeValue): this;
328
+ /**
329
+ * Sets attributes to the span.
330
+ *
331
+ * @param attributes the attributes that will be added.
332
+ * null or undefined attribute values
333
+ * are invalid and will result in undefined behavior.
334
+ */
335
+ setAttributes(attributes: SpanAttributes): this;
336
+ /**
337
+ * Adds an event to the Span.
338
+ *
339
+ * @param name the name of the event.
340
+ * @param [attributesOrStartTime] the attributes that will be added; these are
341
+ * associated with this event. Can be also a start time
342
+ * if type is {@type TimeInput} and 3rd param is undefined
343
+ * @param [startTime] start time of the event.
344
+ */
345
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
346
+ /**
347
+ * Adds a single link to the span.
348
+ *
349
+ * Links added after the creation will not affect the sampling decision.
350
+ * It is preferred span links be added at span creation.
351
+ *
352
+ * @param link the link to add.
353
+ */
354
+ addLink(link: Link): this;
355
+ /**
356
+ * Adds multiple links to the span.
357
+ *
358
+ * Links added after the creation will not affect the sampling decision.
359
+ * It is preferred span links be added at span creation.
360
+ *
361
+ * @param links the links to add.
362
+ */
363
+ addLinks(links: Link[]): this;
364
+ /**
365
+ * Sets the status of the span.
366
+ *
367
+ * By default, a span has status {@link SpanStatusCode.UNSET}.
368
+ * Calling this method overrides that default.
369
+ *
370
+ * The status codes have a total order: `OK > ERROR > UNSET`.
371
+ *
372
+ * - Once {@link SpanStatusCode.OK} is set, any further attempts to change
373
+ * the status are ignored.
374
+ * - Any attempt to set {@link SpanStatusCode.UNSET} is always ignored.
375
+ *
376
+ * The `message` field is only used when {@link SpanStatusCode.ERROR} is set.
377
+ * For all other status codes, `message` is ignored.
378
+ *
379
+ * @param status The {@link SpanStatus} to set.
380
+ */
381
+ setStatus(status: SpanStatus): this;
382
+ /**
383
+ * Updates the Span name.
384
+ *
385
+ * This will override the name provided via {@link Tracer.startSpan}.
386
+ *
387
+ * Upon this update, any sampling behavior based on Span name will depend on
388
+ * the implementation.
389
+ *
390
+ * @param name the Span name.
391
+ */
392
+ updateName(name: string): this;
393
+ /**
394
+ * Marks the end of Span execution.
395
+ *
396
+ * Call to End of a Span MUST not have any effects on child spans. Those may
397
+ * still be running and can be ended later.
398
+ *
399
+ * Do not return `this`. The Span generally should not be used after it
400
+ * is ended so chaining is not desired in this context.
401
+ *
402
+ * @param [endTime] the time to set as Span's end time. If not provided,
403
+ * use the current time as the span's end time.
404
+ */
405
+ end(endTime?: TimeInput): void;
406
+ /**
407
+ * Returns the flag whether this span will be recorded.
408
+ *
409
+ * @returns true if this Span is active and recording information like events
410
+ * with the `AddEvent` operation and attributes using `setAttributes`.
411
+ */
412
+ isRecording(): boolean;
413
+ /**
414
+ * Sets exception as a span event
415
+ * @param exception the exception the only accepted values are string or Error
416
+ * @param [time] the time to set as Span's event time. If not provided,
417
+ * use the current time.
418
+ */
419
+ recordException(exception: Exception, time?: TimeInput): void;
420
+ }
421
+ /**
422
+ * @since 1.0.0
423
+ */
424
+ declare enum SpanKind {
425
+ /** Default value. Indicates that the span is used internally. */
426
+ INTERNAL = 0,
427
+ /**
428
+ * Indicates that the span covers server-side handling of an RPC or other
429
+ * remote request.
430
+ */
431
+ SERVER = 1,
432
+ /**
433
+ * Indicates that the span covers the client-side wrapper around an RPC or
434
+ * other remote request.
435
+ */
436
+ CLIENT = 2,
437
+ /**
438
+ * Indicates that the span describes producer sending a message to a
439
+ * broker. Unlike client and server, there is no direct critical path latency
440
+ * relationship between producer and consumer spans.
441
+ */
442
+ PRODUCER = 3,
443
+ /**
444
+ * Indicates that the span describes consumer receiving a message from a
445
+ * broker. Unlike client and server, there is no direct critical path latency
446
+ * relationship between producer and consumer spans.
447
+ */
448
+ CONSUMER = 4
449
+ }
450
+ /**
451
+ * Options needed for span creation
452
+ *
453
+ * @since 1.0.0
454
+ */
455
+ interface SpanOptions {
456
+ /**
457
+ * The SpanKind of a span
458
+ * @default {@link SpanKind.INTERNAL}
459
+ */
460
+ kind?: SpanKind;
461
+ /** A span's attributes */
462
+ attributes?: Attributes;
463
+ /** {@link Link}s span to other spans */
464
+ links?: Link[];
465
+ /** A manually specified start time for the created `Span` object. */
466
+ startTime?: TimeInput;
467
+ /** The new span should be a root span. (Ignore parent from context). */
468
+ root?: boolean;
469
+ }
470
+ /**
471
+ * Tracer provides an interface for creating {@link Span}s.
472
+ *
473
+ * @since 1.0.0
474
+ */
475
+ interface Tracer {
476
+ /**
477
+ * Starts a new {@link Span}. Start the span without setting it on context.
478
+ *
479
+ * This method do NOT modify the current Context.
480
+ *
481
+ * @param name The name of the span
482
+ * @param [options] SpanOptions used for span creation
483
+ * @param [context] Context to use to extract parent
484
+ * @returns Span The newly created span
485
+ * @example
486
+ * const span = tracer.startSpan('op');
487
+ * span.setAttribute('key', 'value');
488
+ * span.end();
489
+ */
490
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
491
+ /**
492
+ * Starts a new {@link Span} and calls the given function passing it the
493
+ * created span as first argument.
494
+ * Additionally the new span gets set in context and this context is activated
495
+ * for the duration of the function call.
496
+ *
497
+ * @param name The name of the span
498
+ * @param [options] SpanOptions used for span creation
499
+ * @param [context] Context to use to extract parent
500
+ * @param fn function called in the context of the span and receives the newly created span as an argument
501
+ * @returns return value of fn
502
+ * @example
503
+ * const something = tracer.startActiveSpan('op', span => {
504
+ * try {
505
+ * do some work
506
+ * span.setStatus({code: SpanStatusCode.OK});
507
+ * return something;
508
+ * } catch (err) {
509
+ * span.setStatus({
510
+ * code: SpanStatusCode.ERROR,
511
+ * message: err.message,
512
+ * });
513
+ * throw err;
514
+ * } finally {
515
+ * span.end();
516
+ * }
517
+ * });
518
+ *
519
+ * @example
520
+ * const span = tracer.startActiveSpan('op', span => {
521
+ * try {
522
+ * do some work
523
+ * return span;
524
+ * } catch (err) {
525
+ * span.setStatus({
526
+ * code: SpanStatusCode.ERROR,
527
+ * message: err.message,
528
+ * });
529
+ * throw err;
530
+ * }
531
+ * });
532
+ * do some more work
533
+ * span.end();
534
+ */
535
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
536
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
537
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
538
+ }
539
+ /**
540
+ * The slice of a Lunora function `ctx` this bridge needs — the dispatch's span
541
+ * handle and the span factory.
542
+ *
543
+ * Structural rather than `QueryCtx`/`MutationCtx`/`ActionCtx` so one signature
544
+ * accepts all three (and a test double), while still being expressed in the real
545
+ * {@link SpanHandle} / {@link LunoraTracer} types now that this lives beside them.
546
+ */
547
+ interface LunoraTraceContext {
548
+ /** The dispatch's own span handle — supplies the trace this bridge joins. */
549
+ readonly span: SpanHandle;
550
+ /** The span factory: `ctx.trace(name, fn, options)`. */
551
+ readonly trace: LunoraTracer;
552
+ }
553
+ /** Options for {@link createOtelTracer}. */
554
+ interface OtelTracerOptions {
555
+ /**
556
+ * Prefix applied to every span name the bridge creates, e.g. `"ai."`.
557
+ *
558
+ * Useful when a third-party library emits generic names (`doGenerate`,
559
+ * `execute`) that would be ambiguous next to your own spans in a collector.
560
+ * Off by default — renaming someone else's spans breaks the dashboards their
561
+ * own documentation tells you to build.
562
+ */
563
+ namePrefix?: string;
564
+ }
565
+ /**
566
+ * Adapt a Lunora `ctx` into an `@opentelemetry/api` `Tracer`.
567
+ *
568
+ * Spans created through it are ordinary `ctx.trace` spans: they join the
569
+ * request's trace, appear in the studio waterfall, ride the same sampling
570
+ * decision, and export through the same OTLP sink. Nothing in the runtime has to
571
+ * know they came from a third-party library.
572
+ *
573
+ * **Parenting.** The parent is read from the `Context` the caller threads —
574
+ * `startSpan(name, options, ctx)` parents to `trace.getSpanContext(ctx)` when it
575
+ * names a span in THIS trace — and falls back to the dispatch when no Context is
576
+ * passed (or it carries a span from a different trace, which would be a lie to
577
+ * parent to). What the bridge does NOT do is track a dynamically scoped "current"
578
+ * span, because that needs `AsyncLocalStorage` — unavailable in the Durable
579
+ * Object profile (see the module doc). `startActiveSpan` therefore runs its
580
+ * callback with the new span passed in, exactly as the interface requires, but
581
+ * does NOT make it ambient: `trace.getActiveSpan()` inside that callback still
582
+ * reports whatever the global provider says. A library that threads its `Context`
583
+ * or the span it is handed (the common case, and what the AI SDK does) nests
584
+ * correctly; one that relies on ambient context gets a flat trace instead of a
585
+ * nested one — flatter, never wrong, never lost.
586
+ *
587
+ * **Ids and sampling.** The `SpanContext` returned by `startSpan` is the one the
588
+ * span is RECORDED under: the id is minted here and handed to `ctx.trace` as its
589
+ * span identity, so a `traceparent` a library builds from it names a span that
590
+ * actually reaches the collector. `traceFlags` carries the trace's settled
591
+ * sampling verdict rather than a hardcoded SAMPLED, so a sampled-out trace is not
592
+ * announced downstream as kept.
593
+ * @param context Any Lunora function context (`QueryCtx` / `MutationCtx` / `ActionCtx`).
594
+ * @param options See {@link OtelTracerOptions}.
595
+ */
596
+ declare const createOtelTracer: (context: LunoraTraceContext, options?: OtelTracerOptions) => Tracer;
597
+ export { type LunoraTraceContext, type OtelTracerOptions, createOtelTracer };