@dereekb/openrouter 13.37.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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/firebase/index.cjs.default.js +1 -0
  4. package/firebase/index.cjs.js +666 -0
  5. package/firebase/index.cjs.mjs +2 -0
  6. package/firebase/index.d.ts +1 -0
  7. package/firebase/index.esm.js +626 -0
  8. package/firebase/package.json +25 -0
  9. package/firebase/src/index.d.ts +1 -0
  10. package/firebase/src/lib/index.d.ts +4 -0
  11. package/firebase/src/lib/openrouter.api.d.ts +226 -0
  12. package/firebase/src/lib/openrouter.id.d.ts +56 -0
  13. package/firebase/src/lib/openrouter.model.d.ts +609 -0
  14. package/firebase/src/lib/openrouter.query.d.ts +121 -0
  15. package/firebase-server/index.cjs.default.js +1 -0
  16. package/firebase-server/index.cjs.js +4520 -0
  17. package/firebase-server/index.cjs.mjs +2 -0
  18. package/firebase-server/index.d.ts +1 -0
  19. package/firebase-server/index.esm.js +4466 -0
  20. package/firebase-server/package.json +38 -0
  21. package/firebase-server/src/index.d.ts +1 -0
  22. package/firebase-server/src/lib/index.d.ts +10 -0
  23. package/firebase-server/src/lib/openrouter.action.server.d.ts +196 -0
  24. package/firebase-server/src/lib/openrouter.broadcast.d.ts +93 -0
  25. package/firebase-server/src/lib/openrouter.call.inline.d.ts +57 -0
  26. package/firebase-server/src/lib/openrouter.file.attachment.d.ts +97 -0
  27. package/firebase-server/src/lib/openrouter.module.d.ts +65 -0
  28. package/firebase-server/src/lib/openrouter.prompt.service.d.ts +109 -0
  29. package/firebase-server/src/lib/openrouter.runtask.handle.d.ts +56 -0
  30. package/firebase-server/src/lib/openrouter.runtask.service.d.ts +380 -0
  31. package/firebase-server/src/lib/openrouter.runtask.sweep.d.ts +170 -0
  32. package/firebase-server/src/lib/openrouter.state.accessor.d.ts +106 -0
  33. package/firebase-server/src/test/openrouter.fake.d.ts +134 -0
  34. package/index.cjs.default.js +1 -0
  35. package/index.cjs.js +1867 -0
  36. package/index.cjs.mjs +2 -0
  37. package/index.d.ts +1 -0
  38. package/index.esm.js +1771 -0
  39. package/package.json +32 -0
  40. package/src/index.d.ts +1 -0
  41. package/src/lib/index.d.ts +10 -0
  42. package/src/lib/openrouter.call.d.ts +268 -0
  43. package/src/lib/openrouter.config.d.ts +314 -0
  44. package/src/lib/openrouter.embedding.d.ts +87 -0
  45. package/src/lib/openrouter.generation.d.ts +46 -0
  46. package/src/lib/openrouter.input.d.ts +238 -0
  47. package/src/lib/openrouter.prompt.d.ts +79 -0
  48. package/src/lib/openrouter.request.d.ts +91 -0
  49. package/src/lib/openrouter.sdk.d.ts +37 -0
  50. package/src/lib/openrouter.tool.d.ts +99 -0
  51. package/src/lib/openrouter.type.d.ts +125 -0
