@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.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/firebase/index.cjs.default.js +1 -0
- package/firebase/index.cjs.js +666 -0
- package/firebase/index.cjs.mjs +2 -0
- package/firebase/index.d.ts +1 -0
- package/firebase/index.esm.js +626 -0
- package/firebase/package.json +25 -0
- package/firebase/src/index.d.ts +1 -0
- package/firebase/src/lib/index.d.ts +4 -0
- package/firebase/src/lib/openrouter.api.d.ts +226 -0
- package/firebase/src/lib/openrouter.id.d.ts +56 -0
- package/firebase/src/lib/openrouter.model.d.ts +609 -0
- package/firebase/src/lib/openrouter.query.d.ts +121 -0
- package/firebase-server/index.cjs.default.js +1 -0
- package/firebase-server/index.cjs.js +4520 -0
- package/firebase-server/index.cjs.mjs +2 -0
- package/firebase-server/index.d.ts +1 -0
- package/firebase-server/index.esm.js +4466 -0
- package/firebase-server/package.json +38 -0
- package/firebase-server/src/index.d.ts +1 -0
- package/firebase-server/src/lib/index.d.ts +10 -0
- package/firebase-server/src/lib/openrouter.action.server.d.ts +196 -0
- package/firebase-server/src/lib/openrouter.broadcast.d.ts +93 -0
- package/firebase-server/src/lib/openrouter.call.inline.d.ts +57 -0
- package/firebase-server/src/lib/openrouter.file.attachment.d.ts +97 -0
- package/firebase-server/src/lib/openrouter.module.d.ts +65 -0
- package/firebase-server/src/lib/openrouter.prompt.service.d.ts +109 -0
- package/firebase-server/src/lib/openrouter.runtask.handle.d.ts +56 -0
- package/firebase-server/src/lib/openrouter.runtask.service.d.ts +380 -0
- package/firebase-server/src/lib/openrouter.runtask.sweep.d.ts +170 -0
- package/firebase-server/src/lib/openrouter.state.accessor.d.ts +106 -0
- package/firebase-server/src/test/openrouter.fake.d.ts +134 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +1867 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +1771 -0
- package/package.json +32 -0
- package/src/index.d.ts +1 -0
- package/src/lib/index.d.ts +10 -0
- package/src/lib/openrouter.call.d.ts +268 -0
- package/src/lib/openrouter.config.d.ts +314 -0
- package/src/lib/openrouter.embedding.d.ts +87 -0
- package/src/lib/openrouter.generation.d.ts +46 -0
- package/src/lib/openrouter.input.d.ts +238 -0
- package/src/lib/openrouter.prompt.d.ts +79 -0
- package/src/lib/openrouter.request.d.ts +91 -0
- package/src/lib/openrouter.sdk.d.ts +37 -0
- package/src/lib/openrouter.tool.d.ts +99 -0
- package/src/lib/openrouter.type.d.ts +125 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
|
|
2
|
+
import { type Maybe, type Milliseconds } from '@dereekb/util';
|
|
3
|
+
import { type OpenRouterFileAnnotation, type OpenRouterFileReference, type OpenRouterGenerationId, type OpenRouterInputMessage, type OpenRouterInputRole, type OpenRouterModelConfig, type OpenRouterPromptKey, type OpenRouterPromptVersionNumber, type OpenRouterResolvedPrompt, type OpenRouterRunError, type OpenRouterRunUsage } from '@dereekb/openrouter';
|
|
4
|
+
import { AbstractFirestoreDocument, AbstractFirestoreDocumentWithParent, type CollectionGroup, type CollectionReference, type FirestoreCollection, type FirestoreCollectionGroup, type FirestoreCollectionWithParent, type FirestoreContext, type FirestoreModelKey } from '@dereekb/firebase';
|
|
5
|
+
import { openRouterPromptVersionId } from './openrouter.id';
|
|
6
|
+
/**
|
|
7
|
+
* Provides access to the {@link OpenRouterPrompt} collection and its version subcollection.
|
|
8
|
+
*
|
|
9
|
+
* @dbxModelGroup OpenRouterPrompt
|
|
10
|
+
*/
|
|
11
|
+
export interface OpenRouterPromptFirestoreCollections {
|
|
12
|
+
readonly openRouterPromptCollection: OpenRouterPromptFirestoreCollection;
|
|
13
|
+
readonly openRouterPromptVersionCollectionFactory: OpenRouterPromptVersionFirestoreCollectionFactory;
|
|
14
|
+
readonly openRouterPromptVersionCollectionGroup: OpenRouterPromptVersionFirestoreCollectionGroup;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Union of all OpenRouterPrompt model identity types.
|
|
18
|
+
*/
|
|
19
|
+
export type OpenRouterPromptTypes = typeof openRouterPromptIdentity | typeof openRouterPromptVersionIdentity;
|
|
20
|
+
/**
|
|
21
|
+
* Identity for {@link OpenRouterPrompt} documents. Model type: `openRouterPrompt`, collection: `orp`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const openRouterPromptIdentity: import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterPrompt", "orp">;
|
|
24
|
+
/**
|
|
25
|
+
* Lifecycle state of an {@link OpenRouterPrompt}.
|
|
26
|
+
*/
|
|
27
|
+
export declare enum OpenRouterPromptState {
|
|
28
|
+
/**
|
|
29
|
+
* Created but not yet servable. A caller resolving this prompt gets an error rather than a guess.
|
|
30
|
+
*/
|
|
31
|
+
DRAFT = 0,
|
|
32
|
+
/**
|
|
33
|
+
* Servable.
|
|
34
|
+
*/
|
|
35
|
+
ACTIVE = 1,
|
|
36
|
+
/**
|
|
37
|
+
* Retired. Retained so historical runs stay explicable, but no longer servable.
|
|
38
|
+
*/
|
|
39
|
+
ARCHIVED = 2
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A reusable prompt.
|
|
43
|
+
*
|
|
44
|
+
* This is the replacement for an OpenAI Prompt Object. The document id IS the prompt's key
|
|
45
|
+
* (`kaia-resume-parser`), so a call site names the prompt in readable text instead of quoting an
|
|
46
|
+
* opaque `pmpt_…`, and the content, model, reasoning effort, and output format live here rather than
|
|
47
|
+
* in a vendor dashboard.
|
|
48
|
+
*
|
|
49
|
+
* The prompt document holds only identity and version pointers; everything servable lives on an
|
|
50
|
+
* {@link OpenRouterPromptVersion}.
|
|
51
|
+
*
|
|
52
|
+
* @dbxModel
|
|
53
|
+
* @dbxModelRead admin
|
|
54
|
+
* @dbxModelUpdate admin
|
|
55
|
+
*/
|
|
56
|
+
export interface OpenRouterPrompt {
|
|
57
|
+
/**
|
|
58
|
+
* Date this prompt was created at.
|
|
59
|
+
*
|
|
60
|
+
* @dbxModelVariable createdAt
|
|
61
|
+
*/
|
|
62
|
+
cat: Date;
|
|
63
|
+
/**
|
|
64
|
+
* Date this prompt was last updated at.
|
|
65
|
+
*
|
|
66
|
+
* @dbxModelVariable updatedAt
|
|
67
|
+
*/
|
|
68
|
+
uat?: Maybe<Date>;
|
|
69
|
+
/**
|
|
70
|
+
* Human-readable name.
|
|
71
|
+
*
|
|
72
|
+
* @dbxModelVariable name
|
|
73
|
+
*/
|
|
74
|
+
n: string;
|
|
75
|
+
/**
|
|
76
|
+
* What this prompt is for.
|
|
77
|
+
*
|
|
78
|
+
* @dbxModelVariable description
|
|
79
|
+
*/
|
|
80
|
+
d?: Maybe<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Lifecycle state.
|
|
83
|
+
*
|
|
84
|
+
* @dbxModelVariable state
|
|
85
|
+
*/
|
|
86
|
+
s: OpenRouterPromptState;
|
|
87
|
+
/**
|
|
88
|
+
* Version served when a caller does not pin one.
|
|
89
|
+
*
|
|
90
|
+
* Absent until a version is published and promoted, which is what keeps an unfinished prompt from
|
|
91
|
+
* being served by accident.
|
|
92
|
+
*
|
|
93
|
+
* @dbxModelVariable activeVersion
|
|
94
|
+
*/
|
|
95
|
+
av?: Maybe<OpenRouterPromptVersionNumber>;
|
|
96
|
+
/**
|
|
97
|
+
* Highest version number allocated so far — the allocator for the next one.
|
|
98
|
+
*
|
|
99
|
+
* @dbxModelVariable latestVersion
|
|
100
|
+
*/
|
|
101
|
+
lv: OpenRouterPromptVersionNumber;
|
|
102
|
+
/**
|
|
103
|
+
* Free-form tags for grouping.
|
|
104
|
+
*
|
|
105
|
+
* @dbxModelVariable tags
|
|
106
|
+
*/
|
|
107
|
+
t?: Maybe<string[]>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Roles for an {@link OpenRouterPrompt}. Prompts are operational configuration, so reads and writes
|
|
111
|
+
* are administrative.
|
|
112
|
+
*/
|
|
113
|
+
export type OpenRouterPromptRoles = GrantedReadRole | GrantedUpdateRole | 'publish';
|
|
114
|
+
export declare class OpenRouterPromptDocument extends AbstractFirestoreDocument<OpenRouterPrompt, OpenRouterPromptDocument, typeof openRouterPromptIdentity> {
|
|
115
|
+
get modelIdentity(): import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterPrompt", "orp">;
|
|
116
|
+
}
|
|
117
|
+
export declare const openRouterPromptConverter: import("@dereekb/firebase").SnapshotConverterFunctions<OpenRouterPrompt, Partial<import("@dereekb/util").ReplaceType<OpenRouterPrompt, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the root Firestore collection reference for {@link OpenRouterPrompt} documents.
|
|
120
|
+
*
|
|
121
|
+
* @param context - The FirestoreContext used to resolve the collection.
|
|
122
|
+
* @returns A typed CollectionReference for the openRouterPrompt collection.
|
|
123
|
+
*/
|
|
124
|
+
export declare function openRouterPromptCollectionReference(context: FirestoreContext): CollectionReference<OpenRouterPrompt>;
|
|
125
|
+
export type OpenRouterPromptFirestoreCollection = FirestoreCollection<OpenRouterPrompt, OpenRouterPromptDocument>;
|
|
126
|
+
/**
|
|
127
|
+
* Creates the Firestore collection accessor for {@link OpenRouterPrompt} documents.
|
|
128
|
+
*
|
|
129
|
+
* @param firestoreContext - The FirestoreContext used to build the collection.
|
|
130
|
+
* @returns An OpenRouterPromptFirestoreCollection.
|
|
131
|
+
*/
|
|
132
|
+
export declare function openRouterPromptFirestoreCollection(firestoreContext: FirestoreContext): OpenRouterPromptFirestoreCollection;
|
|
133
|
+
/**
|
|
134
|
+
* Identity for {@link OpenRouterPromptVersion} documents. Subcollection of {@link OpenRouterPrompt}.
|
|
135
|
+
* Model type: `openRouterPromptVersion`, collection: `orpv`.
|
|
136
|
+
*/
|
|
137
|
+
export declare const openRouterPromptVersionIdentity: import("@dereekb/firebase").FirestoreModelIdentityWithParent<import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterPrompt", "orp">, "openRouterPromptVersion", "orpv">;
|
|
138
|
+
/**
|
|
139
|
+
* A seed message stored on a version, in short-key persisted form.
|
|
140
|
+
*
|
|
141
|
+
* @dbxModelSubObject
|
|
142
|
+
*/
|
|
143
|
+
export interface OpenRouterPromptVersionMessage {
|
|
144
|
+
/**
|
|
145
|
+
* Message role.
|
|
146
|
+
*
|
|
147
|
+
* @dbxModelVariable role
|
|
148
|
+
*/
|
|
149
|
+
r: OpenRouterInputRole;
|
|
150
|
+
/**
|
|
151
|
+
* Message content.
|
|
152
|
+
*
|
|
153
|
+
* @dbxModelVariable content
|
|
154
|
+
*/
|
|
155
|
+
c: string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* One version of a prompt.
|
|
159
|
+
*
|
|
160
|
+
* Version pinning is the one thing OpenRouter Presets structurally cannot do — a preset always
|
|
161
|
+
* resolves to latest — so it is the reason this model exists rather than deferring to a preset. A run
|
|
162
|
+
* records the version it used, so a result is always traceable to the exact prompt text that produced
|
|
163
|
+
* it, and a historical run can be replayed against that same text.
|
|
164
|
+
*
|
|
165
|
+
* Only the latest version is editable. Creating the next version {@link OpenRouterPromptVersion.lk
|
|
166
|
+
* locks} the one before it, permanently, because editing a version a past run cites would silently
|
|
167
|
+
* change the meaning of that run's result. The head version stays open so that a prompt can be
|
|
168
|
+
* iterated on without minting a version per keystroke — which does mean a run against the head can be
|
|
169
|
+
* replayed against text that has since moved. Lock it by creating the next version.
|
|
170
|
+
*
|
|
171
|
+
* @dbxModel
|
|
172
|
+
* @dbxModelRead admin
|
|
173
|
+
*/
|
|
174
|
+
export interface OpenRouterPromptVersion {
|
|
175
|
+
/**
|
|
176
|
+
* Date this version was published at.
|
|
177
|
+
*
|
|
178
|
+
* @dbxModelVariable createdAt
|
|
179
|
+
*/
|
|
180
|
+
cat: Date;
|
|
181
|
+
/**
|
|
182
|
+
* The version number. Matches the (unpadded) document id.
|
|
183
|
+
*
|
|
184
|
+
* @dbxModelVariable version
|
|
185
|
+
*/
|
|
186
|
+
v: OpenRouterPromptVersionNumber;
|
|
187
|
+
/**
|
|
188
|
+
* System prompt.
|
|
189
|
+
*
|
|
190
|
+
* @dbxModelVariable instructions
|
|
191
|
+
*/
|
|
192
|
+
i?: Maybe<string>;
|
|
193
|
+
/**
|
|
194
|
+
* Static seed messages, emitted before the caller's dynamic input.
|
|
195
|
+
*
|
|
196
|
+
* @dbxModelVariable messages
|
|
197
|
+
*/
|
|
198
|
+
m?: Maybe<OpenRouterPromptVersionMessage[]>;
|
|
199
|
+
/**
|
|
200
|
+
* Model configuration.
|
|
201
|
+
*
|
|
202
|
+
* Stored as PASSTHROUGH JSON, deliberately not a strict converter. OpenRouter's parameter surface
|
|
203
|
+
* moves fast, and a strict converter would silently drop any field it did not know about — turning
|
|
204
|
+
* every OpenRouter release into a config-corrupting event. `OpenRouterModelConfig` types it in
|
|
205
|
+
* TypeScript for autocomplete and call-time validation instead: strict types in code, loose storage.
|
|
206
|
+
*
|
|
207
|
+
* @dbxModelVariable config
|
|
208
|
+
*/
|
|
209
|
+
c?: Maybe<OpenRouterModelConfig>;
|
|
210
|
+
/**
|
|
211
|
+
* Why this version was published.
|
|
212
|
+
*
|
|
213
|
+
* @dbxModelVariable notes
|
|
214
|
+
*/
|
|
215
|
+
nt?: Maybe<string>;
|
|
216
|
+
/**
|
|
217
|
+
* Model key of whoever published it.
|
|
218
|
+
*
|
|
219
|
+
* @dbxModelVariable createdBy
|
|
220
|
+
*/
|
|
221
|
+
by?: Maybe<FirestoreModelKey>;
|
|
222
|
+
/**
|
|
223
|
+
* Whether the version is locked against further edits.
|
|
224
|
+
*
|
|
225
|
+
* Set on the outgoing version when the next one is created, and never unset — a version a past run
|
|
226
|
+
* cites has to keep saying what it said when the run cited it.
|
|
227
|
+
*
|
|
228
|
+
* Stored rather than derived from the prompt's `lv`, so a reader holding only the version document
|
|
229
|
+
* can tell whether it is editable, and so the update path needs no second read to find out.
|
|
230
|
+
*
|
|
231
|
+
* @dbxModelVariable locked
|
|
232
|
+
*/
|
|
233
|
+
lk?: Maybe<boolean>;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Roles for an {@link OpenRouterPromptVersion}.
|
|
237
|
+
*
|
|
238
|
+
* `update` is granted by the role map, but the action refuses a locked version regardless: the lock is
|
|
239
|
+
* a property of the document, not of who is asking.
|
|
240
|
+
*/
|
|
241
|
+
export type OpenRouterPromptVersionRoles = GrantedReadRole | GrantedUpdateRole;
|
|
242
|
+
/**
|
|
243
|
+
* With a parent, unlike the other documents here: a version only ever exists in a subcollection under
|
|
244
|
+
* the prompt it belongs to, so a holder of one — a collection-group query result especially — needs a
|
|
245
|
+
* way back to that prompt without parsing the path.
|
|
246
|
+
*/
|
|
247
|
+
export declare class OpenRouterPromptVersionDocument extends AbstractFirestoreDocumentWithParent<OpenRouterPrompt, OpenRouterPromptVersion, OpenRouterPromptVersionDocument, typeof openRouterPromptVersionIdentity> {
|
|
248
|
+
get modelIdentity(): import("@dereekb/firebase").FirestoreModelIdentityWithParent<import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterPrompt", "orp">, "openRouterPromptVersion", "orpv">;
|
|
249
|
+
}
|
|
250
|
+
export declare const openRouterPromptVersionConverter: import("@dereekb/firebase").SnapshotConverterFunctions<OpenRouterPromptVersion, Partial<import("@dereekb/util").ReplaceType<OpenRouterPromptVersion, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
251
|
+
/**
|
|
252
|
+
* Creates a factory that produces {@link OpenRouterPromptVersion} subcollection references for a given
|
|
253
|
+
* {@link OpenRouterPromptDocument} parent.
|
|
254
|
+
*
|
|
255
|
+
* @param context - Firestore context to create subcollection references from.
|
|
256
|
+
* @returns A factory function that creates collection references for a given prompt parent.
|
|
257
|
+
*
|
|
258
|
+
* @__NO_SIDE_EFFECTS__
|
|
259
|
+
*/
|
|
260
|
+
export declare function openRouterPromptVersionCollectionReferenceFactory(context: FirestoreContext): (prompt: OpenRouterPromptDocument) => CollectionReference<OpenRouterPromptVersion>;
|
|
261
|
+
export type OpenRouterPromptVersionFirestoreCollection = FirestoreCollectionWithParent<OpenRouterPromptVersion, OpenRouterPrompt, OpenRouterPromptVersionDocument, OpenRouterPromptDocument>;
|
|
262
|
+
export type OpenRouterPromptVersionFirestoreCollectionFactory = (parent: OpenRouterPromptDocument) => OpenRouterPromptVersionFirestoreCollection;
|
|
263
|
+
/**
|
|
264
|
+
* Creates an {@link OpenRouterPromptVersionFirestoreCollectionFactory} bound to the given context.
|
|
265
|
+
*
|
|
266
|
+
* @param firestoreContext - Firestore context to bind the collection factory to.
|
|
267
|
+
* @returns A factory that creates typed subcollections for version documents.
|
|
268
|
+
*
|
|
269
|
+
* @__NO_SIDE_EFFECTS__
|
|
270
|
+
*/
|
|
271
|
+
export declare function openRouterPromptVersionFirestoreCollectionFactory(firestoreContext: FirestoreContext): OpenRouterPromptVersionFirestoreCollectionFactory;
|
|
272
|
+
/**
|
|
273
|
+
* Creates a collection group reference for querying every {@link OpenRouterPromptVersion} across all
|
|
274
|
+
* prompts.
|
|
275
|
+
*
|
|
276
|
+
* @param context - Firestore context to create the collection group reference from.
|
|
277
|
+
* @returns A typed collection group.
|
|
278
|
+
*/
|
|
279
|
+
export declare function openRouterPromptVersionCollectionReference(context: FirestoreContext): CollectionGroup<OpenRouterPromptVersion>;
|
|
280
|
+
export type OpenRouterPromptVersionFirestoreCollectionGroup = FirestoreCollectionGroup<OpenRouterPromptVersion, OpenRouterPromptVersionDocument>;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a typed {@link OpenRouterPromptVersionFirestoreCollectionGroup} bound to the given context.
|
|
283
|
+
*
|
|
284
|
+
* @param firestoreContext - Firestore context to bind the collection group to.
|
|
285
|
+
* @returns A typed Firestore collection group.
|
|
286
|
+
*/
|
|
287
|
+
export declare function openRouterPromptVersionFirestoreCollectionGroup(firestoreContext: FirestoreContext): OpenRouterPromptVersionFirestoreCollectionGroup;
|
|
288
|
+
/**
|
|
289
|
+
* How long an OpenRouterRunTask lives before it is deleted, measured from `qat`.
|
|
290
|
+
*
|
|
291
|
+
* A design requirement rather than a tuning knob. NotificationTask already owns retrying, durable
|
|
292
|
+
* persistence, and delayed execution, so a run task is a short-lived execution record — letting one
|
|
293
|
+
* outlive a week would make it a second system of record with a second retention policy to reason about,
|
|
294
|
+
* for no gain.
|
|
295
|
+
*
|
|
296
|
+
* Measured from `qat` rather than a per-task expiration field because there is nothing to configure:
|
|
297
|
+
* a queued task runs essentially immediately, so its queue time IS its age. No field to forget to
|
|
298
|
+
* write, no document excluded from the retention query for lacking one.
|
|
299
|
+
*/
|
|
300
|
+
export declare const OPENROUTER_RUN_TASK_MAX_AGE: Milliseconds;
|
|
301
|
+
/**
|
|
302
|
+
* Provides access to the {@link OpenRouterRunTask} collection.
|
|
303
|
+
*
|
|
304
|
+
* @dbxModelGroup OpenRouterRunTask
|
|
305
|
+
*/
|
|
306
|
+
export interface OpenRouterRunTaskFirestoreCollections {
|
|
307
|
+
readonly openRouterRunTaskCollection: OpenRouterRunTaskFirestoreCollection;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Union of all OpenRouterRunTask model identity types.
|
|
311
|
+
*/
|
|
312
|
+
export type OpenRouterRunTaskTypes = typeof openRouterRunTaskIdentity;
|
|
313
|
+
/**
|
|
314
|
+
* Identity for {@link OpenRouterRunTask} documents. Model type: `openRouterRunTask`, collection: `orrt`.
|
|
315
|
+
*/
|
|
316
|
+
export declare const openRouterRunTaskIdentity: import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterRunTask", "orrt">;
|
|
317
|
+
/**
|
|
318
|
+
* State of an {@link OpenRouterRunTask}.
|
|
319
|
+
*/
|
|
320
|
+
export declare enum OpenRouterRunTaskState {
|
|
321
|
+
/**
|
|
322
|
+
* Enqueued and waiting for a sweep to claim it.
|
|
323
|
+
*/
|
|
324
|
+
QUEUED = 0,
|
|
325
|
+
/**
|
|
326
|
+
* Claimed by a sweep and executing.
|
|
327
|
+
*
|
|
328
|
+
* A `RUNNING` document whose lease has gone stale is reclaimable — that is what makes a crashed
|
|
329
|
+
* sweep recoverable instead of permanently stuck.
|
|
330
|
+
*/
|
|
331
|
+
RUNNING = 1,
|
|
332
|
+
/**
|
|
333
|
+
* Finished successfully. `o` / `j` hold the result.
|
|
334
|
+
*/
|
|
335
|
+
COMPLETE = 2,
|
|
336
|
+
/**
|
|
337
|
+
* Finished unsuccessfully, with the retry budget spent. `e` holds why.
|
|
338
|
+
*/
|
|
339
|
+
FAILED = 3,
|
|
340
|
+
/**
|
|
341
|
+
* Paused mid-run waiting on a deferred tool result from another process.
|
|
342
|
+
*
|
|
343
|
+
* Resumable: the next sweep picks it up once `utr` carries the resolutions.
|
|
344
|
+
*/
|
|
345
|
+
AWAITING_ASYNC_TOOLS = 4
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* States a sweep considers claimable.
|
|
349
|
+
*
|
|
350
|
+
* `AWAITING_ASYNC_TOOLS` is in here alongside `QUEUED` because a task parked on a deferred tool whose
|
|
351
|
+
* results have since arrived is runnable again; `isOpenRouterRunTaskClaimable` is what decides whether
|
|
352
|
+
* the results actually did arrive.
|
|
353
|
+
*/
|
|
354
|
+
export declare const OPENROUTER_RUN_TASK_CLAIMABLE_STATES: readonly OpenRouterRunTaskState[];
|
|
355
|
+
/**
|
|
356
|
+
* States a run task will never leave.
|
|
357
|
+
*/
|
|
358
|
+
export declare const OPENROUTER_RUN_TASK_TERMINAL_STATES: readonly OpenRouterRunTaskState[];
|
|
359
|
+
/**
|
|
360
|
+
* Whether a state is terminal.
|
|
361
|
+
*
|
|
362
|
+
* @param state - The state to check.
|
|
363
|
+
* @returns True when the run will not change state again.
|
|
364
|
+
*
|
|
365
|
+
* @__NO_SIDE_EFFECTS__
|
|
366
|
+
*/
|
|
367
|
+
export declare function isOpenRouterRunTaskStateTerminal(state: OpenRouterRunTaskState): boolean;
|
|
368
|
+
/**
|
|
369
|
+
* A pending deferred tool call, in persisted form.
|
|
370
|
+
*
|
|
371
|
+
* @dbxModelSubObject
|
|
372
|
+
*/
|
|
373
|
+
export interface OpenRouterRunTaskPendingToolCall {
|
|
374
|
+
/**
|
|
375
|
+
* The tool call id assigned by the SDK.
|
|
376
|
+
*/
|
|
377
|
+
readonly callId: string;
|
|
378
|
+
/**
|
|
379
|
+
* The tool name.
|
|
380
|
+
*/
|
|
381
|
+
readonly name: string;
|
|
382
|
+
/**
|
|
383
|
+
* The task id the resolving system quotes.
|
|
384
|
+
*/
|
|
385
|
+
readonly taskId: string;
|
|
386
|
+
/**
|
|
387
|
+
* The arguments the model called with.
|
|
388
|
+
*/
|
|
389
|
+
readonly arguments?: Maybe<Record<string, unknown>>;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A tool result recorded but not yet sent to the model.
|
|
393
|
+
*
|
|
394
|
+
* @dbxModelSubObject
|
|
395
|
+
*/
|
|
396
|
+
export interface OpenRouterRunTaskUnsentToolResult {
|
|
397
|
+
readonly callId: string;
|
|
398
|
+
readonly name: string;
|
|
399
|
+
readonly output?: unknown;
|
|
400
|
+
readonly error?: Maybe<string>;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* One asynchronous OpenRouter run: both the queue entry and the conversation-state backend.
|
|
404
|
+
*
|
|
405
|
+
* There is deliberately only ONE model here rather than a queue document plus a conversation
|
|
406
|
+
* document. OpenRouter is stateless — no `background: true`, no server-side job store, no
|
|
407
|
+
* `previous_response_id` — so everything OpenAI kept on their side has to live somewhere on ours, and
|
|
408
|
+
* splitting it across two documents would mean two writes to keep consistent on every state change
|
|
409
|
+
* for no gain.
|
|
410
|
+
*
|
|
411
|
+
* The document id is the caller-supplied run key: the value stored wherever an OpenAI `responseId` is
|
|
412
|
+
* stored today. Callers derive it deterministically so re-entering the checkpoint that enqueued the
|
|
413
|
+
* run reuses this document instead of queueing a duplicate.
|
|
414
|
+
*
|
|
415
|
+
* @dbxModel
|
|
416
|
+
* @dbxModelRead admin
|
|
417
|
+
* @dbxModelUpdate admin
|
|
418
|
+
*/
|
|
419
|
+
export interface OpenRouterRunTask {
|
|
420
|
+
/**
|
|
421
|
+
* Current state.
|
|
422
|
+
*
|
|
423
|
+
* @dbxModelVariable state
|
|
424
|
+
*/
|
|
425
|
+
s: OpenRouterRunTaskState;
|
|
426
|
+
/**
|
|
427
|
+
* Date this task was queued at. The sweep's ONLY sort key.
|
|
428
|
+
*
|
|
429
|
+
* WRITE-ONCE: set at enqueue and never moved, not even when a deferred-tool resume returns the task to
|
|
430
|
+
* `QUEUED`. Two things depend on that. It is what makes `qat` a valid retention age — a rolling value
|
|
431
|
+
* would let a task cycling through tool resolutions keep pushing its own age forward and never reach
|
|
432
|
+
* {@link OPENROUTER_RUN_TASK_MAX_AGE}. And it is the more correct ORDER: a task that has been waiting on
|
|
433
|
+
* a deferred tool since yesterday should be claimed before one queued a minute ago.
|
|
434
|
+
*
|
|
435
|
+
* @dbxModelVariable queuedAt
|
|
436
|
+
*/
|
|
437
|
+
qat: Date;
|
|
438
|
+
/**
|
|
439
|
+
* Date execution most recently started at.
|
|
440
|
+
*
|
|
441
|
+
* @dbxModelVariable startedAt
|
|
442
|
+
*/
|
|
443
|
+
sat?: Maybe<Date>;
|
|
444
|
+
/**
|
|
445
|
+
* Date this task reached a terminal state at.
|
|
446
|
+
*
|
|
447
|
+
* @dbxModelVariable finishedAt
|
|
448
|
+
*/
|
|
449
|
+
fat?: Maybe<Date>;
|
|
450
|
+
/**
|
|
451
|
+
* Date the current lease was taken at.
|
|
452
|
+
*
|
|
453
|
+
* A `RUNNING` task whose `lat` is older than the lease timeout is reclaimed by the next sweep. This
|
|
454
|
+
* is the generalised replacement for ad-hoc "unstick anything that has been processing for over an
|
|
455
|
+
* hour" logic.
|
|
456
|
+
*
|
|
457
|
+
* @dbxModelVariable leaseAt
|
|
458
|
+
*/
|
|
459
|
+
lat?: Maybe<Date>;
|
|
460
|
+
/**
|
|
461
|
+
* Identifier of the sweep that holds the lease. Claiming is transactional, so two overlapping
|
|
462
|
+
* sweeps can never both run one task.
|
|
463
|
+
*
|
|
464
|
+
* @dbxModelVariable leaseOwner
|
|
465
|
+
*/
|
|
466
|
+
lo?: Maybe<string>;
|
|
467
|
+
/**
|
|
468
|
+
* Number of attempts made.
|
|
469
|
+
*
|
|
470
|
+
* @dbxModelVariable attempts
|
|
471
|
+
*/
|
|
472
|
+
at: number;
|
|
473
|
+
/**
|
|
474
|
+
* Prompt this run uses.
|
|
475
|
+
*
|
|
476
|
+
* @dbxModelVariable promptKey
|
|
477
|
+
*/
|
|
478
|
+
pk: OpenRouterPromptKey;
|
|
479
|
+
/**
|
|
480
|
+
* The resolved prompt version. Recorded rather than re-resolved so a retry cannot silently switch
|
|
481
|
+
* prompt text mid-run.
|
|
482
|
+
*
|
|
483
|
+
* @dbxModelVariable promptVersion
|
|
484
|
+
*/
|
|
485
|
+
pv: OpenRouterPromptVersionNumber;
|
|
486
|
+
/**
|
|
487
|
+
* The call input.
|
|
488
|
+
*
|
|
489
|
+
* @dbxModelVariable input
|
|
490
|
+
*/
|
|
491
|
+
in: OpenRouterInputMessage[];
|
|
492
|
+
/**
|
|
493
|
+
* Files to attach, as GCS object paths — never signed URLs. See {@link OpenRouterFileReference} for why.
|
|
494
|
+
*
|
|
495
|
+
* @dbxModelVariable files
|
|
496
|
+
*/
|
|
497
|
+
fp?: Maybe<OpenRouterFileReference[]>;
|
|
498
|
+
/**
|
|
499
|
+
* Cached `file-parser` annotations, resubmitted on retries and chained calls so an already-parsed
|
|
500
|
+
* PDF is not parsed again. See {@link OpenRouterFileAnnotation} for what a re-parse costs.
|
|
501
|
+
*
|
|
502
|
+
* @dbxModelVariable fileAnnotations
|
|
503
|
+
*/
|
|
504
|
+
fa?: Maybe<OpenRouterFileAnnotation[]>;
|
|
505
|
+
/**
|
|
506
|
+
* Per-run overrides applied on top of the version's config. Passthrough JSON, for the reason
|
|
507
|
+
* {@link OpenRouterModelConfig} states.
|
|
508
|
+
*
|
|
509
|
+
* @dbxModelVariable configOverrides
|
|
510
|
+
*/
|
|
511
|
+
co?: Maybe<OpenRouterModelConfig>;
|
|
512
|
+
/**
|
|
513
|
+
* The output text.
|
|
514
|
+
*
|
|
515
|
+
* @dbxModelVariable outputText
|
|
516
|
+
*/
|
|
517
|
+
o?: Maybe<string>;
|
|
518
|
+
/**
|
|
519
|
+
* The output parsed as JSON, when it parsed as an object.
|
|
520
|
+
*
|
|
521
|
+
* @dbxModelVariable outputJson
|
|
522
|
+
*/
|
|
523
|
+
j?: Maybe<Record<string, unknown>>;
|
|
524
|
+
/**
|
|
525
|
+
* Generation ids produced, for auditing via `getGeneration` / `listGenerationContent`.
|
|
526
|
+
*
|
|
527
|
+
* Audit only. OpenRouter can reload a generation's content later, but that surface is tied to
|
|
528
|
+
* account logging settings (nothing is retained under ZDR / logging-disabled) and its retention is
|
|
529
|
+
* undocumented — so `o` / `j` here are the system of record, not those.
|
|
530
|
+
*
|
|
531
|
+
* @dbxModelVariable generationIds
|
|
532
|
+
*/
|
|
533
|
+
gi?: Maybe<OpenRouterGenerationId[]>;
|
|
534
|
+
/**
|
|
535
|
+
* Token and cost usage.
|
|
536
|
+
*
|
|
537
|
+
* Written by the runner from the response, and refined later by the broadcast webhook — cost is
|
|
538
|
+
* finalised server-side, so the runner's value can be provisional.
|
|
539
|
+
*
|
|
540
|
+
* @dbxModelVariable usage
|
|
541
|
+
*/
|
|
542
|
+
u?: Maybe<OpenRouterRunUsage>;
|
|
543
|
+
/**
|
|
544
|
+
* Why the run failed.
|
|
545
|
+
*
|
|
546
|
+
* @dbxModelVariable error
|
|
547
|
+
*/
|
|
548
|
+
e?: Maybe<OpenRouterRunError>;
|
|
549
|
+
/**
|
|
550
|
+
* Conversation history. This is what replaces `previous_response_id`, which OpenRouter rejects with
|
|
551
|
+
* a 400 — continuing a conversation means resending its history.
|
|
552
|
+
*
|
|
553
|
+
* Only populated for multi-step or chained runs; a single-shot run leaves it empty.
|
|
554
|
+
*
|
|
555
|
+
* @dbxModelVariable messages
|
|
556
|
+
*/
|
|
557
|
+
msg?: Maybe<OpenRouterInputMessage[]>;
|
|
558
|
+
/**
|
|
559
|
+
* Tool calls awaiting a result from another process. Only populated for deferred-tool runs.
|
|
560
|
+
*
|
|
561
|
+
* @dbxModelVariable pendingToolCalls
|
|
562
|
+
*/
|
|
563
|
+
ptc?: Maybe<OpenRouterRunTaskPendingToolCall[]>;
|
|
564
|
+
/**
|
|
565
|
+
* Tool results recorded but not yet delivered to the model. Only populated for deferred-tool runs.
|
|
566
|
+
*
|
|
567
|
+
* @dbxModelVariable unsentToolResults
|
|
568
|
+
*/
|
|
569
|
+
utr?: Maybe<OpenRouterRunTaskUnsentToolResult[]>;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Roles for an {@link OpenRouterRunTask}. Run tasks are server-owned infrastructure.
|
|
573
|
+
*/
|
|
574
|
+
export type OpenRouterRunTaskRoles = GrantedReadRole | GrantedUpdateRole;
|
|
575
|
+
export declare class OpenRouterRunTaskDocument extends AbstractFirestoreDocument<OpenRouterRunTask, OpenRouterRunTaskDocument, typeof openRouterRunTaskIdentity> {
|
|
576
|
+
get modelIdentity(): import("@dereekb/firebase").RootFirestoreModelIdentity<"openRouterRunTask", "orrt">;
|
|
577
|
+
}
|
|
578
|
+
export declare const openRouterRunTaskConverter: import("@dereekb/firebase").SnapshotConverterFunctions<OpenRouterRunTask, Partial<import("@dereekb/util").ReplaceType<OpenRouterRunTask, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
579
|
+
/**
|
|
580
|
+
* Returns the root Firestore collection reference for {@link OpenRouterRunTask} documents.
|
|
581
|
+
*
|
|
582
|
+
* @param context - The FirestoreContext used to resolve the collection.
|
|
583
|
+
* @returns A typed CollectionReference for the openRouterRunTask collection.
|
|
584
|
+
*/
|
|
585
|
+
export declare function openRouterRunTaskCollectionReference(context: FirestoreContext): CollectionReference<OpenRouterRunTask>;
|
|
586
|
+
export type OpenRouterRunTaskFirestoreCollection = FirestoreCollection<OpenRouterRunTask, OpenRouterRunTaskDocument>;
|
|
587
|
+
/**
|
|
588
|
+
* Creates the Firestore collection accessor for {@link OpenRouterRunTask} documents.
|
|
589
|
+
*
|
|
590
|
+
* @param firestoreContext - The FirestoreContext used to build the collection.
|
|
591
|
+
* @returns An OpenRouterRunTaskFirestoreCollection.
|
|
592
|
+
*/
|
|
593
|
+
export declare function openRouterRunTaskFirestoreCollection(firestoreContext: FirestoreContext): OpenRouterRunTaskFirestoreCollection;
|
|
594
|
+
/**
|
|
595
|
+
* Converts a stored version document into the resolved prompt the request builder consumes.
|
|
596
|
+
*
|
|
597
|
+
* @param promptKey - The prompt key the version belongs to.
|
|
598
|
+
* @param version - The stored version.
|
|
599
|
+
* @returns The resolved prompt.
|
|
600
|
+
*
|
|
601
|
+
* @__NO_SIDE_EFFECTS__
|
|
602
|
+
*/
|
|
603
|
+
export declare function openRouterResolvedPromptForVersion(promptKey: OpenRouterPromptKey, version: OpenRouterPromptVersion): OpenRouterResolvedPrompt;
|
|
604
|
+
/**
|
|
605
|
+
* The document id of a version, from its number.
|
|
606
|
+
*
|
|
607
|
+
* Re-exported here so a caller reading a version does not need to reach for the id module separately.
|
|
608
|
+
*/
|
|
609
|
+
export declare const openRouterPromptVersionDocumentId: typeof openRouterPromptVersionId;
|