@vertesia/common 0.42.2

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 (201) hide show
  1. package/LICENSE +13 -0
  2. package/lib/cjs/access-control.js +39 -0
  3. package/lib/cjs/access-control.js.map +1 -0
  4. package/lib/cjs/analytics.js +3 -0
  5. package/lib/cjs/analytics.js.map +1 -0
  6. package/lib/cjs/apikey.js +15 -0
  7. package/lib/cjs/apikey.js.map +1 -0
  8. package/lib/cjs/common.js +3 -0
  9. package/lib/cjs/common.js.map +1 -0
  10. package/lib/cjs/environment.js +116 -0
  11. package/lib/cjs/environment.js.map +1 -0
  12. package/lib/cjs/facets.js +3 -0
  13. package/lib/cjs/facets.js.map +1 -0
  14. package/lib/cjs/index.js +37 -0
  15. package/lib/cjs/index.js.map +1 -0
  16. package/lib/cjs/integrations.js +10 -0
  17. package/lib/cjs/integrations.js.map +1 -0
  18. package/lib/cjs/interaction.js +63 -0
  19. package/lib/cjs/interaction.js.map +1 -0
  20. package/lib/cjs/package.json +3 -0
  21. package/lib/cjs/payload.js +3 -0
  22. package/lib/cjs/payload.js.map +1 -0
  23. package/lib/cjs/project.js +50 -0
  24. package/lib/cjs/project.js.map +1 -0
  25. package/lib/cjs/prompt.js +21 -0
  26. package/lib/cjs/prompt.js.map +1 -0
  27. package/lib/cjs/query.js +3 -0
  28. package/lib/cjs/query.js.map +1 -0
  29. package/lib/cjs/refs.js +12 -0
  30. package/lib/cjs/refs.js.map +1 -0
  31. package/lib/cjs/runs.js +3 -0
  32. package/lib/cjs/runs.js.map +1 -0
  33. package/lib/cjs/store/activity-catalog.js +3 -0
  34. package/lib/cjs/store/activity-catalog.js.map +1 -0
  35. package/lib/cjs/store/common.js +3 -0
  36. package/lib/cjs/store/common.js.map +1 -0
  37. package/lib/cjs/store/dsl-workflow.js +5 -0
  38. package/lib/cjs/store/dsl-workflow.js.map +1 -0
  39. package/lib/cjs/store/index.js +24 -0
  40. package/lib/cjs/store/index.js.map +1 -0
  41. package/lib/cjs/store/object-types.js +98 -0
  42. package/lib/cjs/store/object-types.js.map +1 -0
  43. package/lib/cjs/store/store.js +18 -0
  44. package/lib/cjs/store/store.js.map +1 -0
  45. package/lib/cjs/store/temporalio.js +44 -0
  46. package/lib/cjs/store/temporalio.js.map +1 -0
  47. package/lib/cjs/store/workflow.js +24 -0
  48. package/lib/cjs/store/workflow.js.map +1 -0
  49. package/lib/cjs/training.js +14 -0
  50. package/lib/cjs/training.js.map +1 -0
  51. package/lib/cjs/transient-tokens.js +9 -0
  52. package/lib/cjs/transient-tokens.js.map +1 -0
  53. package/lib/cjs/user.js +12 -0
  54. package/lib/cjs/user.js.map +1 -0
  55. package/lib/cjs/utils/auth.js +15 -0
  56. package/lib/cjs/utils/auth.js.map +1 -0
  57. package/lib/cjs/utils/schemas.js +48 -0
  58. package/lib/cjs/utils/schemas.js.map +1 -0
  59. package/lib/esm/access-control.js +36 -0
  60. package/lib/esm/access-control.js.map +1 -0
  61. package/lib/esm/analytics.js +2 -0
  62. package/lib/esm/analytics.js.map +1 -0
  63. package/lib/esm/apikey.js +12 -0
  64. package/lib/esm/apikey.js.map +1 -0
  65. package/lib/esm/common.js +2 -0
  66. package/lib/esm/common.js.map +1 -0
  67. package/lib/esm/environment.js +113 -0
  68. package/lib/esm/environment.js.map +1 -0
  69. package/lib/esm/facets.js +2 -0
  70. package/lib/esm/facets.js.map +1 -0
  71. package/lib/esm/index.js +21 -0
  72. package/lib/esm/index.js.map +1 -0
  73. package/lib/esm/integrations.js +7 -0
  74. package/lib/esm/integrations.js.map +1 -0
  75. package/lib/esm/interaction.js +60 -0
  76. package/lib/esm/interaction.js.map +1 -0
  77. package/lib/esm/payload.js +2 -0
  78. package/lib/esm/payload.js.map +1 -0
  79. package/lib/esm/project.js +46 -0
  80. package/lib/esm/project.js.map +1 -0
  81. package/lib/esm/prompt.js +18 -0
  82. package/lib/esm/prompt.js.map +1 -0
  83. package/lib/esm/query.js +2 -0
  84. package/lib/esm/query.js.map +1 -0
  85. package/lib/esm/refs.js +9 -0
  86. package/lib/esm/refs.js.map +1 -0
  87. package/lib/esm/runs.js +2 -0
  88. package/lib/esm/runs.js.map +1 -0
  89. package/lib/esm/store/activity-catalog.js +2 -0
  90. package/lib/esm/store/activity-catalog.js.map +1 -0
  91. package/lib/esm/store/common.js +2 -0
  92. package/lib/esm/store/common.js.map +1 -0
  93. package/lib/esm/store/dsl-workflow.js +2 -0
  94. package/lib/esm/store/dsl-workflow.js.map +1 -0
  95. package/lib/esm/store/index.js +8 -0
  96. package/lib/esm/store/index.js.map +1 -0
  97. package/lib/esm/store/object-types.js +95 -0
  98. package/lib/esm/store/object-types.js.map +1 -0
  99. package/lib/esm/store/store.js +15 -0
  100. package/lib/esm/store/store.js.map +1 -0
  101. package/lib/esm/store/temporalio.js +41 -0
  102. package/lib/esm/store/temporalio.js.map +1 -0
  103. package/lib/esm/store/workflow.js +21 -0
  104. package/lib/esm/store/workflow.js.map +1 -0
  105. package/lib/esm/training.js +11 -0
  106. package/lib/esm/training.js.map +1 -0
  107. package/lib/esm/transient-tokens.js +6 -0
  108. package/lib/esm/transient-tokens.js.map +1 -0
  109. package/lib/esm/user.js +9 -0
  110. package/lib/esm/user.js.map +1 -0
  111. package/lib/esm/utils/auth.js +11 -0
  112. package/lib/esm/utils/auth.js.map +1 -0
  113. package/lib/esm/utils/schemas.js +44 -0
  114. package/lib/esm/utils/schemas.js.map +1 -0
  115. package/lib/tsconfig.tsbuildinfo +1 -0
  116. package/lib/types/access-control.d.ts +56 -0
  117. package/lib/types/access-control.d.ts.map +1 -0
  118. package/lib/types/analytics.d.ts +36 -0
  119. package/lib/types/analytics.d.ts.map +1 -0
  120. package/lib/types/apikey.d.ts +54 -0
  121. package/lib/types/apikey.d.ts.map +1 -0
  122. package/lib/types/common.d.ts +28 -0
  123. package/lib/types/common.d.ts.map +1 -0
  124. package/lib/types/environment.d.ts +79 -0
  125. package/lib/types/environment.d.ts.map +1 -0
  126. package/lib/types/facets.d.ts +34 -0
  127. package/lib/types/facets.d.ts.map +1 -0
  128. package/lib/types/index.d.ts +20 -0
  129. package/lib/types/index.d.ts.map +1 -0
  130. package/lib/types/integrations.d.ts +18 -0
  131. package/lib/types/integrations.d.ts.map +1 -0
  132. package/lib/types/interaction.d.ts +233 -0
  133. package/lib/types/interaction.d.ts.map +1 -0
  134. package/lib/types/payload.d.ts +49 -0
  135. package/lib/types/payload.d.ts.map +1 -0
  136. package/lib/types/project.d.ts +95 -0
  137. package/lib/types/project.d.ts.map +1 -0
  138. package/lib/types/prompt.d.ts +70 -0
  139. package/lib/types/prompt.d.ts.map +1 -0
  140. package/lib/types/query.d.ts +74 -0
  141. package/lib/types/query.d.ts.map +1 -0
  142. package/lib/types/refs.d.ts +19 -0
  143. package/lib/types/refs.d.ts.map +1 -0
  144. package/lib/types/runs.d.ts +24 -0
  145. package/lib/types/runs.d.ts.map +1 -0
  146. package/lib/types/store/activity-catalog.d.ts +24 -0
  147. package/lib/types/store/activity-catalog.d.ts.map +1 -0
  148. package/lib/types/store/common.d.ts +10 -0
  149. package/lib/types/store/common.d.ts.map +1 -0
  150. package/lib/types/store/dsl-workflow.d.ts +244 -0
  151. package/lib/types/store/dsl-workflow.d.ts.map +1 -0
  152. package/lib/types/store/index.d.ts +7 -0
  153. package/lib/types/store/index.d.ts.map +1 -0
  154. package/lib/types/store/object-types.d.ts +23 -0
  155. package/lib/types/store/object-types.d.ts.map +1 -0
  156. package/lib/types/store/store.d.ts +211 -0
  157. package/lib/types/store/store.d.ts.map +1 -0
  158. package/lib/types/store/temporalio.d.ts +16 -0
  159. package/lib/types/store/temporalio.d.ts.map +1 -0
  160. package/lib/types/store/workflow.d.ts +129 -0
  161. package/lib/types/store/workflow.d.ts.map +1 -0
  162. package/lib/types/training.d.ts +38 -0
  163. package/lib/types/training.d.ts.map +1 -0
  164. package/lib/types/transient-tokens.d.ts +27 -0
  165. package/lib/types/transient-tokens.d.ts.map +1 -0
  166. package/lib/types/user.d.ts +105 -0
  167. package/lib/types/user.d.ts.map +1 -0
  168. package/lib/types/utils/auth.d.ts +3 -0
  169. package/lib/types/utils/auth.d.ts.map +1 -0
  170. package/lib/types/utils/schemas.d.ts +5 -0
  171. package/lib/types/utils/schemas.d.ts.map +1 -0
  172. package/package.json +34 -0
  173. package/src/access-control.ts +77 -0
  174. package/src/analytics.ts +49 -0
  175. package/src/apikey.ts +68 -0
  176. package/src/common.ts +34 -0
  177. package/src/environment.ts +193 -0
  178. package/src/facets.ts +44 -0
  179. package/src/index.ts +20 -0
  180. package/src/integrations.ts +25 -0
  181. package/src/interaction.ts +300 -0
  182. package/src/payload.ts +62 -0
  183. package/src/project.ts +136 -0
  184. package/src/prompt.ts +95 -0
  185. package/src/query.ts +85 -0
  186. package/src/refs.ts +27 -0
  187. package/src/runs.ts +27 -0
  188. package/src/store/activity-catalog.ts +39 -0
  189. package/src/store/common.ts +10 -0
  190. package/src/store/dsl-workflow.ts +289 -0
  191. package/src/store/index.ts +7 -0
  192. package/src/store/ms.d.ts +11 -0
  193. package/src/store/object-types.ts +128 -0
  194. package/src/store/store.ts +262 -0
  195. package/src/store/temporalio.ts +54 -0
  196. package/src/store/workflow.ts +156 -0
  197. package/src/training.ts +44 -0
  198. package/src/transient-tokens.ts +30 -0
  199. package/src/user.ts +124 -0
  200. package/src/utils/auth.ts +12 -0
  201. package/src/utils/schemas.ts +44 -0