@@ -0,0 +1,666 @@
1
+ 'use strict';
2
+
3
+ var util = require('@dereekb/util');
4
+ var firebase = require('@dereekb/firebase');
5
+ var arktype = require('arktype');
6
+ var model = require('@dereekb/model');
7
+
8
+ /**
9
+ * Number of digits an {@link OpenRouterPromptVersionId} is padded to.
10
+ *
11
+ * Padding is what makes `orderBy(documentId())` on the subcollection return v2 before v10. Six digits
12
+ * is far past any realistic version count while staying readable.
13
+ */ var OPENROUTER_PROMPT_VERSION_ID_DIGITS = 6;
14
+ /**
15
+ * Converts a version number to its zero-padded document id.
16
+ *
17
+ * @param version - The version number.
18
+ * @returns The document id.
19
+ *
20
+ * @__NO_SIDE_EFFECTS__
21
+ */ function openRouterPromptVersionId(version) {
22
+ return String(version).padStart(OPENROUTER_PROMPT_VERSION_ID_DIGITS, '0');
23
+ }
24
+ /**
25
+ * Reads the version number back out of a version document id.
26
+ *
27
+ * @param id - The document id.
28
+ * @returns The version number, or NaN when the id is not a number.
29
+ *
30
+ * @__NO_SIDE_EFFECTS__
31
+ */ function openRouterPromptVersionNumberFromId(id) {
32
+ return Number(id);
33
+ }
34
+
35
+ function _assert_this_initialized(self) {
36
+ if (self === void 0) {
37
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
38
+ }
39
+ return self;
40
+ }
41
+ function _call_super(_this, derived, args) {
42
+ derived = _get_prototype_of(derived);
43
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
44
+ }
45
+ function _class_call_check$1(instance, Constructor) {
46
+ if (!(instance instanceof Constructor)) {
47
+ throw new TypeError("Cannot call a class as a function");
48
+ }
49
+ }
50
+ function _defineProperties(target, props) {
51
+ for(var i = 0; i < props.length; i++){
52
+ var descriptor = props[i];
53
+ descriptor.enumerable = descriptor.enumerable || false;
54
+ descriptor.configurable = true;
55
+ if ("value" in descriptor) descriptor.writable = true;
56
+ Object.defineProperty(target, descriptor.key, descriptor);
57
+ }
58
+ }
59
+ function _create_class(Constructor, protoProps, staticProps) {
60
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
61
+ return Constructor;
62
+ }
63
+ function _get_prototype_of(o) {
64
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
65
+ return o.__proto__ || Object.getPrototypeOf(o);
66
+ };
67
+ return _get_prototype_of(o);
68
+ }
69
+ function _inherits(subClass, superClass) {
70
+ if (typeof superClass !== "function" && superClass !== null) {
71
+ throw new TypeError("Super expression must either be null or a function");
72
+ }
73
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
74
+ constructor: {
75
+ value: subClass,
76
+ writable: true,
77
+ configurable: true
78
+ }
79
+ });
80
+ if (superClass) _set_prototype_of(subClass, superClass);
81
+ }
82
+ function _possible_constructor_return(self, call) {
83
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
84
+ return call;
85
+ }
86
+ return _assert_this_initialized(self);
87
+ }
88
+ function _set_prototype_of(o, p) {
89
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
90
+ o.__proto__ = p;
91
+ return o;
92
+ };
93
+ return _set_prototype_of(o, p);
94
+ }
95
+ function _type_of(obj) {
96
+ "@swc/helpers - typeof";
97
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
98
+ }
99
+ function _is_native_reflect_construct() {
100
+ try {
101
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
102
+ } catch (_) {}
103
+ return (_is_native_reflect_construct = function() {
104
+ return !!result;
105
+ })();
106
+ }
107
+ /**
108
+ * Identity for {@link OpenRouterPrompt} documents. Model type: `openRouterPrompt`, collection: `orp`.
109
+ */ var openRouterPromptIdentity = firebase.firestoreModelIdentity('openRouterPrompt', 'orp');
110
+ /**
111
+ * Lifecycle state of an {@link OpenRouterPrompt}.
112
+ */ exports.OpenRouterPromptState = void 0;
113
+ (function(OpenRouterPromptState) {
114
+ /**
115
+ * Created but not yet servable. A caller resolving this prompt gets an error rather than a guess.
116
+ */ OpenRouterPromptState[OpenRouterPromptState["DRAFT"] = 0] = "DRAFT";
117
+ /**
118
+ * Servable.
119
+ */ OpenRouterPromptState[OpenRouterPromptState["ACTIVE"] = 1] = "ACTIVE";
120
+ /**
121
+ * Retired. Retained so historical runs stay explicable, but no longer servable.
122
+ */ OpenRouterPromptState[OpenRouterPromptState["ARCHIVED"] = 2] = "ARCHIVED";
123
+ })(exports.OpenRouterPromptState || (exports.OpenRouterPromptState = {}));
124
+ var OpenRouterPromptDocument = /*#__PURE__*/ function(AbstractFirestoreDocument) {
125
+ _inherits(OpenRouterPromptDocument, AbstractFirestoreDocument);
126
+ function OpenRouterPromptDocument() {
127
+ _class_call_check$1(this, OpenRouterPromptDocument);
128
+ return _call_super(this, OpenRouterPromptDocument, arguments);
129
+ }
130
+ _create_class(OpenRouterPromptDocument, [
131
+ {
132
+ key: "modelIdentity",
133
+ get: function get() {
134
+ return openRouterPromptIdentity;
135
+ }
136
+ }
137
+ ]);
138
+ return OpenRouterPromptDocument;
139
+ }(firebase.AbstractFirestoreDocument);
140
+ var openRouterPromptConverter = firebase.snapshotConverterFunctions({
141
+ fields: {
142
+ cat: firebase.firestoreDate({
143
+ saveDefaultAsNow: true
144
+ }),
145
+ uat: firebase.optionalFirestoreDate(),
146
+ n: firebase.firestoreString({
147
+ default: ''
148
+ }),
149
+ d: firebase.optionalFirestoreString(),
150
+ s: firebase.firestoreEnum({
151
+ default: exports.OpenRouterPromptState.DRAFT
152
+ }),
153
+ av: firebase.optionalFirestoreNumber(),
154
+ lv: firebase.firestoreNumber({
155
+ default: 0
156
+ }),
157
+ t: firebase.optionalFirestoreArray({
158
+ filterUnique: true,
159
+ dontStoreIfEmpty: true
160
+ })
161
+ }
162
+ });
163
+ /**
164
+ * Returns the root Firestore collection reference for {@link OpenRouterPrompt} documents.
165
+ *
166
+ * @param context - The FirestoreContext used to resolve the collection.
167
+ * @returns A typed CollectionReference for the openRouterPrompt collection.
168
+ */ function openRouterPromptCollectionReference(context) {
169
+ return context.collection(openRouterPromptIdentity.collectionName);
170
+ }
171
+ /**
172
+ * Creates the Firestore collection accessor for {@link OpenRouterPrompt} documents.
173
+ *
174
+ * @param firestoreContext - The FirestoreContext used to build the collection.
175
+ * @returns An OpenRouterPromptFirestoreCollection.
176
+ */ function openRouterPromptFirestoreCollection(firestoreContext) {
177
+ return firestoreContext.firestoreCollection({
178
+ modelIdentity: openRouterPromptIdentity,
179
+ converter: openRouterPromptConverter,
180
+ collection: openRouterPromptCollectionReference(firestoreContext),
181
+ makeDocument: function makeDocument(accessor, documentAccessor) {
182
+ return new OpenRouterPromptDocument(accessor, documentAccessor);
183
+ },
184
+ firestoreContext: firestoreContext
185
+ });
186
+ }
187
+ // MARK: OpenRouterPromptVersion
188
+ /**
189
+ * Identity for {@link OpenRouterPromptVersion} documents. Subcollection of {@link OpenRouterPrompt}.
190
+ * Model type: `openRouterPromptVersion`, collection: `orpv`.
191
+ */ var openRouterPromptVersionIdentity = firebase.firestoreModelIdentity(openRouterPromptIdentity, 'openRouterPromptVersion', 'orpv');
192
+ /**
193
+ * With a parent, unlike the other documents here: a version only ever exists in a subcollection under
194
+ * the prompt it belongs to, so a holder of one — a collection-group query result especially — needs a
195
+ * way back to that prompt without parsing the path.
196
+ */ var OpenRouterPromptVersionDocument = /*#__PURE__*/ function(AbstractFirestoreDocumentWithParent) {
197
+ _inherits(OpenRouterPromptVersionDocument, AbstractFirestoreDocumentWithParent);
198
+ function OpenRouterPromptVersionDocument() {
199
+ _class_call_check$1(this, OpenRouterPromptVersionDocument);
200
+ return _call_super(this, OpenRouterPromptVersionDocument, arguments);
201
+ }
202
+ _create_class(OpenRouterPromptVersionDocument, [
203
+ {
204
+ key: "modelIdentity",
205
+ get: function get() {
206
+ return openRouterPromptVersionIdentity;
207
+ }
208
+ }
209
+ ]);
210
+ return OpenRouterPromptVersionDocument;
211
+ }(firebase.AbstractFirestoreDocumentWithParent);
212
+ var openRouterPromptVersionConverter = firebase.snapshotConverterFunctions({
213
+ fields: {
214
+ cat: firebase.firestoreDate({
215
+ saveDefaultAsNow: true
216
+ }),
217
+ v: firebase.firestoreNumber({
218
+ default: 0
219
+ }),
220
+ i: firebase.optionalFirestoreString(),
221
+ m: firebase.optionalFirestoreArray({
222
+ dontStoreIfEmpty: true
223
+ }),
224
+ c: firebase.optionalFirestorePassthroughJsonField(),
225
+ nt: firebase.optionalFirestoreString(),
226
+ by: firebase.optionalFirestoreString(),
227
+ lk: firebase.optionalFirestoreBoolean()
228
+ }
229
+ });
230
+ /**
231
+ * Creates a factory that produces {@link OpenRouterPromptVersion} subcollection references for a given
232
+ * {@link OpenRouterPromptDocument} parent.
233
+ *
234
+ * @param context - Firestore context to create subcollection references from.
235
+ * @returns A factory function that creates collection references for a given prompt parent.
236
+ *
237
+ * @__NO_SIDE_EFFECTS__
238
+ */ function openRouterPromptVersionCollectionReferenceFactory(context) {
239
+ return function(prompt) {
240
+ return context.subcollection(prompt.documentRef, openRouterPromptVersionIdentity.collectionName);
241
+ };
242
+ }
243
+ /**
244
+ * Creates an {@link OpenRouterPromptVersionFirestoreCollectionFactory} bound to the given context.
245
+ *
246
+ * @param firestoreContext - Firestore context to bind the collection factory to.
247
+ * @returns A factory that creates typed subcollections for version documents.
248
+ *
249
+ * @__NO_SIDE_EFFECTS__
250
+ */ function openRouterPromptVersionFirestoreCollectionFactory(firestoreContext) {
251
+ var factory = openRouterPromptVersionCollectionReferenceFactory(firestoreContext);
252
+ return function(parent) {
253
+ return firestoreContext.firestoreCollectionWithParent({
254
+ modelIdentity: openRouterPromptVersionIdentity,
255
+ converter: openRouterPromptVersionConverter,
256
+ collection: factory(parent),
257
+ makeDocument: function makeDocument(accessor, documentAccessor) {
258
+ return new OpenRouterPromptVersionDocument(accessor, documentAccessor);
259
+ },
260
+ firestoreContext: firestoreContext,
261
+ parent: parent
262
+ });
263
+ };
264
+ }
265
+ /**
266
+ * Creates a collection group reference for querying every {@link OpenRouterPromptVersion} across all
267
+ * prompts.
268
+ *
269
+ * @param context - Firestore context to create the collection group reference from.
270
+ * @returns A typed collection group.
271
+ */ function openRouterPromptVersionCollectionReference(context) {
272
+ return context.collectionGroup(openRouterPromptVersionIdentity.collectionName);
273
+ }
274
+ /**
275
+ * Creates a typed {@link OpenRouterPromptVersionFirestoreCollectionGroup} bound to the given context.
276
+ *
277
+ * @param firestoreContext - Firestore context to bind the collection group to.
278
+ * @returns A typed Firestore collection group.
279
+ */ function openRouterPromptVersionFirestoreCollectionGroup(firestoreContext) {
280
+ return firestoreContext.firestoreCollectionGroup({
281
+ modelIdentity: openRouterPromptVersionIdentity,
282
+ converter: openRouterPromptVersionConverter,
283
+ queryLike: openRouterPromptVersionCollectionReference(firestoreContext),
284
+ makeDocument: function makeDocument(accessor, documentAccessor) {
285
+ return new OpenRouterPromptVersionDocument(accessor, documentAccessor);
286
+ },
287
+ firestoreContext: firestoreContext
288
+ });
289
+ }
290
+ // MARK: OpenRouterRunTask
291
+ /**
292
+ * How long an OpenRouterRunTask lives before it is deleted, measured from `qat`.
293
+ *
294
+ * A design requirement rather than a tuning knob. NotificationTask already owns retrying, durable
295
+ * persistence, and delayed execution, so a run task is a short-lived execution record — letting one
296
+ * outlive a week would make it a second system of record with a second retention policy to reason about,
297
+ * for no gain.
298
+ *
299
+ * Measured from `qat` rather than a per-task expiration field because there is nothing to configure:
300
+ * a queued task runs essentially immediately, so its queue time IS its age. No field to forget to
301
+ * write, no document excluded from the retention query for lacking one.
302
+ */ var OPENROUTER_RUN_TASK_MAX_AGE = util.MS_IN_DAY * 7;
303
+ /**
304
+ * Identity for {@link OpenRouterRunTask} documents. Model type: `openRouterRunTask`, collection: `orrt`.
305
+ */ var openRouterRunTaskIdentity = firebase.firestoreModelIdentity('openRouterRunTask', 'orrt');
306
+ /**
307
+ * State of an {@link OpenRouterRunTask}.
308
+ */ exports.OpenRouterRunTaskState = void 0;
309
+ (function(OpenRouterRunTaskState) {
310
+ /**
311
+ * Enqueued and waiting for a sweep to claim it.
312
+ */ OpenRouterRunTaskState[OpenRouterRunTaskState["QUEUED"] = 0] = "QUEUED";
313
+ /**
314
+ * Claimed by a sweep and executing.
315
+ *
316
+ * A `RUNNING` document whose lease has gone stale is reclaimable — that is what makes a crashed
317
+ * sweep recoverable instead of permanently stuck.
318
+ */ OpenRouterRunTaskState[OpenRouterRunTaskState["RUNNING"] = 1] = "RUNNING";
319
+ /**
320
+ * Finished successfully. `o` / `j` hold the result.
321
+ */ OpenRouterRunTaskState[OpenRouterRunTaskState["COMPLETE"] = 2] = "COMPLETE";
322
+ /**
323
+ * Finished unsuccessfully, with the retry budget spent. `e` holds why.
324
+ */ OpenRouterRunTaskState[OpenRouterRunTaskState["FAILED"] = 3] = "FAILED";
325
+ /**
326
+ * Paused mid-run waiting on a deferred tool result from another process.
327
+ *
328
+ * Resumable: the next sweep picks it up once `utr` carries the resolutions.
329
+ */ OpenRouterRunTaskState[OpenRouterRunTaskState["AWAITING_ASYNC_TOOLS"] = 4] = "AWAITING_ASYNC_TOOLS";
330
+ })(exports.OpenRouterRunTaskState || (exports.OpenRouterRunTaskState = {}));
331
+ /**
332
+ * States a sweep considers claimable.
333
+ *
334
+ * `AWAITING_ASYNC_TOOLS` is in here alongside `QUEUED` because a task parked on a deferred tool whose
335
+ * results have since arrived is runnable again; `isOpenRouterRunTaskClaimable` is what decides whether
336
+ * the results actually did arrive.
337
+ */ var OPENROUTER_RUN_TASK_CLAIMABLE_STATES = [
338
+ exports.OpenRouterRunTaskState.QUEUED,
339
+ exports.OpenRouterRunTaskState.AWAITING_ASYNC_TOOLS
340
+ ];
341
+ /**
342
+ * States a run task will never leave.
343
+ */ var OPENROUTER_RUN_TASK_TERMINAL_STATES = [
344
+ exports.OpenRouterRunTaskState.COMPLETE,
345
+ exports.OpenRouterRunTaskState.FAILED
346
+ ];
347
+ /**
348
+ * Whether a state is terminal.
349
+ *
350
+ * @param state - The state to check.
351
+ * @returns True when the run will not change state again.
352
+ *
353
+ * @__NO_SIDE_EFFECTS__
354
+ */ function isOpenRouterRunTaskStateTerminal(state) {
355
+ return OPENROUTER_RUN_TASK_TERMINAL_STATES.includes(state);
356
+ }
357
+ var OpenRouterRunTaskDocument = /*#__PURE__*/ function(AbstractFirestoreDocument) {
358
+ _inherits(OpenRouterRunTaskDocument, AbstractFirestoreDocument);
359
+ function OpenRouterRunTaskDocument() {
360
+ _class_call_check$1(this, OpenRouterRunTaskDocument);
361
+ return _call_super(this, OpenRouterRunTaskDocument, arguments);
362
+ }
363
+ _create_class(OpenRouterRunTaskDocument, [
364
+ {
365
+ key: "modelIdentity",
366
+ get: function get() {
367
+ return openRouterRunTaskIdentity;
368
+ }
369
+ }
370
+ ]);
371
+ return OpenRouterRunTaskDocument;
372
+ }(firebase.AbstractFirestoreDocument);
373
+ var openRouterRunTaskConverter = firebase.snapshotConverterFunctions({
374
+ fields: {
375
+ s: firebase.firestoreEnum({
376
+ default: exports.OpenRouterRunTaskState.QUEUED
377
+ }),
378
+ qat: firebase.firestoreDate({
379
+ saveDefaultAsNow: true
380
+ }),
381
+ sat: firebase.optionalFirestoreDate(),
382
+ fat: firebase.optionalFirestoreDate(),
383
+ lat: firebase.optionalFirestoreDate(),
384
+ lo: firebase.optionalFirestoreString(),
385
+ at: firebase.firestoreNumber({
386
+ default: 0
387
+ }),
388
+ pk: firebase.firestoreString({
389
+ default: ''
390
+ }),
391
+ pv: firebase.firestoreNumber({
392
+ default: 0
393
+ }),
394
+ in: firebase.firestoreArray({}),
395
+ fp: firebase.optionalFirestoreArray({
396
+ dontStoreIfEmpty: true
397
+ }),
398
+ fa: firebase.optionalFirestoreArray({
399
+ dontStoreIfEmpty: true
400
+ }),
401
+ co: firebase.optionalFirestorePassthroughJsonField(),
402
+ o: firebase.optionalFirestoreString(),
403
+ j: firebase.optionalFirestorePassthroughJsonField(),
404
+ gi: firebase.optionalFirestoreArray({
405
+ filterUnique: true,
406
+ dontStoreIfEmpty: true
407
+ }),
408
+ u: firebase.optionalFirestorePassthroughJsonField(),
409
+ e: firebase.optionalFirestorePassthroughJsonField(),
410
+ msg: firebase.optionalFirestoreArray({
411
+ dontStoreIfEmpty: true
412
+ }),
413
+ ptc: firebase.optionalFirestoreArray({
414
+ dontStoreIfEmpty: true
415
+ }),
416
+ utr: firebase.optionalFirestoreArray({
417
+ dontStoreIfEmpty: true
418
+ })
419
+ }
420
+ });
421
+ /**
422
+ * Returns the root Firestore collection reference for {@link OpenRouterRunTask} documents.
423
+ *
424
+ * @param context - The FirestoreContext used to resolve the collection.
425
+ * @returns A typed CollectionReference for the openRouterRunTask collection.
426
+ */ function openRouterRunTaskCollectionReference(context) {
427
+ return context.collection(openRouterRunTaskIdentity.collectionName);
428
+ }
429
+ /**
430
+ * Creates the Firestore collection accessor for {@link OpenRouterRunTask} documents.
431
+ *
432
+ * @param firestoreContext - The FirestoreContext used to build the collection.
433
+ * @returns An OpenRouterRunTaskFirestoreCollection.
434
+ */ function openRouterRunTaskFirestoreCollection(firestoreContext) {
435
+ return firestoreContext.firestoreCollection({
436
+ modelIdentity: openRouterRunTaskIdentity,
437
+ converter: openRouterRunTaskConverter,
438
+ collection: openRouterRunTaskCollectionReference(firestoreContext),
439
+ makeDocument: function makeDocument(accessor, documentAccessor) {
440
+ return new OpenRouterRunTaskDocument(accessor, documentAccessor);
441
+ },
442
+ firestoreContext: firestoreContext
443
+ });
444
+ }
445
+ // MARK: Utility
446
+ /**
447
+ * Converts a stored version document into the resolved prompt the request builder consumes.
448
+ *
449
+ * @param promptKey - The prompt key the version belongs to.
450
+ * @param version - The stored version.
451
+ * @returns The resolved prompt.
452
+ *
453
+ * @__NO_SIDE_EFFECTS__
454
+ */ function openRouterResolvedPromptForVersion(promptKey, version) {
455
+ var _version_c;
456
+ var _version_m;
457
+ return {
458
+ promptKey: promptKey,
459
+ version: version.v,
460
+ instructions: version.i,
461
+ messages: (_version_m = version.m) === null || _version_m === void 0 ? void 0 : _version_m.map(function(param) {
462
+ var r = param.r, c = param.c;
463
+ return {
464
+ role: r,
465
+ content: c
466
+ };
467
+ }),
468
+ config: (_version_c = version.c) !== null && _version_c !== void 0 ? _version_c : {}
469
+ };
470
+ }
471
+ /**
472
+ * The document id of a version, from its number.
473
+ *
474
+ * Re-exported here so a caller reading a version does not need to reach for the id module separately.
475
+ */ var openRouterPromptVersionDocumentId = openRouterPromptVersionId;
476
+
477
+ function _class_call_check(instance, Constructor) {
478
+ if (!(instance instanceof Constructor)) {
479
+ throw new TypeError("Cannot call a class as a function");
480
+ }
481
+ }
482
+ var updateOpenRouterPromptParamsType = /* @__PURE__ */ firebase.inferredTargetModelParamsType.merge(arktype.type({
483
+ 'name?': model.clearable('string'),
484
+ 'description?': model.clearable('string'),
485
+ 'tags?': model.clearable('string[]'),
486
+ 'state?': model.clearable('number'),
487
+ 'activeVersion?': model.clearable('number')
488
+ }));
489
+ var openRouterPromptVersionMessageParamsType = /* @__PURE__ */ arktype.type({
490
+ role: "'user' | 'system' | 'assistant' | 'developer'",
491
+ content: 'string'
492
+ });
493
+ var createOpenRouterPromptVersionParamsType = /* @__PURE__ */ arktype.type({
494
+ prompt: 'string >= 1',
495
+ 'instructions?': model.clearable('string'),
496
+ 'messages?': model.clearable(openRouterPromptVersionMessageParamsType.array()),
497
+ 'config?': model.clearable('object'),
498
+ 'notes?': model.clearable('string'),
499
+ 'activate?': model.clearable('boolean')
500
+ });
501
+ var updateOpenRouterPromptVersionParamsType = /* @__PURE__ */ firebase.inferredTargetModelParamsType.merge(arktype.type({
502
+ 'instructions?': model.clearable('string'),
503
+ 'messages?': model.clearable(openRouterPromptVersionMessageParamsType.array()),
504
+ 'config?': model.clearable('object'),
505
+ 'notes?': model.clearable('string')
506
+ }));
507
+ var readOpenRouterRunTaskParamsType = /* @__PURE__ */ arktype.type({
508
+ key: 'string >= 1'
509
+ });
510
+ var OPENROUTER_PROMPT_FUNCTION_TYPE_CONFIG_MAP = {};
511
+ var OPENROUTER_PROMPT_MODEL_CRUD_FUNCTIONS_CONFIG = {
512
+ openRouterPrompt: [
513
+ 'update',
514
+ 'query'
515
+ ],
516
+ openRouterPromptVersion: [
517
+ 'create',
518
+ 'update'
519
+ ]
520
+ };
521
+ /**
522
+ * Abstract class defining the callable OpenRouter prompt functions.
523
+ */ var OpenRouterPromptModelFunctions = function OpenRouterPromptModelFunctions() {
524
+ _class_call_check(this, OpenRouterPromptModelFunctions);
525
+ };
526
+ /**
527
+ * Client-side callable function map factory for OpenRouter prompt CRUD.
528
+ */ var openRouterPromptModelFunctionMap = firebase.callModelFirebaseFunctionMapFactory(OPENROUTER_PROMPT_FUNCTION_TYPE_CONFIG_MAP, OPENROUTER_PROMPT_MODEL_CRUD_FUNCTIONS_CONFIG);
529
+
530
+ /**
531
+ * Query for the prompts in one lifecycle state.
532
+ *
533
+ * Needs no composite index, and is deliberately kept that way. Unordered, so pagination falls through to
534
+ * Firestore's implicit `__name__` order — which for this model is the prompt's own readable key, already
535
+ * the order a listing wants — and state is the only filter axis: pairing it with an `array-contains` on
536
+ * `t` would buy a composite index for a collection measured in dozens of documents.
537
+ *
538
+ * @param params - The state to match.
539
+ * @returns Firestore query constraints for the prompts in that state.
540
+ *
541
+ * @dbxModelFirebaseIndex
542
+ * @dbxModelFirebaseIndexModel OpenRouterPrompt
543
+ * @dbxModelFirebaseIndexScope COLLECTION
544
+ * @dbxModelFirebaseIndexCategory admin
545
+ */ function openRouterPromptsWithStateQuery(params) {
546
+ return [
547
+ firebase.where('s', '==', params.state)
548
+ ];
549
+ }
550
+ /**
551
+ * Query for the run tasks a sweep may execute, oldest-queued first.
552
+ *
553
+ * Queue order is the ONLY order, and deliberately so. A priority column costs a second composite index
554
+ * and buys a second failure mode: Firestore sorts `null` before every number, so one task written without
555
+ * a priority jumps the entire queue. Delaying a run is `NotificationTask`'s job — it owns the delayed
556
+ * firing — which leaves nothing for a priority here to express.
557
+ *
558
+ * @param params - The page limit.
559
+ * @returns Firestore query constraints for the runnable page.
560
+ *
561
+ * @dbxModelFirebaseIndex
562
+ * @dbxModelFirebaseIndexModel OpenRouterRunTask
563
+ * @dbxModelFirebaseIndexScope COLLECTION
564
+ * @dbxModelFirebaseIndexCategory sweep
565
+ */ function openRouterRunTasksRunnableQuery(params) {
566
+ var pageLimit = params.limit;
567
+ return [
568
+ firebase.where('s', 'in', OPENROUTER_RUN_TASK_CLAIMABLE_STATES),
569
+ firebase.orderBy('qat', 'asc'),
570
+ firebase.limit(pageLimit)
571
+ ];
572
+ }
573
+ /**
574
+ * Query for RUNNING run tasks whose lease has gone stale — crash recovery.
575
+ *
576
+ * Separate from {@link openRouterRunTasksRunnableQuery} because it needs a range filter on `lat`, and
577
+ * Firestore allows the range filter on only one field, which the ordering must then lead with.
578
+ *
579
+ * The cutoff goes through `whereDateIsOnOrBefore` rather than a bare `where('lat', '<=', date)`:
580
+ * `firestoreDate` persists an ISO8601 STRING, so comparing the field against a `Date` compares a string
581
+ * to a timestamp and matches nothing — silently, with no error and an empty page, which reads exactly
582
+ * like "no crashed sweeps to recover".
583
+ *
584
+ * @param params - The page limit and lease cutoff.
585
+ * @returns Firestore query constraints for the reclaimable page.
586
+ *
587
+ * @dbxModelFirebaseIndex
588
+ * @dbxModelFirebaseIndexModel OpenRouterRunTask
589
+ * @dbxModelFirebaseIndexScope COLLECTION
590
+ * @dbxModelFirebaseIndexCategory sweep
591
+ */ function openRouterRunTasksReclaimableQuery(params) {
592
+ var pageLimit = params.limit, leaseCutoff = params.leaseCutoff;
593
+ return [
594
+ firebase.where('s', '==', exports.OpenRouterRunTaskState.RUNNING),
595
+ firebase.whereDateIsOnOrBefore('lat', leaseCutoff),
596
+ firebase.orderBy('lat', 'asc'),
597
+ firebase.limit(pageLimit)
598
+ ];
599
+ }
600
+ /**
601
+ * Query for run tasks past their retention age, for deletion. Matches EVERY state, `RUNNING` included —
602
+ * see {@link OPENROUTER_RUN_TASK_MAX_AGE} for why the ceiling is the whole requirement.
603
+ *
604
+ * Ordered by `qat` with no state filter, so it needs no composite index at all: a single-field range with
605
+ * a matching order is served by Firestore's automatic single-field index.
606
+ *
607
+ * Firestore's NATIVE TTL policy cannot do this job, for the same reason the cutoff goes through
608
+ * `whereDateIsOnOrBefore` rather than a bare `where('qat', '<=', date)`: `firestoreDate` persists an
609
+ * ISO8601 STRING, and a TTL policy only deletes on a `Timestamp` field. Pointed at `qat` it would
610
+ * silently never fire. The app-level sweep is the mechanism here, not a stopgap for one.
611
+ *
612
+ * @param params - The retention cutoff and page limit.
613
+ * @returns Firestore query constraints for the expired page.
614
+ *
615
+ * @dbxModelFirebaseIndex
616
+ * @dbxModelFirebaseIndexModel OpenRouterRunTask
617
+ * @dbxModelFirebaseIndexScope COLLECTION
618
+ * @dbxModelFirebaseIndexCategory cleanup
619
+ */ function openRouterRunTasksExpiredQuery(params) {
620
+ var before = params.before, pageLimit = params.limit;
621
+ return [
622
+ firebase.whereDateIsOnOrBefore('qat', before),
623
+ firebase.orderBy('qat', 'asc'),
624
+ firebase.limit(pageLimit)
625
+ ];
626
+ }
627
+
628
+ exports.OPENROUTER_PROMPT_FUNCTION_TYPE_CONFIG_MAP = OPENROUTER_PROMPT_FUNCTION_TYPE_CONFIG_MAP;
629
+ exports.OPENROUTER_PROMPT_MODEL_CRUD_FUNCTIONS_CONFIG = OPENROUTER_PROMPT_MODEL_CRUD_FUNCTIONS_CONFIG;
630
+ exports.OPENROUTER_PROMPT_VERSION_ID_DIGITS = OPENROUTER_PROMPT_VERSION_ID_DIGITS;
631
+ exports.OPENROUTER_RUN_TASK_CLAIMABLE_STATES = OPENROUTER_RUN_TASK_CLAIMABLE_STATES;
632
+ exports.OPENROUTER_RUN_TASK_MAX_AGE = OPENROUTER_RUN_TASK_MAX_AGE;
633
+ exports.OPENROUTER_RUN_TASK_TERMINAL_STATES = OPENROUTER_RUN_TASK_TERMINAL_STATES;
634
+ exports.OpenRouterPromptDocument = OpenRouterPromptDocument;
635
+ exports.OpenRouterPromptModelFunctions = OpenRouterPromptModelFunctions;
636
+ exports.OpenRouterPromptVersionDocument = OpenRouterPromptVersionDocument;
637
+ exports.OpenRouterRunTaskDocument = OpenRouterRunTaskDocument;
638
+ exports.createOpenRouterPromptVersionParamsType = createOpenRouterPromptVersionParamsType;
639
+ exports.isOpenRouterRunTaskStateTerminal = isOpenRouterRunTaskStateTerminal;
640
+ exports.openRouterPromptCollectionReference = openRouterPromptCollectionReference;
641
+ exports.openRouterPromptConverter = openRouterPromptConverter;
642
+ exports.openRouterPromptFirestoreCollection = openRouterPromptFirestoreCollection;
643
+ exports.openRouterPromptIdentity = openRouterPromptIdentity;
644
+ exports.openRouterPromptModelFunctionMap = openRouterPromptModelFunctionMap;
645
+ exports.openRouterPromptVersionCollectionReference = openRouterPromptVersionCollectionReference;
646
+ exports.openRouterPromptVersionCollectionReferenceFactory = openRouterPromptVersionCollectionReferenceFactory;
647
+ exports.openRouterPromptVersionConverter = openRouterPromptVersionConverter;
648
+ exports.openRouterPromptVersionDocumentId = openRouterPromptVersionDocumentId;
649
+ exports.openRouterPromptVersionFirestoreCollectionFactory = openRouterPromptVersionFirestoreCollectionFactory;
650
+ exports.openRouterPromptVersionFirestoreCollectionGroup = openRouterPromptVersionFirestoreCollectionGroup;
651
+ exports.openRouterPromptVersionId = openRouterPromptVersionId;
652
+ exports.openRouterPromptVersionIdentity = openRouterPromptVersionIdentity;
653
+ exports.openRouterPromptVersionMessageParamsType = openRouterPromptVersionMessageParamsType;
654
+ exports.openRouterPromptVersionNumberFromId = openRouterPromptVersionNumberFromId;
655
+ exports.openRouterPromptsWithStateQuery = openRouterPromptsWithStateQuery;
656
+ exports.openRouterResolvedPromptForVersion = openRouterResolvedPromptForVersion;
657
+ exports.openRouterRunTaskCollectionReference = openRouterRunTaskCollectionReference;
658
+ exports.openRouterRunTaskConverter = openRouterRunTaskConverter;
659
+ exports.openRouterRunTaskFirestoreCollection = openRouterRunTaskFirestoreCollection;
660
+ exports.openRouterRunTaskIdentity = openRouterRunTaskIdentity;
661
+ exports.openRouterRunTasksExpiredQuery = openRouterRunTasksExpiredQuery;
662
+ exports.openRouterRunTasksReclaimableQuery = openRouterRunTasksReclaimableQuery;
663
+ exports.openRouterRunTasksRunnableQuery = openRouterRunTasksRunnableQuery;
664
+ exports.readOpenRouterRunTaskParamsType = readOpenRouterRunTaskParamsType;
665
+ exports.updateOpenRouterPromptParamsType = updateOpenRouterPromptParamsType;
666
+ exports.updateOpenRouterPromptVersionParamsType = updateOpenRouterPromptVersionParamsType;
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
@@ -0,0 +1 @@
1
+ export * from "./src/index";