@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,226 @@
|
|
|
1
|
+
import { type Type } from 'arktype';
|
|
2
|
+
import { type FirebaseFunctionTypeConfigMap, type FirestoreModelKey, type InferredTargetModelParams, type ModelFirebaseCreateFunction, type ModelFirebaseCrudFunction, type ModelFirebaseCrudFunctionConfigMap, type ModelFirebaseFunctionMap, type ModelFirebaseQueryFunction, type OnCallCreateModelResult, type OnCallQueryModelRequestParams, type OnCallQueryModelResult } from '@dereekb/firebase';
|
|
3
|
+
import { type Maybe } from '@dereekb/util';
|
|
4
|
+
import { type OpenRouterPromptVersionNumber } from '@dereekb/openrouter';
|
|
5
|
+
import { type OpenRouterPrompt, type OpenRouterPromptState, type OpenRouterPromptTypes } from './openrouter.model';
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for updating an {@link OpenRouterPrompt}'s metadata and lifecycle state.
|
|
8
|
+
*
|
|
9
|
+
* Notably absent: anything that would change what a version SAYS. That is the version model's own
|
|
10
|
+
* update, so the only writes here are to the prompt's metadata and to which version is active.
|
|
11
|
+
*
|
|
12
|
+
* @dbxModelApiParams
|
|
13
|
+
*/
|
|
14
|
+
export interface UpdateOpenRouterPromptParams extends InferredTargetModelParams {
|
|
15
|
+
readonly name?: Maybe<string>;
|
|
16
|
+
readonly description?: Maybe<string>;
|
|
17
|
+
readonly tags?: Maybe<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* New lifecycle state.
|
|
20
|
+
*/
|
|
21
|
+
readonly state?: Maybe<OpenRouterPromptState>;
|
|
22
|
+
/**
|
|
23
|
+
* Version to serve to unpinned callers.
|
|
24
|
+
*
|
|
25
|
+
* Must already exist — promoting a version that was never published would leave every unpinned caller
|
|
26
|
+
* failing to resolve.
|
|
27
|
+
*/
|
|
28
|
+
readonly activeVersion?: Maybe<OpenRouterPromptVersionNumber>;
|
|
29
|
+
}
|
|
30
|
+
export declare const updateOpenRouterPromptParamsType: Type<UpdateOpenRouterPromptParams>;
|
|
31
|
+
/**
|
|
32
|
+
* A seed message supplied when creating a version.
|
|
33
|
+
*/
|
|
34
|
+
export interface OpenRouterPromptVersionMessageParams {
|
|
35
|
+
readonly role: 'user' | 'system' | 'assistant' | 'developer';
|
|
36
|
+
readonly content: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const openRouterPromptVersionMessageParamsType: Type<OpenRouterPromptVersionMessageParams>;
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for creating a new {@link OpenRouterPromptVersion}.
|
|
41
|
+
*
|
|
42
|
+
* A create on the version model rather than an update on its parent: publishing writes a new document,
|
|
43
|
+
* which is what a create is, and it puts the operation on the model whose document appears. It also locks
|
|
44
|
+
* the version it succeeds — see {@link OpenRouterPromptVersion}.
|
|
45
|
+
*
|
|
46
|
+
* The version number is ALLOCATED by the server from the prompt's `lv`, not supplied — two concurrent
|
|
47
|
+
* creates picking the same number would silently overwrite one another. That is also why the parent is
|
|
48
|
+
* named here rather than inferred: the target of the call is a document that does not exist yet.
|
|
49
|
+
*
|
|
50
|
+
* @dbxModelApiParams
|
|
51
|
+
*/
|
|
52
|
+
export interface CreateOpenRouterPromptVersionParams {
|
|
53
|
+
/**
|
|
54
|
+
* Key of the {@link OpenRouterPrompt} the version belongs to.
|
|
55
|
+
*/
|
|
56
|
+
readonly prompt: FirestoreModelKey;
|
|
57
|
+
/**
|
|
58
|
+
* System prompt.
|
|
59
|
+
*/
|
|
60
|
+
readonly instructions?: Maybe<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Static seed messages.
|
|
63
|
+
*/
|
|
64
|
+
readonly messages?: Maybe<OpenRouterPromptVersionMessageParams[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Model configuration. Passthrough JSON — validated against `OpenRouterModelConfig` but stored as-is.
|
|
67
|
+
*/
|
|
68
|
+
readonly config?: Maybe<Record<string, unknown>>;
|
|
69
|
+
/**
|
|
70
|
+
* Why this version was created.
|
|
71
|
+
*/
|
|
72
|
+
readonly notes?: Maybe<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Whether to promote this version to `activeVersion` on creation.
|
|
75
|
+
*
|
|
76
|
+
* Defaults to false: publishing and promoting are separate acts, so a version can be tested by a
|
|
77
|
+
* pinned caller before it becomes what everyone gets.
|
|
78
|
+
*/
|
|
79
|
+
readonly activate?: Maybe<boolean>;
|
|
80
|
+
}
|
|
81
|
+
export declare const createOpenRouterPromptVersionParamsType: Type<CreateOpenRouterPromptVersionParams>;
|
|
82
|
+
/**
|
|
83
|
+
* Parameters for updating the latest {@link OpenRouterPromptVersion} of a prompt.
|
|
84
|
+
*
|
|
85
|
+
* Only what a version SAYS is editable, and only while the version is the latest one. Creating the
|
|
86
|
+
* next version locks this one, and a locked version is refused — see {@link OpenRouterPromptVersion}
|
|
87
|
+
* for why. The version number, its creation date and its lock are not caller-writable.
|
|
88
|
+
*
|
|
89
|
+
* @dbxModelApiParams
|
|
90
|
+
*/
|
|
91
|
+
export interface UpdateOpenRouterPromptVersionParams extends InferredTargetModelParams {
|
|
92
|
+
/**
|
|
93
|
+
* System prompt.
|
|
94
|
+
*/
|
|
95
|
+
readonly instructions?: Maybe<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Static seed messages.
|
|
98
|
+
*/
|
|
99
|
+
readonly messages?: Maybe<OpenRouterPromptVersionMessageParams[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Model configuration. Passthrough JSON — validated against `OpenRouterModelConfig` but stored as-is.
|
|
102
|
+
*/
|
|
103
|
+
readonly config?: Maybe<Record<string, unknown>>;
|
|
104
|
+
/**
|
|
105
|
+
* Why the version says what it says.
|
|
106
|
+
*/
|
|
107
|
+
readonly notes?: Maybe<string>;
|
|
108
|
+
}
|
|
109
|
+
export declare const updateOpenRouterPromptVersionParamsType: Type<UpdateOpenRouterPromptVersionParams>;
|
|
110
|
+
/**
|
|
111
|
+
* Result of updating a version.
|
|
112
|
+
*/
|
|
113
|
+
export interface UpdateOpenRouterPromptVersionResult {
|
|
114
|
+
/**
|
|
115
|
+
* Config problems that did not prevent the edit from being written.
|
|
116
|
+
*
|
|
117
|
+
* Returned for the same reason the create returns them: an unpinned PDF engine or an unpinned
|
|
118
|
+
* provider produces a wrong answer rather than an error, so an edit that introduces one has to say so.
|
|
119
|
+
*/
|
|
120
|
+
readonly warnings: string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Result of creating a version.
|
|
124
|
+
*/
|
|
125
|
+
export interface CreateOpenRouterPromptVersionResult extends OnCallCreateModelResult {
|
|
126
|
+
/**
|
|
127
|
+
* Key of the created version document.
|
|
128
|
+
*/
|
|
129
|
+
readonly modelKeys: [FirestoreModelKey];
|
|
130
|
+
/**
|
|
131
|
+
* The allocated version number.
|
|
132
|
+
*/
|
|
133
|
+
readonly version: OpenRouterPromptVersionNumber;
|
|
134
|
+
/**
|
|
135
|
+
* Whether the version was promoted to active.
|
|
136
|
+
*/
|
|
137
|
+
readonly activated: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Config problems that did not prevent the version from being written.
|
|
140
|
+
*
|
|
141
|
+
* Surfaced rather than swallowed: an unpinned PDF engine or an unpinned provider produces a wrong
|
|
142
|
+
* answer rather than an error, so the warning is the only chance to notice.
|
|
143
|
+
*/
|
|
144
|
+
readonly warnings: string[];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Parameters for querying {@link OpenRouterPrompt}s.
|
|
148
|
+
*
|
|
149
|
+
* The standard query operation rather than a bespoke list endpoint: it inherits `limit` and
|
|
150
|
+
* `cursorDocumentKey` pagination that every client and the callModel MCP already know how to drive,
|
|
151
|
+
* and returns the stored documents rather than a hand-maintained projection of them.
|
|
152
|
+
*
|
|
153
|
+
* @dbxModelApiParams
|
|
154
|
+
*/
|
|
155
|
+
export interface QueryOpenRouterPromptsParams extends OnCallQueryModelRequestParams {
|
|
156
|
+
/**
|
|
157
|
+
* Restrict to one lifecycle state. Omit to page through every prompt.
|
|
158
|
+
*
|
|
159
|
+
* The only filter axis, deliberately — see {@link openRouterPromptsWithStateQuery}.
|
|
160
|
+
*/
|
|
161
|
+
readonly state?: Maybe<OpenRouterPromptState>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Parameters for reading an {@link OpenRouterRunTask}.
|
|
165
|
+
*
|
|
166
|
+
* @dbxModelApiParams
|
|
167
|
+
*/
|
|
168
|
+
export interface ReadOpenRouterRunTaskParams {
|
|
169
|
+
/**
|
|
170
|
+
* The run key.
|
|
171
|
+
*/
|
|
172
|
+
readonly key: string;
|
|
173
|
+
}
|
|
174
|
+
export declare const readOpenRouterRunTaskParamsType: Type<ReadOpenRouterRunTaskParams>;
|
|
175
|
+
/**
|
|
176
|
+
* Custom (non-CRUD) function type map for OpenRouter prompts.
|
|
177
|
+
*/
|
|
178
|
+
export type OpenRouterPromptFunctionTypeMap = {};
|
|
179
|
+
export declare const OPENROUTER_PROMPT_FUNCTION_TYPE_CONFIG_MAP: FirebaseFunctionTypeConfigMap<OpenRouterPromptFunctionTypeMap>;
|
|
180
|
+
/**
|
|
181
|
+
* CRUD function configuration map for {@link OpenRouterPrompt}.
|
|
182
|
+
*
|
|
183
|
+
* There is deliberately no Angular UI for prompt authoring: declaring the CRUD here is what makes every
|
|
184
|
+
* prompt operation reachable over an app's existing callModel surface — including from the callModel
|
|
185
|
+
* MCP — instead of requiring a screen to be built for it.
|
|
186
|
+
*
|
|
187
|
+
* A prompt has no `create` of its own: it is created server-side, from a seed against an
|
|
188
|
+
* {@link OpenRouterPromptDefinition} the code already carries. A VERSION does, because publishing one
|
|
189
|
+
* writes a new document, and the create sits on `openRouterPromptVersion` — the model whose document
|
|
190
|
+
* appears — rather than as a specifier on the parent's update. Its `update` edits the latest version
|
|
191
|
+
* in place and refuses a locked one, so iterating on a prompt does not mint a version per keystroke.
|
|
192
|
+
*
|
|
193
|
+
* Neither model declares a `read`: both are registered model services, so a stored prompt or one of its
|
|
194
|
+
* versions is already fetchable by key through model-get.
|
|
195
|
+
*
|
|
196
|
+
* `OpenRouterRunTask` is absent on purpose. A run task is written and drained entirely server-side, and
|
|
197
|
+
* its `msg` field carries raw model input and output.
|
|
198
|
+
*/
|
|
199
|
+
export type OpenRouterPromptModelCrudFunctionsConfig = {
|
|
200
|
+
readonly openRouterPrompt: {
|
|
201
|
+
update: UpdateOpenRouterPromptParams;
|
|
202
|
+
query: [QueryOpenRouterPromptsParams, OnCallQueryModelResult<OpenRouterPrompt>];
|
|
203
|
+
};
|
|
204
|
+
readonly openRouterPromptVersion: {
|
|
205
|
+
create: [CreateOpenRouterPromptVersionParams, CreateOpenRouterPromptVersionResult];
|
|
206
|
+
update: [UpdateOpenRouterPromptVersionParams, UpdateOpenRouterPromptVersionResult];
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
export declare const OPENROUTER_PROMPT_MODEL_CRUD_FUNCTIONS_CONFIG: ModelFirebaseCrudFunctionConfigMap<OpenRouterPromptModelCrudFunctionsConfig, OpenRouterPromptTypes>;
|
|
210
|
+
/**
|
|
211
|
+
* Abstract class defining the callable OpenRouter prompt functions.
|
|
212
|
+
*/
|
|
213
|
+
export declare abstract class OpenRouterPromptModelFunctions implements ModelFirebaseFunctionMap<OpenRouterPromptFunctionTypeMap, OpenRouterPromptModelCrudFunctionsConfig> {
|
|
214
|
+
abstract openRouterPrompt: {
|
|
215
|
+
updateOpenRouterPrompt: ModelFirebaseCrudFunction<UpdateOpenRouterPromptParams>;
|
|
216
|
+
queryOpenRouterPrompt: ModelFirebaseQueryFunction<QueryOpenRouterPromptsParams, OnCallQueryModelResult<OpenRouterPrompt>>;
|
|
217
|
+
};
|
|
218
|
+
abstract openRouterPromptVersion: {
|
|
219
|
+
createOpenRouterPromptVersion: ModelFirebaseCreateFunction<CreateOpenRouterPromptVersionParams, CreateOpenRouterPromptVersionResult>;
|
|
220
|
+
updateOpenRouterPromptVersion: ModelFirebaseCrudFunction<UpdateOpenRouterPromptVersionParams, UpdateOpenRouterPromptVersionResult>;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Client-side callable function map factory for OpenRouter prompt CRUD.
|
|
225
|
+
*/
|
|
226
|
+
export declare const openRouterPromptModelFunctionMap: import("@dereekb/firebase").ModelFirebaseFunctionMapFactory<OpenRouterPromptFunctionTypeMap, OpenRouterPromptModelCrudFunctionsConfig>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type FirestoreModelId, type FirestoreModelKey } from '@dereekb/firebase';
|
|
2
|
+
import { type OpenRouterPromptVersionNumber } from '@dereekb/openrouter';
|
|
3
|
+
/**
|
|
4
|
+
* An {@link OpenRouterPrompt} id.
|
|
5
|
+
*
|
|
6
|
+
* This is the prompt's stable human-readable key (`kaia-resume-parser`) rather than a generated id —
|
|
7
|
+
* the whole point of the model is that a call site names the prompt it wants in readable text instead
|
|
8
|
+
* of quoting an opaque `pmpt_…`.
|
|
9
|
+
*/
|
|
10
|
+
export type OpenRouterPromptId = FirestoreModelId;
|
|
11
|
+
/**
|
|
12
|
+
* An {@link OpenRouterPrompt} key.
|
|
13
|
+
*/
|
|
14
|
+
export type OpenRouterPromptModelKey = FirestoreModelKey;
|
|
15
|
+
/**
|
|
16
|
+
* An {@link OpenRouterPromptVersion} id: the version number, zero-padded so lexical document
|
|
17
|
+
* ordering matches numeric ordering.
|
|
18
|
+
*/
|
|
19
|
+
export type OpenRouterPromptVersionId = FirestoreModelId;
|
|
20
|
+
/**
|
|
21
|
+
* An {@link OpenRouterPromptVersion} key.
|
|
22
|
+
*/
|
|
23
|
+
export type OpenRouterPromptVersionModelKey = FirestoreModelKey;
|
|
24
|
+
/**
|
|
25
|
+
* Number of digits an {@link OpenRouterPromptVersionId} is padded to.
|
|
26
|
+
*
|
|
27
|
+
* Padding is what makes `orderBy(documentId())` on the subcollection return v2 before v10. Six digits
|
|
28
|
+
* is far past any realistic version count while staying readable.
|
|
29
|
+
*/
|
|
30
|
+
export declare const OPENROUTER_PROMPT_VERSION_ID_DIGITS = 6;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a version number to its zero-padded document id.
|
|
33
|
+
*
|
|
34
|
+
* @param version - The version number.
|
|
35
|
+
* @returns The document id.
|
|
36
|
+
*
|
|
37
|
+
* @__NO_SIDE_EFFECTS__
|
|
38
|
+
*/
|
|
39
|
+
export declare function openRouterPromptVersionId(version: OpenRouterPromptVersionNumber): OpenRouterPromptVersionId;
|
|
40
|
+
/**
|
|
41
|
+
* Reads the version number back out of a version document id.
|
|
42
|
+
*
|
|
43
|
+
* @param id - The document id.
|
|
44
|
+
* @returns The version number, or NaN when the id is not a number.
|
|
45
|
+
*
|
|
46
|
+
* @__NO_SIDE_EFFECTS__
|
|
47
|
+
*/
|
|
48
|
+
export declare function openRouterPromptVersionNumberFromId(id: OpenRouterPromptVersionId): OpenRouterPromptVersionNumber;
|
|
49
|
+
/**
|
|
50
|
+
* An {@link OpenRouterRunTask} id — the caller-supplied run key.
|
|
51
|
+
*/
|
|
52
|
+
export type OpenRouterRunTaskId = FirestoreModelId;
|
|
53
|
+
/**
|
|
54
|
+
* An {@link OpenRouterRunTask} key.
|
|
55
|
+
*/
|
|
56
|
+
export type OpenRouterRunTaskModelKey = FirestoreModelKey;
|