@@ -0,0 +1,300 @@
1
+ import type { JSONObject, Modalities, ModelOptions } from "@llumiverse/core";
2
+ import { JSONSchema4 } from 'json-schema';
3
+
4
+ import { ExecutionTokenUsage } from '@llumiverse/core';
5
+
6
+ import { ExecutionEnvironmentRef } from './environment.js';
7
+ import { ProjectRef } from './project.js';
8
+ import { PopulatedPromptSegmentDef, PromptSegmentDef, PromptTemplateRef, PromptTemplateRefWithSchema } from './prompt.js';
9
+ import { AccountRef } from './user.js';
10
+
11
+ export interface InteractionExecutionError {
12
+ code: string;
13
+ message: string;
14
+ data?: any;
15
+ }
16
+
17
+ export interface InteractionRef {
18
+ id: string;
19
+ name: string;
20
+ description?: string;
21
+ status: InteractionStatus;
22
+ visibility?: InteractionVisibility;
23
+ version: number;
24
+ tags: string[];
25
+ prompts?: PromptSegmentDef<PromptTemplateRef>[];
26
+ updated_at: Date;
27
+ }
28
+ export const InteractionRefPopulate = "id name description status version visibility tags updated_at prompts";
29
+
30
+ export interface InteractionRefWithSchema
31
+ extends Omit<InteractionRef, "prompts"> {
32
+ result_schema?: JSONSchema4;
33
+ prompts?: PromptSegmentDef<PromptTemplateRefWithSchema>[];
34
+ }
35
+
36
+ export interface InteractionsExportPayload {
37
+ /**
38
+ * The name of the interaction. If not spcified all the interactions in the current project will be exported
39
+ */
40
+ name?: string;
41
+ /*
42
+ * tags to filter the exported interactions
43
+ */
44
+ tags?: string[];
45
+ /*
46
+ * if not specified, all versions will be exported
47
+ */
48
+ versions?: (number | 'draft' | 'latest')[];
49
+ }
50
+
51
+ export enum InteractionStatus {
52
+ draft = "draft",
53
+ published = "published",
54
+ archived = "archived",
55
+ }
56
+
57
+ export enum ExecutionRunStatus {
58
+ created = "created",
59
+ processing = "processing",
60
+ completed = "completed",
61
+ failed = "failed",
62
+ }
63
+
64
+ export enum RunDataStorageLevel {
65
+ STANDARD = "STANDARD",
66
+ RESTRICTED = "RESTRICTED",
67
+ DEBUG = "DEBUG"
68
+ }
69
+
70
+ export enum RunDataStorageDescription {
71
+ STANDARD = "Run data is stored for both the model inputs and output.",
72
+ RESTRICTED = "No run data is stored for the model inputs — only the model output.",
73
+ DEBUG = "Run data is stored for the model inputs and output, schema, and final prompt."
74
+ }
75
+
76
+ export const RunDataStorageOptions: Record<RunDataStorageLevel, RunDataStorageDescription> = {
77
+ [RunDataStorageLevel.STANDARD]: RunDataStorageDescription.STANDARD,
78
+ [RunDataStorageLevel.RESTRICTED]: RunDataStorageDescription.RESTRICTED,
79
+ [RunDataStorageLevel.DEBUG]: RunDataStorageDescription.DEBUG,
80
+ }
81
+
82
+ /**
83
+ * Schema can be stored or specified as a reference to an external schema.
84
+ * We only support "store:" references for now
85
+ */
86
+ export interface SchemaRef {
87
+ $uri: string;
88
+ }
89
+ export interface CachePolicy {
90
+ type: "cache" | "no_cache" | "cache_and_refresh";
91
+ refresh_probability: number;
92
+ varies_on: string[];
93
+ ttl: number;
94
+ }
95
+ export type InteractionVisibility = 'public' | 'private';
96
+ export interface Interaction extends ModelOptions {
97
+ readonly id: string;
98
+ name: string;
99
+ endpoint: string;
100
+ description?: string;
101
+ status: InteractionStatus;
102
+ parent?: string;
103
+ // only used for versions (status === "published")
104
+ visibility: InteractionVisibility;
105
+ version: number;
106
+ tags: string[];
107
+ test_data?: JSONObject;
108
+ result_schema?: JSONSchema4 | SchemaRef;
109
+ cache_policy?: CachePolicy;
110
+ model: string;
111
+ prompts: PromptSegmentDef[];
112
+ output_modality?: Modalities;
113
+ environment: string | ExecutionEnvironmentRef;
114
+ restriction?: RunDataStorageLevel;
115
+ project: string | ProjectRef;
116
+ // only for drafts - when it was last published
117
+ last_published_at?: Date;
118
+ created_by: string,
119
+ updated_by: string,
120
+ created_at: Date;
121
+ updated_at: Date;
122
+ }
123
+
124
+ export interface PopulatedInteraction
125
+ extends Omit<Interaction, "prompts"> {
126
+ prompts: PopulatedPromptSegmentDef[];
127
+ }
128
+
129
+ export interface InteractionCreatePayload
130
+ extends Omit<
131
+ Interaction,
132
+ "id" | "created_at" | "updated_at" | "created_by" | "updated_by" | "project" | "formatter" | "tags" | "parent" | "version" | "visibility" | "endpoint"
133
+ > {
134
+ visibility?: InteractionVisibility;
135
+ }
136
+
137
+ export interface InteractionUpdatePayload
138
+ extends Partial<
139
+ Omit<
140
+ Interaction,
141
+ "result_schema" | "id" | "created_at" | "updated_at" | "created_by" | "updated_by" | "project"
142
+ | "temperature" | "max_tokens" | "stop_sequence" | "top_k" | "top_p" | "presence_penalty" | "frequency_penalty" | "top_logprobs"
143
+ >
144
+ > {
145
+ result_schema?: JSONSchema4 | null;
146
+
147
+ // Change ModelOptions properties to include null as a possible type
148
+ // Null values indicate that the property should be cleared.
149
+ temperature?: number | null;
150
+ max_tokens?: number | null;
151
+ stop_sequence?: string[] | null;
152
+ top_k?: number | null;
153
+ top_p?: number | null;
154
+ top_logprobs?: number | null;
155
+ presence_penalty?: number | null;
156
+ frequency_penalty?: number | null;
157
+ }
158
+
159
+ export interface InteractionPublishPayload {
160
+ visibility?: InteractionVisibility;
161
+ tags?: string[];
162
+ }
163
+
164
+ export interface InteractionForkPayload {
165
+ keepTags?: boolean;
166
+ forkPrompts?: boolean;
167
+ targetProject?: string;
168
+ }
169
+
170
+
171
+ export interface InteractionExecutionPayload {
172
+ /**
173
+ * If a `@memory` property exists on the input data then the value will be used as the value of a memory pack location.
174
+ * and the other proerties of the data will contain the memory pack mapping.
175
+ */
176
+ data?: Record<string, any> | `memory:${string}`;
177
+ config?: InteractionExecutionConfiguration;
178
+ result_schema?: JSONSchema4;
179
+ stream?: boolean;
180
+ do_validate?: boolean;
181
+ tags?: string | string[]; // tags to be added to the execution run
182
+ }
183
+
184
+ export interface NamedInteractionExecutionPayload extends InteractionExecutionPayload {
185
+ /**
186
+ * The interaction name and suffixed by an optional tag or version separated from the name using a @ character
187
+ * If no version/tag part is specified then the latest version is used.
188
+ * Example: ReviewContract, ReviewContract@draft, ReviewContract@1, ReviewContract@some-tag
189
+ */
190
+ interaction: string;
191
+ }
192
+
193
+ export enum RunSourceTypes {
194
+ api = "api",
195
+ cli = "cli",
196
+ ui = "ui",
197
+ webhook = "webhook",
198
+ test = "test-data",
199
+ system = "system",
200
+ }
201
+
202
+ export interface RunSource {
203
+ type: RunSourceTypes;
204
+ label: string;
205
+ principal_type: 'user' | 'apikey';
206
+ principal_id: string;
207
+ client_ip: string;
208
+ }
209
+
210
+ export interface ExecutionRun<P = any, R = any> {
211
+ readonly id: string;
212
+ /**
213
+ * Only used by runs that were created by a virtual run to point toward the virtual run parent
214
+ */
215
+ parent?: string | ExecutionRun;
216
+ evaluation?: {
217
+ score?: number,
218
+ selected?: boolean,
219
+ scores?: Record<string, number>
220
+ }
221
+ result: R;
222
+ /**
223
+ * The parameters used to create the interaction.
224
+ * If the parameters contains the special property "@memory" it will be used
225
+ * to locate a meory pack and the other properties will be used as the memory pack mapping.
226
+ */
227
+ parameters: P; //params used to create the interaction, only in varies on?
228
+ tags?: string[];
229
+ //TODO a string is returned when executing not the interaction object
230
+ interaction: Interaction;
231
+ //TODO a string is returned when execution not the env object
232
+ environment: ExecutionEnvironmentRef;
233
+ modelId: string;
234
+ result_schema: JSONSchema4;
235
+ ttl: number;
236
+ status: ExecutionRunStatus;
237
+ finish_reason?: string;
238
+ prompt: any;
239
+ token_use?: ExecutionTokenUsage;
240
+ chunks?: number;
241
+ execution_time?: number; //s
242
+ created_at: Date;
243
+ updated_at: Date;
244
+ account: AccountRef;
245
+ project: ProjectRef;
246
+ config: InteractionExecutionConfiguration;
247
+ error?: InteractionExecutionError;
248
+ source: RunSource;
249
+ output_modality: Modalities;
250
+ created_by: string,
251
+ updated_by: string,
252
+ }
253
+
254
+ export interface ExecutionRunRef
255
+ extends Omit<ExecutionRun, "result" | "parameters" | "interaction"> {
256
+ interaction: InteractionRef;
257
+ }
258
+
259
+ export const ExecutionRunRefSelect = "-result -parameters -result_schema -prompt";
260
+
261
+ export enum ConfigModes {
262
+ RUN_AND_INTERACTION_CONFIG = "RUN_AND_INTERACTION_CONFIG",
263
+ RUN_CONFIG_ONLY = "RUN_CONFIG_ONLY",
264
+ INTERACTION_CONFIG_ONLY = "INTERACTION_CONFIG_ONLY"
265
+ };
266
+
267
+ export enum ConfigModesDescription {
268
+ RUN_AND_INTERACTION_CONFIG = "This run configuration is used. Undefined options are filled with interaction configuration.",
269
+ RUN_CONFIG_ONLY = "Only this run configuration is used. Undefined options remain undefined.",
270
+ INTERACTION_CONFIG_ONLY = "Only interaction configuration is used."
271
+ }
272
+
273
+ export const ConfigModesOptions: Record<ConfigModes, ConfigModesDescription> = {
274
+ [ConfigModes.RUN_AND_INTERACTION_CONFIG]: ConfigModesDescription.RUN_AND_INTERACTION_CONFIG,
275
+ [ConfigModes.RUN_CONFIG_ONLY]: ConfigModesDescription.RUN_CONFIG_ONLY,
276
+ [ConfigModes.INTERACTION_CONFIG_ONLY]: ConfigModesDescription.INTERACTION_CONFIG_ONLY,
277
+ }
278
+
279
+ export interface InteractionExecutionConfiguration extends ModelOptions {
280
+ environment?: string;
281
+ model?: string;
282
+ do_validate?: boolean;
283
+ run_data?: RunDataStorageLevel;
284
+ configMode?: ConfigModes;
285
+ }
286
+
287
+ export interface GenerateInteractionPayload {
288
+ description: string;
289
+ config: InteractionExecutionConfiguration;
290
+ }
291
+
292
+ export interface GenerateTestDataPayload {
293
+ message?: string;
294
+ count?: number;
295
+ config: InteractionExecutionConfiguration;
296
+ }
297
+
298
+ export interface ImprovePromptPayload {
299
+ config: InteractionExecutionConfiguration;
300
+ }
package/src/payload.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { FacetSpec } from './facets.js';
2
+ import { ComplexSearchQuery, InteractionSearchQuery, ObjectSearchQuery, ObjectTypeSearchQuery, PromptSearchQuery, RunSearchQuery, SimpleSearchQuery, VectorSearchQuery } from './query.js';
3
+
4
+ export interface SearchPayload {
5
+ query?: SimpleSearchQuery;
6
+ limit?: number;
7
+ offset?: number;
8
+ }
9
+
10
+ export interface ComputeFacetPayload {
11
+ facets: FacetSpec[];
12
+ query?: SimpleSearchQuery;
13
+ }
14
+
15
+ export interface InteractionSearchPayload extends SearchPayload {
16
+ query?: InteractionSearchQuery;
17
+ }
18
+
19
+ export interface ObjectSearchPayload extends SearchPayload {
20
+ query?: ObjectSearchQuery;
21
+ }
22
+
23
+ export interface ObjectTypeSearchPayload extends SearchPayload {
24
+ query?: ObjectTypeSearchQuery;
25
+ }
26
+
27
+ export interface PromptSearchPayload extends SearchPayload {
28
+ query?: PromptSearchQuery;
29
+ }
30
+
31
+ export interface RunSearchPayload extends SearchPayload {
32
+ query?: RunSearchQuery;
33
+ }
34
+
35
+ export interface ComputeInteractionFacetPayload extends ComputeFacetPayload {
36
+ query?: InteractionSearchQuery;
37
+ }
38
+
39
+ export interface ComputeObjectFacetPayload extends ComputeFacetPayload {
40
+ query?: ObjectSearchQuery;
41
+ vector?: VectorSearchQuery;
42
+ }
43
+
44
+ export interface ComputePromptFacetPayload extends ComputeFacetPayload {
45
+ query?: PromptSearchQuery;
46
+ }
47
+
48
+ export interface ComputeRunFacetPayload extends ComputeFacetPayload {
49
+ query?: RunSearchQuery;
50
+ }
51
+
52
+ export interface ExportPropertiesPayload {
53
+ objectIds: string[];
54
+ type: string;
55
+ query?: ComplexSearchQuery;
56
+ }
57
+
58
+ export interface ExportPropertiesResponse {
59
+ type: string;
60
+ name: string;
61
+ data: Blob;
62
+ }
package/src/project.ts ADDED
@@ -0,0 +1,136 @@
1
+ import { SupportedIntegrations } from "./integrations.js";
2
+ import { AccountRef } from "./user.js";
3
+
4
+ export interface ICreateProjectPayload {
5
+ name: string;
6
+ namespace: string;
7
+ description?: string;
8
+ }
9
+ export enum ProjectRoles {
10
+ owner = "owner", // all permissions
11
+ admin = "admin", // all permissions
12
+ project_admin = "project_admin", // all permissions but manage_account, manage_billing
13
+ developer = "developer", // all permissions but manage_account, manage_billing, manage_roles, delete
14
+ application = "application", // executor + request_pk
15
+ executor = "executor", // can only read and execute interactions
16
+ reader = "reader", // can only read (browse)
17
+ billing = "billing", // can only manage billings
18
+ member = "member", // can only access, but no specific permissions
19
+ }
20
+
21
+ export function isRoleIncludedIn(role: string, includingRole: string) {
22
+ switch (includingRole) {
23
+ case ProjectRoles.owner:
24
+ return true; // includes billing to?
25
+ case ProjectRoles.admin:
26
+ return role !== ProjectRoles.billing && role !== ProjectRoles.owner;
27
+ case ProjectRoles.developer:
28
+ return role === ProjectRoles.developer;
29
+ case ProjectRoles.billing:
30
+ return role === ProjectRoles.billing;
31
+ default:
32
+ return false;
33
+ }
34
+ }
35
+
36
+
37
+ export interface PopulatedProjectRef {
38
+ id: string;
39
+ name: string;
40
+ account: AccountRef
41
+ }
42
+ export interface ProjectRef {
43
+ id: string;
44
+ name: string;
45
+ account: string;
46
+ }
47
+
48
+ export enum ResourceVisibility {
49
+ public = "public",
50
+ account = "account",
51
+ project = "project"
52
+ }
53
+
54
+
55
+ export interface ProjectConfiguration {
56
+
57
+ human_context: string;
58
+
59
+ default_environment?: string;
60
+ default_model?: string;
61
+
62
+ embeddings: {
63
+ text?: ProjectConfigurationEmbeddings;
64
+ image?: ProjectConfigurationEmbeddings;
65
+ properties?: ProjectConfigurationEmbeddings
66
+ }
67
+
68
+ datacenter?: string;
69
+ storage_bucket?: string;
70
+
71
+ }
72
+
73
+ // export interface ProjectConfigurationEmbeddings {
74
+ // environment: string;
75
+ // max_tokens: number;
76
+ // dimensions: number;
77
+ // model?: string;
78
+ // }
79
+
80
+ export enum SupportedEmbeddingTypes {
81
+ text = "text",
82
+ image = "image",
83
+ properties = "properties"
84
+ }
85
+
86
+ export interface ProjectConfigurationEmbeddings {
87
+ environment: string;
88
+ enabled: boolean;
89
+ dimensions: number;
90
+ max_tokens?: number;
91
+ model?: string;
92
+ }
93
+
94
+ export interface Project {
95
+ id: string;
96
+ name: string;
97
+ namespace: string;
98
+ description?: string;
99
+ account: string;
100
+ configuration: ProjectConfiguration;
101
+ integrations: Map<string, any>;
102
+ created_by: string,
103
+ updated_by: string,
104
+ created_at: Date;
105
+ updated_at: Date;
106
+ }
107
+
108
+ export interface ProjectCreatePayload {
109
+ name: string;
110
+ description?: string;
111
+ }
112
+
113
+ export interface ProjectUpdatePayload extends Partial<Project> { }
114
+
115
+
116
+ export const ProjectRefPopulate = "id name account";
117
+
118
+
119
+ export interface EmbeddingsStatusResponse {
120
+ status: string;
121
+ embeddingRunsInProgress: number;
122
+ totalRunsInProgress: number;
123
+ totalIndexableObjects: number;
124
+ embeddingsModels: string[];
125
+ objectsWithEmbeddings: number;
126
+ vectorIndex: {
127
+ status: "READY" | "PENDING" | "DELETING" | "ABSENT",
128
+ name?: string,
129
+ type?: string
130
+ }
131
+ }
132
+
133
+ export interface ProjectIntegrationListEntry {
134
+ id: SupportedIntegrations;
135
+ enabled: boolean;
136
+ }
package/src/prompt.ts ADDED
@@ -0,0 +1,95 @@
1
+ import { JSONSchema4 } from "json-schema";
2
+ import type { JSONObject } from "@llumiverse/core";
3
+ import { ProjectRef } from "./project.js";
4
+ import { PromptRole } from "@llumiverse/core";
5
+
6
+ export interface ChatPromptSchema {
7
+ role: PromptRole.user | PromptRole.assistant;
8
+ content: string;
9
+ }
10
+
11
+ export enum PromptStatus {
12
+ draft = "draft",
13
+ published = "published",
14
+ archived = "archived",
15
+ }
16
+
17
+
18
+ export enum PromptSegmentDefType {
19
+ chat = "chat",
20
+ template = "template",
21
+ }
22
+
23
+ export interface PromptSegmentDef<
24
+ T = string | PromptTemplate | PromptTemplateRef,
25
+ > {
26
+ type: PromptSegmentDefType;
27
+ template?: T; // the template id in case of a prompt template
28
+ configuration?: any; // the configuration if any in case of builtin prompts
29
+ }
30
+ export interface PopulatedPromptSegmentDef
31
+ extends Omit<PromptSegmentDef, "template"> {
32
+ template?: PromptTemplate;
33
+ }
34
+
35
+ export interface PromptTemplateRef {
36
+ id: string;
37
+ name: string;
38
+ role: PromptRole;
39
+ version: number;
40
+ status: PromptStatus;
41
+ content_type: TemplateType;
42
+ }
43
+
44
+ export interface PromptTemplateRefWithSchema extends PromptTemplateRef {
45
+ inputSchema?: JSONSchema4;
46
+ }
47
+
48
+ export enum TemplateType {
49
+ text = "text",
50
+ js = "js",
51
+ jst = "jst",
52
+ }
53
+
54
+ export interface PromptTemplate {
55
+ id: string;
56
+ name: string;
57
+ role: PromptRole;
58
+ status: PromptStatus;
59
+ version: number;
60
+ // only to be used by published versions
61
+ // the id draft version which is the source of this published version (only when published)
62
+ parent?: string;
63
+ description?: string;
64
+ content_type: TemplateType;
65
+ content: string;
66
+ test_data?: JSONObject; // optional test data satisfying the schema
67
+ script?: string; // cache the template output
68
+ inputSchema?: JSONSchema4;
69
+ project: string | ProjectRef; // or projectRef? ObjectIdType;
70
+ // The name of a field in the input data that is of the specified schema and on each the template will iterate.
71
+ // If not specified then the sceham will define the whole input data
72
+ tags?: string[];
73
+ // only for drafts - when it was last published
74
+ last_published_at?: Date;
75
+ created_by: string,
76
+ updated_by: string,
77
+ created_at: Date;
78
+ updated_at: Date;
79
+ }
80
+
81
+ export interface PromptTemplateForkPayload {
82
+ keepTags?: boolean;
83
+ targetProject?: string;
84
+ }
85
+
86
+ export interface PromptTemplateCreatePayload
87
+ extends Omit<
88
+ PromptTemplate,
89
+ "id" | "created_at" | "updated_at" | "created_by" | "updated_by" | "project" | "status" | "version"
90
+ > { }
91
+
92
+ export interface PromptTemplateUpdatePayload
93
+ extends Partial<
94
+ Omit<PromptTemplate, "id" | "created_at" | "updated_at" | "created_by" | "updated_by" | "project">
95
+ > { }
package/src/query.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { ExecutionRunStatus } from './interaction.js';
2
+ import { SupportedEmbeddingTypes } from './project.js';
3
+
4
+ export interface RunListingQueryOptions {
5
+ project?: string;
6
+ interaction?: string;
7
+ limit?: number;
8
+ offset?: number;
9
+ filters?: RunListingFilters;
10
+ }
11
+
12
+ export interface RunListingFilters {
13
+ interaction?: string,
14
+ status?: ExecutionRunStatus,
15
+ model?: string,
16
+ environment?: string,
17
+ tag?: string,
18
+ fromDate?: string,
19
+ toDate?: string,
20
+ parent?: string | false,
21
+ }
22
+
23
+ export interface VectorSearchQuery {
24
+ objectId?: string;
25
+ values?: number[];
26
+ text?: string;
27
+ image?: string;
28
+ threshold?: number;
29
+ type: SupportedEmbeddingTypes
30
+ }
31
+
32
+ export interface SimpleSearchQuery {
33
+ name?: string;
34
+ status?: string;
35
+ }
36
+
37
+ export interface ObjectSearchQuery extends SimpleSearchQuery {
38
+ location?: string;
39
+ parent?: string;
40
+ similarTo?: string;
41
+ embeddingType?: SupportedEmbeddingTypes;
42
+ type?: string;
43
+ }
44
+
45
+ export interface ObjectTypeSearchQuery extends SimpleSearchQuery {
46
+ chunckable?: boolean;
47
+ }
48
+
49
+ export interface PromptSearchQuery extends SimpleSearchQuery {
50
+ role?: string;
51
+ }
52
+
53
+ export interface InteractionSearchQuery extends SimpleSearchQuery {
54
+ prompt?: string;
55
+ tags?: string[];
56
+ version?: number;
57
+ }
58
+
59
+ export interface RunSearchQuery extends SimpleSearchQuery {
60
+ offset?: number;
61
+ interaction?: string;
62
+ environment?: string;
63
+ model?: string;
64
+ status?: ExecutionRunStatus;
65
+ tags?: string[];
66
+ query?: string;
67
+ default_query_path?: string;
68
+ parent?: string[] | false;
69
+ object?: string;
70
+ start?: string;
71
+ end?: string;
72
+ }
73
+
74
+ export interface WorkflowExecutionSearchQuery extends SimpleSearchQuery {
75
+ documentId?: string;
76
+ eventName?: string;
77
+ ruleId?: string;
78
+ start?: string;
79
+ end?: string;
80
+ status?: string;
81
+ }
82
+
83
+ export interface ComplexSearchQuery extends ObjectSearchQuery {
84
+ vector?: VectorSearchQuery;
85
+ }
package/src/refs.ts ADDED
@@ -0,0 +1,27 @@
1
+
2
+
3
+ export enum ResolvableRefType {
4
+ project = "Project",
5
+ environment = "Environment",
6
+ user = "User",
7
+ account = "Account",
8
+ interaction = "Interaction"
9
+ }
10
+
11
+ export interface ResolvableRef {
12
+ type: ResolvableRefType
13
+ id: string
14
+ }
15
+
16
+ export interface RefResolutionRequest {
17
+
18
+ refs: ResolvableRef[]
19
+
20
+ }
21
+
22
+
23
+ export interface ResourceRef {
24
+ id: string
25
+ name: string
26
+ type: string
27
+ }