@opendatalabs/personal-server-ts-core 1.8.0 → 1.9.0

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 (61) hide show
  1. package/dist/api/index.d.ts +19 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +23 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/derivatives/api.d.ts +33 -0
  6. package/dist/derivatives/api.d.ts.map +1 -0
  7. package/dist/derivatives/api.js +216 -0
  8. package/dist/derivatives/api.js.map +1 -0
  9. package/dist/derivatives/compute.d.ts +106 -0
  10. package/dist/derivatives/compute.d.ts.map +1 -0
  11. package/dist/derivatives/compute.js +373 -0
  12. package/dist/derivatives/compute.js.map +1 -0
  13. package/dist/derivatives/index.d.ts +9 -0
  14. package/dist/derivatives/index.d.ts.map +1 -0
  15. package/dist/derivatives/index.js +9 -0
  16. package/dist/derivatives/index.js.map +1 -0
  17. package/dist/derivatives/inference.d.ts +102 -0
  18. package/dist/derivatives/inference.d.ts.map +1 -0
  19. package/dist/derivatives/inference.js +159 -0
  20. package/dist/derivatives/inference.js.map +1 -0
  21. package/dist/derivatives/prompt.d.ts +64 -0
  22. package/dist/derivatives/prompt.d.ts.map +1 -0
  23. package/dist/derivatives/prompt.js +186 -0
  24. package/dist/derivatives/prompt.js.map +1 -0
  25. package/dist/derivatives/registration.d.ts +53 -0
  26. package/dist/derivatives/registration.d.ts.map +1 -0
  27. package/dist/derivatives/registration.js +163 -0
  28. package/dist/derivatives/registration.js.map +1 -0
  29. package/dist/derivatives/scheduler.d.ts +56 -0
  30. package/dist/derivatives/scheduler.d.ts.map +1 -0
  31. package/dist/derivatives/scheduler.js +151 -0
  32. package/dist/derivatives/scheduler.js.map +1 -0
  33. package/dist/derivatives/store.d.ts +14 -0
  34. package/dist/derivatives/store.d.ts.map +1 -0
  35. package/dist/derivatives/store.js +75 -0
  36. package/dist/derivatives/store.js.map +1 -0
  37. package/dist/derivatives/types.d.ts +72 -0
  38. package/dist/derivatives/types.d.ts.map +1 -0
  39. package/dist/derivatives/types.js +25 -0
  40. package/dist/derivatives/types.js.map +1 -0
  41. package/dist/errors/catalog.d.ts +20 -0
  42. package/dist/errors/catalog.d.ts.map +1 -1
  43. package/dist/errors/catalog.js +26 -0
  44. package/dist/errors/catalog.js.map +1 -1
  45. package/dist/schemas/server-config.d.ts +12 -0
  46. package/dist/schemas/server-config.d.ts.map +1 -1
  47. package/dist/schemas/server-config.js +29 -0
  48. package/dist/schemas/server-config.js.map +1 -1
  49. package/dist/sync/workers/download.d.ts +14 -0
  50. package/dist/sync/workers/download.d.ts.map +1 -1
  51. package/dist/sync/workers/download.js +23 -0
  52. package/dist/sync/workers/download.js.map +1 -1
  53. package/dist/test-utils/index.d.ts +1 -0
  54. package/dist/test-utils/index.d.ts.map +1 -1
  55. package/dist/test-utils/index.js +1 -0
  56. package/dist/test-utils/index.js.map +1 -1
  57. package/dist/test-utils/memory-storage.d.ts +12 -0
  58. package/dist/test-utils/memory-storage.d.ts.map +1 -0
  59. package/dist/test-utils/memory-storage.js +146 -0
  60. package/dist/test-utils/memory-storage.js.map +1 -0
  61. package/package.json +5 -1
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The compute job: answer one registered question from local data and
3
+ * write the answer as a derivative record (owner path, `$lineage` = the
4
+ * source data points).
5
+ */
6
+ import type { ScopeDeletionTracker } from "../sync/scope-deletions.js";
7
+ import type { DataStoragePort, RuntimeAvailabilityPort } from "../ports/index.js";
8
+ import { type DataWritePolicyPorts } from "../policy/data-write.js";
9
+ import { type InferenceProvider } from "./inference.js";
10
+ import type { QuestionRegistration, QuestionStore } from "./types.js";
11
+ export interface ComputeLogger {
12
+ info?(payload: Record<string, unknown>, message: string): void;
13
+ warn?(payload: Record<string, unknown>, message: string): void;
14
+ }
15
+ export interface ComputeSyncNotifier {
16
+ notifyNewData?(): void;
17
+ trigger?(): Promise<void>;
18
+ }
19
+ export interface QuestionComputeDeps {
20
+ storage: DataStoragePort;
21
+ store: QuestionStore;
22
+ provider: InferenceProvider;
23
+ /** Required: lineage ids are keccak256(owner, scope). */
24
+ serverOwner: `0x${string}` | undefined;
25
+ /** Newest-first items kept per source scope (default 50). */
26
+ maxSourceItems?: number;
27
+ maxSourceChars?: number;
28
+ maxTokens?: number;
29
+ /** Uploads the derivative after it is written locally. */
30
+ syncManager?: ComputeSyncNotifier | null;
31
+ /** Re-add marker, same as an HTTP ingest (see api/index.ts). */
32
+ scopeDeletions?: ScopeDeletionTracker;
33
+ /**
34
+ * When present, a builder-registered question re-checks its write grant
35
+ * before every compute (revoked / expired / scope no longer covered =>
36
+ * failed, no inference call). Owner registrations skip the check.
37
+ */
38
+ writePolicyPorts?: DataWritePolicyPorts;
39
+ /**
40
+ * Called after the derivative is written and the question marked ready,
41
+ * so a question that reads THIS derived scope recomputes in turn
42
+ * (A -> B -> C chains). The compute path never goes through the HTTP
43
+ * ingest hook.
44
+ */
45
+ onDerivedWritten?: (event: {
46
+ scope: string;
47
+ collectedAt: string;
48
+ lineageSources: string[];
49
+ }) => void;
50
+ /** When unavailable the compute is skipped and the status left as is. */
51
+ runtimeAvailability?: RuntimeAvailabilityPort;
52
+ /**
53
+ * Backoff between retries of a transient inference or gateway failure
54
+ * (default 1s, 4s: three attempts). Tests pass zeros.
55
+ */
56
+ retryDelaysMs?: readonly number[];
57
+ sleep?: (ms: number) => Promise<void>;
58
+ now?: () => Date;
59
+ logger?: ComputeLogger;
60
+ }
61
+ export type ComputeOutcome = {
62
+ status: "ready";
63
+ registration: QuestionRegistration;
64
+ } | {
65
+ status: "failed";
66
+ registration: QuestionRegistration;
67
+ error: string;
68
+ } | {
69
+ status: "skipped";
70
+ reason: "unknown-question" | "runtime-unavailable";
71
+ };
72
+ /** The record written into the derived scope. */
73
+ export interface DerivativeAnswerRecord {
74
+ questionId: string;
75
+ question: string;
76
+ answer: string;
77
+ evidence: string | null;
78
+ model: string;
79
+ computedAt: string;
80
+ sources: Array<{
81
+ scope: string;
82
+ version: number;
83
+ collectedAt: string;
84
+ }>;
85
+ /** Caller-side lineage field, mirrored by the server into `$lineage`. */
86
+ lineage: `0x${string}`[];
87
+ inference?: {
88
+ receiptId?: string;
89
+ aciIdentity?: string;
90
+ };
91
+ [key: string]: unknown;
92
+ }
93
+ /**
94
+ * Version stamp for the derived record, second precision like an HTTP
95
+ * ingest. A recompute inside the same second as the previous one would
96
+ * collide on the (scope, collectedAt) path, so the stamp advances past any
97
+ * version the scope already holds (bounded: at most one minute ahead).
98
+ */
99
+ export declare function collectedAtStamp(now: () => Date, isTaken: (collectedAt: string) => boolean): string;
100
+ /**
101
+ * Compute one question end to end. Never throws for a compute failure: the
102
+ * registration is marked `failed` with a short reason and the outcome says
103
+ * so. Throws only when the store itself fails.
104
+ */
105
+ export declare function computeQuestion(questionId: string, deps: QuestionComputeDeps): Promise<ComputeOutcome>;
106
+ //# sourceMappingURL=compute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/derivatives/compute.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAO/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OA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AAE,QAAQ,CAAC;IAAC,YAAY,EAAE,oBAAoB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,kBAAkB,GAAG,qBAAqB,CAAA;CAAE,CAAC;AAkC9E,iDAAiD;AACjD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxE,yEAAyE;IACzE,OAAO,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAmBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,IAAI,EACf,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,GACxC,MAAM,CAUR;AAwLD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,cAAc,CAAC,CAmKzB"}
@@ -0,0 +1,373 @@
1
+ /**
2
+ * The compute job: answer one registered question from local data and
3
+ * write the answer as a derivative record (owner path, `$lineage` = the
4
+ * source data points).
5
+ */
6
+ import { DerivativeCycleError, DerivativeSourceNotGrantedError, ProtocolError, } from "../errors/catalog.js";
7
+ import { resolveReadDeletion } from "../api/index.js";
8
+ import { LOCAL_SCOPE_SCAN_PAGE, readStoredLineage, } from "../lineage/lineage.js";
9
+ import { uncoveredSourceScopes } from "./registration.js";
10
+ import { ingestDataContract } from "../contracts/data.js";
11
+ import { isBinaryEnvelope } from "../contracts/binary.js";
12
+ import { assertDerivedScopeNaming } from "../lineage/lineage.js";
13
+ import { computeDataPointId } from "../sync/data-point-id.js";
14
+ import { verifyDataWritePolicy, } from "../policy/data-write.js";
15
+ import { InferenceRequestError } from "./inference.js";
16
+ import { buildQuestionMessages, parseAnswer, trimSourceData, } from "./prompt.js";
17
+ const DEFAULT_RETRY_DELAYS_MS = [1_000, 4_000];
18
+ /** Transient: no response, rate limited or a provider-side failure. */
19
+ function isRetryableInferenceError(err) {
20
+ return (err instanceof InferenceRequestError &&
21
+ (err.status === null || err.status === 429 || err.status >= 500));
22
+ }
23
+ /**
24
+ * Run `attempt` up to `delays.length + 1` times while `retryable(err)`;
25
+ * anything else (a ProtocolError, a permanent status) surfaces at once.
26
+ */
27
+ async function withRetries(deps, attempt, retryable) {
28
+ const delays = deps.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS;
29
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
30
+ for (let index = 0;; index += 1) {
31
+ try {
32
+ return await attempt();
33
+ }
34
+ catch (err) {
35
+ if (index >= delays.length || !retryable(err))
36
+ throw err;
37
+ await sleep(delays[index]);
38
+ }
39
+ }
40
+ }
41
+ /** A failure message safe to persist: never the prompt, never the data. */
42
+ class ComputeFailure extends Error {
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = "ComputeFailure";
46
+ }
47
+ }
48
+ function shortError(err) {
49
+ if (err instanceof ComputeFailure)
50
+ return err.message;
51
+ if (err instanceof InferenceRequestError)
52
+ return err.message;
53
+ if (err instanceof ProtocolError)
54
+ return `${err.errorCode}: ${err.message}`;
55
+ // Unknown errors may quote data (a JSON parse error echoes its input);
56
+ // keep the class name only.
57
+ return `compute failed (${err instanceof Error ? err.name : "Error"})`;
58
+ }
59
+ /**
60
+ * Version stamp for the derived record, second precision like an HTTP
61
+ * ingest. A recompute inside the same second as the previous one would
62
+ * collide on the (scope, collectedAt) path, so the stamp advances past any
63
+ * version the scope already holds (bounded: at most one minute ahead).
64
+ */
65
+ export function collectedAtStamp(now, isTaken) {
66
+ const base = now();
67
+ base.setUTCMilliseconds(0);
68
+ for (let bump = 0; bump < 60; bump += 1) {
69
+ const candidate = new Date(base.getTime() + bump * 1000)
70
+ .toISOString()
71
+ .replace(/\.\d{3}Z$/, "Z");
72
+ if (!isTaken(candidate))
73
+ return candidate;
74
+ }
75
+ throw new ComputeFailure("could not allocate a version stamp");
76
+ }
77
+ async function tombstoneMarker(scopeDeletions, scope) {
78
+ if (!scopeDeletions)
79
+ return null;
80
+ const verdict = await scopeDeletions.resolve(scope);
81
+ if (!verdict.deleted || verdict.version === null)
82
+ return null;
83
+ const version = Number(verdict.version);
84
+ return Number.isSafeInteger(version) ? version : null;
85
+ }
86
+ /**
87
+ * `dataPointId -> scope` for every scope in the local index, used to walk
88
+ * stored lineage locally. Paged like the lineage resolver.
89
+ */
90
+ function localScopesById(storage, serverOwner) {
91
+ const byId = new Map();
92
+ for (let offset = 0;; offset += LOCAL_SCOPE_SCAN_PAGE) {
93
+ const { scopes, total } = storage.listScopes({
94
+ limit: LOCAL_SCOPE_SCAN_PAGE,
95
+ offset,
96
+ });
97
+ for (const summary of scopes) {
98
+ byId.set(computeDataPointId(serverOwner, summary.scope), summary.scope);
99
+ }
100
+ if (scopes.length === 0 || offset + scopes.length >= total)
101
+ break;
102
+ }
103
+ return byId;
104
+ }
105
+ /**
106
+ * Cycle guard on ACTUAL lineage, for cycles the per-store registration
107
+ * check cannot see (two replicas each holding one half: B <- A here, A <- B
108
+ * there, ping-ponging through sync). Walks `$lineage` from every source's
109
+ * latest local version through the local index; reaching the derived data
110
+ * point id means this question would consume its own output. Bounded by
111
+ * the visited set.
112
+ */
113
+ async function assertNoLineageCycle(deps, registration, serverOwner, sourceLineage) {
114
+ const derivedId = computeDataPointId(serverOwner, registration.derivedScope);
115
+ let byId = null;
116
+ const visited = new Set();
117
+ const stack = [];
118
+ for (const [scope, sources] of sourceLineage) {
119
+ for (const id of sources)
120
+ stack.push({ id, path: [scope] });
121
+ }
122
+ while (stack.length > 0) {
123
+ const { id, path } = stack.pop();
124
+ if (id === derivedId) {
125
+ throw new DerivativeCycleError({
126
+ derivedScope: registration.derivedScope,
127
+ path: [registration.derivedScope, ...path, registration.derivedScope],
128
+ });
129
+ }
130
+ if (visited.has(id))
131
+ continue;
132
+ visited.add(id);
133
+ byId ??= localScopesById(deps.storage, serverOwner);
134
+ const scope = byId.get(id);
135
+ if (!scope)
136
+ continue;
137
+ const entry = deps.storage.findEntry({ scope });
138
+ if (!entry)
139
+ continue;
140
+ let sources = [];
141
+ try {
142
+ const envelope = await deps.storage.readEnvelope(scope, entry.collectedAt);
143
+ sources = readStoredLineage(envelope.data)?.sources ?? [];
144
+ }
145
+ catch {
146
+ // Unreadable or malformed lineage: nothing further to walk here.
147
+ }
148
+ for (const next of sources)
149
+ stack.push({ id: next, path: [...path, scope] });
150
+ }
151
+ }
152
+ async function loadSource(deps, scope) {
153
+ const entry = deps.storage.findEntry({ scope });
154
+ // The same deletion gate a read applies: a tombstoned scope is refused
155
+ // (410 on the read path) whether or not a stale local copy remains.
156
+ const deletion = await resolveReadDeletion({ scopeDeletions: deps.scopeDeletions, serverOwner: deps.serverOwner }, scope, entry);
157
+ if (deletion) {
158
+ throw new ComputeFailure(`source scope ${scope} is deleted`);
159
+ }
160
+ if (!entry) {
161
+ throw new ComputeFailure(`source scope ${scope} has no local data`);
162
+ }
163
+ let envelope;
164
+ try {
165
+ envelope = await deps.storage.readEnvelope(scope, entry.collectedAt);
166
+ }
167
+ catch {
168
+ throw new ComputeFailure(`source scope ${scope} could not be read`);
169
+ }
170
+ let lineageSources = [];
171
+ try {
172
+ lineageSources = readStoredLineage(envelope.data)?.sources ?? [];
173
+ }
174
+ catch {
175
+ // Malformed stored lineage: treated as a root for the cycle walk.
176
+ }
177
+ const raw = isBinaryEnvelope(envelope)
178
+ ? {
179
+ binary: true,
180
+ note: "binary record; its content is not included in the prompt",
181
+ }
182
+ : envelope.data;
183
+ const trimmed = trimSourceData(raw, {
184
+ maxItems: deps.maxSourceItems,
185
+ maxChars: deps.maxSourceChars,
186
+ });
187
+ return {
188
+ source: {
189
+ scope,
190
+ collectedAt: entry.collectedAt,
191
+ version: entry.version,
192
+ data: trimmed.data,
193
+ kept: trimmed.kept,
194
+ total: trimmed.total,
195
+ truncated: trimmed.truncated,
196
+ },
197
+ lineageSources,
198
+ };
199
+ }
200
+ /**
201
+ * A builder question re-checks its grant before every compute: the write
202
+ * permission on the derived scope (revocation, expiry, coverage) AND read
203
+ * coverage of every source scope, since the answer exposes the sources to
204
+ * the builder. Gateway transport failures are retried; policy failures
205
+ * (ProtocolErrors) fail closed at once.
206
+ */
207
+ async function assertGrantStillValid(deps, registration) {
208
+ if (registration.registeredBy.kind !== "builder")
209
+ return;
210
+ if (!deps.writePolicyPorts) {
211
+ throw new ComputeFailure("builder grant verification is not configured");
212
+ }
213
+ if (!deps.serverOwner) {
214
+ throw new ComputeFailure("server owner is not configured");
215
+ }
216
+ const { builder, grantId } = registration.registeredBy;
217
+ const ports = deps.writePolicyPorts;
218
+ const serverOwner = deps.serverOwner;
219
+ const grant = await withRetries(deps, () => verifyDataWritePolicy({
220
+ signer: builder,
221
+ grantId,
222
+ requestedScope: registration.derivedScope,
223
+ serverOwner,
224
+ }, ports), (err) => !(err instanceof ProtocolError));
225
+ const uncovered = uncoveredSourceScopes(registration.sourceScopes, grant.scopes ?? []);
226
+ if (uncovered.length > 0) {
227
+ throw new DerivativeSourceNotGrantedError({ scopes: uncovered });
228
+ }
229
+ }
230
+ /**
231
+ * Compute one question end to end. Never throws for a compute failure: the
232
+ * registration is marked `failed` with a short reason and the outcome says
233
+ * so. Throws only when the store itself fails.
234
+ */
235
+ export async function computeQuestion(questionId, deps) {
236
+ const now = deps.now ?? (() => new Date());
237
+ if ((await deps.runtimeAvailability?.isAvailable()) === false) {
238
+ return { status: "skipped", reason: "runtime-unavailable" };
239
+ }
240
+ const registration = await deps.store.get(questionId);
241
+ if (!registration)
242
+ return { status: "skipped", reason: "unknown-question" };
243
+ try {
244
+ if (!deps.serverOwner) {
245
+ throw new ComputeFailure("server owner is not configured");
246
+ }
247
+ const serverOwner = deps.serverOwner;
248
+ await assertGrantStillValid(deps, registration);
249
+ // Defense in depth: the rule was checked at registration; a registration
250
+ // row edited by hand must still not produce a leaking derivative.
251
+ assertDerivedScopeNaming(registration.derivedScope, registration.sourceScopes);
252
+ const sources = [];
253
+ const sourceLineage = new Map();
254
+ for (const scope of registration.sourceScopes) {
255
+ const loaded = await loadSource(deps, scope);
256
+ sources.push(loaded.source);
257
+ sourceLineage.set(scope, loaded.lineageSources);
258
+ }
259
+ await assertNoLineageCycle(deps, registration, serverOwner, sourceLineage);
260
+ const messages = buildQuestionMessages({
261
+ question: registration.question,
262
+ sources,
263
+ });
264
+ const model = registration.model ?? deps.provider.defaultModel;
265
+ const reply = await withRetries(deps, () => deps.provider.chat({ model, messages, maxTokens: deps.maxTokens }), isRetryableInferenceError);
266
+ const parsed = parseAnswer(reply.content);
267
+ const computedAt = now().toISOString();
268
+ const lineageIds = registration.sourceScopes.map((scope) => computeDataPointId(serverOwner, scope));
269
+ const record = {
270
+ questionId: registration.questionId,
271
+ question: registration.question,
272
+ answer: parsed.answer,
273
+ evidence: parsed.evidence,
274
+ model,
275
+ computedAt,
276
+ sources: sources.map((source) => ({
277
+ scope: source.scope,
278
+ version: source.version,
279
+ collectedAt: source.collectedAt,
280
+ })),
281
+ lineage: lineageIds,
282
+ ...(reply.receiptId || reply.aciIdentity
283
+ ? {
284
+ inference: {
285
+ ...(reply.receiptId ? { receiptId: reply.receiptId } : {}),
286
+ ...(reply.aciIdentity ? { aciIdentity: reply.aciIdentity } : {}),
287
+ },
288
+ }
289
+ : {}),
290
+ };
291
+ const lineage = {
292
+ sources: lineageIds,
293
+ writtenAt: computedAt,
294
+ };
295
+ // `findEntry({ at })` may answer the closest version, so compare exactly.
296
+ const collectedAt = collectedAtStamp(now, (candidate) => deps.storage.findEntry({
297
+ scope: registration.derivedScope,
298
+ at: candidate,
299
+ })?.collectedAt === candidate);
300
+ const written = await ingestDataContract({
301
+ storage: deps.storage,
302
+ scopeParam: registration.derivedScope,
303
+ body: record,
304
+ collectedAt,
305
+ status: deps.syncManager ? "syncing" : "stored",
306
+ lineage,
307
+ afterTombstoneVersion: await tombstoneMarker(deps.scopeDeletions, registration.derivedScope),
308
+ });
309
+ if (!written.ok) {
310
+ throw new ComputeFailure(`derived record rejected: ${written.body.error}`);
311
+ }
312
+ const entry = deps.storage.findEntry({
313
+ scope: registration.derivedScope,
314
+ at: collectedAt,
315
+ });
316
+ const updated = await deps.store.update(questionId, {
317
+ status: "ready",
318
+ error: null,
319
+ updatedAt: computedAt,
320
+ lastComputedAt: computedAt,
321
+ derivedVersion: entry?.version ?? null,
322
+ derivedCollectedAt: collectedAt,
323
+ });
324
+ if (deps.syncManager?.notifyNewData) {
325
+ deps.syncManager.notifyNewData();
326
+ }
327
+ else if (deps.syncManager?.trigger) {
328
+ void deps.syncManager.trigger().catch(() => undefined);
329
+ }
330
+ try {
331
+ deps.onDerivedWritten?.({
332
+ scope: registration.derivedScope,
333
+ collectedAt,
334
+ lineageSources: lineageIds,
335
+ });
336
+ }
337
+ catch (err) {
338
+ deps.logger?.warn?.({
339
+ questionId,
340
+ derivedScope: registration.derivedScope,
341
+ error: err instanceof Error ? err.name : String(err),
342
+ }, "onDerivedWritten hook failed; derivative already written");
343
+ }
344
+ deps.logger?.info?.({
345
+ questionId,
346
+ derivedScope: registration.derivedScope,
347
+ sourceScopes: registration.sourceScopes,
348
+ model,
349
+ version: entry?.version ?? null,
350
+ receiptId: reply.receiptId ?? null,
351
+ }, "Derivative question computed");
352
+ return {
353
+ status: "ready",
354
+ registration: updated ?? { ...registration, status: "ready" },
355
+ };
356
+ }
357
+ catch (err) {
358
+ const error = shortError(err);
359
+ const at = now().toISOString();
360
+ const updated = await deps.store.update(questionId, {
361
+ status: "failed",
362
+ error,
363
+ updatedAt: at,
364
+ });
365
+ deps.logger?.warn?.({ questionId, derivedScope: registration.derivedScope, error }, "Derivative question compute failed");
366
+ return {
367
+ status: "failed",
368
+ registration: updated ?? { ...registration, status: "failed", error },
369
+ error,
370
+ };
371
+ }
372
+ }
373
+ //# sourceMappingURL=compute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute.js","sourceRoot":"","sources":["../../src/derivatives/compute.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,oBAAoB,EACpB,+BAA+B,EAC/B,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAM9D,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,cAAc,GAEf,MAAM,aAAa,CAAC;AA6DrB,MAAM,uBAAuB,GAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAElE,uEAAuE;AACvE,SAAS,yBAAyB,CAAC,GAAY;IAC7C,OAAO,CACL,G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AC,MAAM,EAAE,IAAI,EAAE,CACjB;YACE,UAAU;YACV,YAAY,EAAE,YAAY,CAAC,YAAY;YACvC,YAAY,EAAE,YAAY,CAAC,YAAY;YACvC,KAAK;YACL,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,IAAI;YAC/B,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI;SACnC,EACD,8BAA8B,CAC/B,CAAC;QACF,OAAO;YACL,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,OAAO,IAAI,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE;SAC9D,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;YAClD,MAAM,EAAE,QAAQ;YAChB,KAAK;YACL,SAAS,EAAE,EAAE;SACd,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CACjB,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,EAAE,KAAK,EAAE,EAC9D,oCAAoC,CACrC,CAAC;QACF,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,OAAO,IAAI,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;YACrE,KAAK;SACN,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { questionRegistrationView, type QuestionRegisteredBy, type QuestionRegistration, type QuestionRegistrationPatch, type QuestionRegistrationView, type QuestionStatus, type QuestionStore, type QuestionStoreListFilter, } from "./types.js";
2
+ export { createInMemoryQuestionStore, matchesQuestionFilter, sortQuestions, } from "./store.js";
3
+ export { MAX_ECHOED_SCOPE_CHARS, MAX_MODEL_CHARS, MAX_QUESTION_CHARS, MAX_QUESTION_SOURCE_SCOPES, createQuestionRegistration, findDerivationCycle, parseQuestionInput, uncoveredSourceScopes, type CreateQuestionRegistrationInput, type ParsedQuestionInput, } from "./registration.js";
4
+ export { DEFAULT_MAX_SOURCE_CHARS, DEFAULT_MAX_SOURCE_ITEMS, SYSTEM_PROMPT, buildQuestionMessages, parseAnswer, sortNewestFirst, trimSourceData, type ParsedAnswer, type PromptSource, type TrimResult, } from "./prompt.js";
5
+ export { DEFAULT_INFERENCE_BASE_URL, DEFAULT_INFERENCE_MAX_TOKENS, DEFAULT_INFERENCE_MODEL, DEFAULT_INFERENCE_REQUEST_FIELDS, DEFAULT_INFERENCE_TIMEOUT_MS, InferenceRequestError, createFakeInferenceProvider, createOpenAiCompatibleInferenceProvider, type FakeInferenceProvider, type FakeInferenceProviderOptions, type InferenceChatInput, type InferenceChatResult, type InferenceMessage, type InferenceProvider, type InferenceRequestEncryption, type InferenceRole, type InferenceUsage, type OpenAiCompatibleInferenceOptions, } from "./inference.js";
6
+ export { computeQuestion, type ComputeLogger, type ComputeOutcome, type ComputeSyncNotifier, type DerivativeAnswerRecord, type QuestionComputeDeps, } from "./compute.js";
7
+ export { createRecomputeScheduler, type RecomputeScheduler, type RecomputeSchedulerOptions, type SchedulerTimers, } from "./scheduler.js";
8
+ export { MAX_QUESTION_BODY_BYTES, handlePersonalServerDerivativesRequest, type PersonalServerDerivativesApiDeps, } from "./api.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/derivatives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,uBAAuB,GAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,+BAA+B,EACpC,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,gCAAgC,EAChC,4BAA4B,EAC5B,qBAAqB,EACrB,2BAA2B,EAC3B,uCAAuC,EACvC,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gCAAgC,GACtC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,sCAAsC,EACtC,KAAK,gCAAgC,GACtC,MAAM,UAAU,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { questionRegistrationView, } from "./types.js";
2
+ export { createInMemoryQuestionStore, matchesQuestionFilter, sortQuestions, } from "./store.js";
3
+ export { MAX_ECHOED_SCOPE_CHARS, MAX_MODEL_CHARS, MAX_QUESTION_CHARS, MAX_QUESTION_SOURCE_SCOPES, createQuestionRegistration, findDerivationCycle, parseQuestionInput, uncoveredSourceScopes, } from "./registration.js";
4
+ export { DEFAULT_MAX_SOURCE_CHARS, DEFAULT_MAX_SOURCE_ITEMS, SYSTEM_PROMPT, buildQuestionMessages, parseAnswer, sortNewestFirst, trimSourceData, } from "./prompt.js";
5
+ export { DEFAULT_INFERENCE_BASE_URL, DEFAULT_INFERENCE_MAX_TOKENS, DEFAULT_INFERENCE_MODEL, DEFAULT_INFERENCE_REQUEST_FIELDS, DEFAULT_INFERENCE_TIMEOUT_MS, InferenceRequestError, createFakeInferenceProvider, createOpenAiCompatibleInferenceProvider, } from "./inference.js";
6
+ export { computeQuestion, } from "./compute.js";
7
+ export { createRecomputeScheduler, } from "./scheduler.js";
8
+ export { MAX_QUESTION_BODY_BYTES, handlePersonalServerDerivativesRequest, } from "./api.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/derivatives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAQzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,GAGtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,cAAc,GAIf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,gCAAgC,EAChC,4BAA4B,EAC5B,qBAAqB,EACrB,2BAA2B,EAC3B,uCAAuC,GAWxC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,GAMhB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,wBAAwB,GAIzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,sCAAsC,GAEvC,MAAM,UAAU,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Inference provider adapter for the derivative compute layer.
3
+ *
4
+ * One implementation: OpenAI-compatible chat completions over `fetch`, so it
5
+ * runs unchanged in Node and in the browser (PS-Lite). In production the
6
+ * base URL is the Vana inference relay, which holds the provider key; the
7
+ * optional API key header exists for local development against a provider
8
+ * directly.
9
+ *
10
+ * E2EE SEAM (not implemented): the Phala confidential-inference E2EE v2
11
+ * protocol encrypts each `messages[i].content` to the model's public key
12
+ * and adds the headers X-E2EE-Version, X-Client-Pub-Key, X-Model-Pub-Key,
13
+ * X-E2EE-Nonce and X-E2EE-Timestamp; the response content comes back
14
+ * encrypted to the client key. `InferenceRequestEncryption` below is the
15
+ * hook where that lands: it sees the outgoing messages + headers and the
16
+ * incoming content + headers, and nothing else in this module has to change.
17
+ */
18
+ export type InferenceRole = "system" | "user" | "assistant";
19
+ export interface InferenceMessage {
20
+ role: InferenceRole;
21
+ content: string;
22
+ }
23
+ export interface InferenceChatInput {
24
+ model: string;
25
+ messages: InferenceMessage[];
26
+ maxTokens?: number;
27
+ }
28
+ export interface InferenceUsage {
29
+ promptTokens?: number;
30
+ completionTokens?: number;
31
+ totalTokens?: number;
32
+ }
33
+ export interface InferenceChatResult {
34
+ content: string;
35
+ usage?: InferenceUsage;
36
+ /** `x-receipt-id` response header when the relay / provider sets one. */
37
+ receiptId?: string;
38
+ /** `x-aci-identity` response header (attested compute identity). */
39
+ aciIdentity?: string;
40
+ }
41
+ export interface InferenceProvider {
42
+ /** Model used when a registration names none. */
43
+ readonly defaultModel: string;
44
+ chat(input: InferenceChatInput): Promise<InferenceChatResult>;
45
+ }
46
+ /**
47
+ * E2EE seam. Implement to encrypt message contents end to end (Phala E2EE
48
+ * v2); absent = plaintext over TLS to the relay. Both hooks run inside
49
+ * `createOpenAiCompatibleInferenceProvider`, around the single fetch.
50
+ */
51
+ export interface InferenceRequestEncryption {
52
+ /** Encrypt `messages[i].content` and add the X-E2EE-* request headers. */
53
+ encryptRequest(input: {
54
+ messages: InferenceMessage[];
55
+ headers: Headers;
56
+ }): Promise<{
57
+ messages: InferenceMessage[];
58
+ }>;
59
+ /** Decrypt the assistant content using the response headers. */
60
+ decryptResponse(input: {
61
+ content: string;
62
+ headers: Headers;
63
+ }): Promise<string>;
64
+ }
65
+ export declare const DEFAULT_INFERENCE_BASE_URL = "https://inference.phala.com/v1";
66
+ export declare const DEFAULT_INFERENCE_MODEL = "z-ai/glm-5.2";
67
+ export declare const DEFAULT_INFERENCE_TIMEOUT_MS = 120000;
68
+ export declare const DEFAULT_INFERENCE_MAX_TOKENS = 2048;
69
+ export interface OpenAiCompatibleInferenceOptions {
70
+ /** Chat completions base, e.g. `https://inference.phala.com/v1`. */
71
+ baseUrl?: string;
72
+ /** Local development only; production relays hold the key. */
73
+ apiKey?: string;
74
+ model?: string;
75
+ timeoutMs?: number;
76
+ fetch?: typeof fetch;
77
+ /** E2EE seam; see the module comment. */
78
+ encryption?: InferenceRequestEncryption;
79
+ /**
80
+ * Extra body fields sent with every request. Defaults to the Vana / Phala
81
+ * routing hint `{ provider: { aci_verified: true, zdr: true } }`.
82
+ */
83
+ requestFields?: Record<string, unknown>;
84
+ }
85
+ export declare const DEFAULT_INFERENCE_REQUEST_FIELDS: Record<string, unknown>;
86
+ /** Thrown for a non-2xx or malformed provider reply. Carries no prompt text. */
87
+ export declare class InferenceRequestError extends Error {
88
+ readonly status: number | null;
89
+ constructor(message: string, status: number | null);
90
+ }
91
+ export declare function createOpenAiCompatibleInferenceProvider(options?: OpenAiCompatibleInferenceOptions): InferenceProvider;
92
+ export interface FakeInferenceProviderOptions {
93
+ model?: string;
94
+ /** Answer per call; a function sees the input and may throw. */
95
+ respond?: (input: InferenceChatInput, callIndex: number) => InferenceChatResult | Promise<InferenceChatResult>;
96
+ }
97
+ export interface FakeInferenceProvider extends InferenceProvider {
98
+ readonly calls: InferenceChatInput[];
99
+ }
100
+ /** Test double: records calls, answers with a fixed JSON object by default. */
101
+ export declare function createFakeInferenceProvider(options?: FakeInferenceProviderOptions): FakeInferenceProvider;
102
+ //# sourceMappingURL=inference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../src/derivatives/inference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC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