@proteos/sdk 0.94.1 → 0.96.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteos/sdk",
3
- "version": "0.94.1",
3
+ "version": "0.96.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "TypeScript SDK for the Proteos platform",
6
6
  "repository": {
@@ -156,6 +156,9 @@ export const PLATFORM_ENTITIES: readonly PlatformEntity[] = [
156
156
  // Usage (usage-service): the metering ledger. Read-only and org-level —
157
157
  // whoever reads usage reads all of the org's usage.
158
158
  { slug: 'usage-records', name: 'Usage Records' },
159
+ // The org's usage limits per meter and period (stacking contributions).
160
+ // Org-level; org roles read, only platform admins write.
161
+ { slug: 'usage-limits', name: 'Usage Limits' },
159
162
  ] as const
160
163
 
161
164
  /** Just the platform entity slugs, in canonical order. */
@@ -2,6 +2,7 @@ import type { ProteosClient } from '../client.js'
2
2
  import type {
3
3
  CreateEnrichmentConnectionRequest,
4
4
  CreateEnrichmentRunRequest,
5
+ CreateEnrichmentTypeRequest,
5
6
  CreateResearchDefinitionRequest,
6
7
  CreateSignalMonitorRequest,
7
8
  CreateWaterfallRequest,
@@ -15,6 +16,7 @@ import type {
15
16
  EnrichmentRun,
16
17
  EnrichmentRunList,
17
18
  EnrichmentRunResponse,
19
+ EnrichmentType,
18
20
  EnrichmentTypesResponse,
19
21
  EnrichRequest,
20
22
  EnrichResponse,
@@ -22,6 +24,7 @@ import type {
22
24
  ListResearchRunsQuery,
23
25
  ListSignalsQuery,
24
26
  PatchEnrichmentConnectionRequest,
27
+ PatchEnrichmentTypeRequest,
25
28
  PatchResearchDefinitionRequest,
26
29
  PatchSignalMonitorRequest,
27
30
  PatchWaterfallRequest,
@@ -34,6 +37,8 @@ import type {
34
37
  SignalList,
35
38
  SignalMapping,
36
39
  SignalMonitor,
40
+ TestEnrichmentConnectionRequest,
41
+ TestEnrichmentConnectionResponse,
37
42
  Waterfall,
38
43
  } from './types.js'
39
44
 
@@ -125,6 +130,11 @@ export interface EnrichmentRunService {
125
130
  * to a reviewer who accepted it.
126
131
  */
127
132
  provenance(entitySlug: string, recordId: string): Promise<EnrichmentProvenance>
133
+ /**
134
+ * What the latest runs over records found for one record, newest first
135
+ * (at most 20), whatever their status. An ad-hoc `enrich` is not listed.
136
+ */
137
+ listRecordItems(entitySlug: string, recordId: string): Promise<EnrichmentItem[]>
128
138
  }
129
139
 
130
140
  /** The enrichment mapping of an entity. */
@@ -162,6 +172,8 @@ export interface EnrichmentConnectionService {
162
172
  patch(id: string, request: PatchEnrichmentConnectionRequest): Promise<EnrichmentConnection>
163
173
  /** A waterfall step that names it is skipped from then on. */
164
174
  delete(id: string): Promise<void>
175
+ /** Runs a routine once with a config that may not be saved yet, on the org's own credits. Saves nothing. */
176
+ test(request: TestEnrichmentConnectionRequest): Promise<TestEnrichmentConnectionResponse>
165
177
  }
166
178
 
167
179
  /**
@@ -223,8 +235,14 @@ export interface SignalService {
223
235
 
224
236
  /** What can be asked for and who supplies it. The same for every org. */
225
237
  export interface EnrichmentCatalogService {
238
+ /** The platform's types, then the org's own. */
226
239
  enrichmentTypes(): Promise<EnrichmentTypesResponse>
227
240
  providers(): Promise<EnrichmentProvider[]>
241
+ /** Defines one of the org's own enrichment types. */
242
+ createEnrichmentType(request: CreateEnrichmentTypeRequest): Promise<EnrichmentType>
243
+ patchEnrichmentType(key: string, request: PatchEnrichmentTypeRequest): Promise<EnrichmentType>
244
+ /** Refused while one of the org's waterfalls fills it. */
245
+ deleteEnrichmentType(key: string): Promise<void>
228
246
  }
229
247
 
230
248
  class EnrichmentRunServiceImpl implements EnrichmentRunService {
@@ -265,6 +283,15 @@ class EnrichmentRunServiceImpl implements EnrichmentRunService {
265
283
  record_id: recordId,
266
284
  })
267
285
  }
286
+
287
+ async listRecordItems(entitySlug: string, recordId: string): Promise<EnrichmentItem[]> {
288
+ const response = await this.client.requestWithQuery<{ data: EnrichmentItem[] }>(
289
+ 'GET',
290
+ `${ENRICHMENT_BASE_PATH}/enrichment-items`,
291
+ { entity_slug: entitySlug, record_id: recordId },
292
+ )
293
+ return response.data
294
+ }
268
295
  }
269
296
 
270
297
  class EnrichmentMappingServiceImpl implements EnrichmentMappingService {
@@ -370,6 +397,14 @@ class EnrichmentConnectionServiceImpl implements EnrichmentConnectionService {
370
397
  `${ENRICHMENT_BASE_PATH}/enrichment-connections/${encode(id)}`,
371
398
  )
372
399
  }
400
+
401
+ test(request: TestEnrichmentConnectionRequest): Promise<TestEnrichmentConnectionResponse> {
402
+ return this.client.request(
403
+ 'POST',
404
+ `${ENRICHMENT_BASE_PATH}/enrichment-connections/test`,
405
+ request,
406
+ )
407
+ }
373
408
  }
374
409
 
375
410
  class SignalServiceImpl implements SignalService {
@@ -509,4 +544,20 @@ class EnrichmentCatalogServiceImpl implements EnrichmentCatalogService {
509
544
  )
510
545
  return response.data
511
546
  }
547
+
548
+ createEnrichmentType(request: CreateEnrichmentTypeRequest): Promise<EnrichmentType> {
549
+ return this.client.request('POST', `${ENRICHMENT_BASE_PATH}/enrichment-types`, request)
550
+ }
551
+
552
+ patchEnrichmentType(key: string, request: PatchEnrichmentTypeRequest): Promise<EnrichmentType> {
553
+ return this.client.request(
554
+ 'PATCH',
555
+ `${ENRICHMENT_BASE_PATH}/enrichment-types/${encode(key)}`,
556
+ request,
557
+ )
558
+ }
559
+
560
+ async deleteEnrichmentType(key: string): Promise<void> {
561
+ await this.client.request('DELETE', `${ENRICHMENT_BASE_PATH}/enrichment-types/${encode(key)}`)
562
+ }
512
563
  }
@@ -55,6 +55,10 @@ export interface EnrichmentAttribute {
55
55
  path?: string
56
56
  /** Pins a waterfall, ahead of every default. */
57
57
  waterfall_id?: string
58
+ /** Maps what was found onto the attribute's type; with it, the path may be of any type. */
59
+ transform?: EnrichmentTransform
60
+ /** Other attributes the value is worked out from, by `transform`, without a provider call. */
61
+ derive_from?: string[]
58
62
  }
59
63
 
60
64
  /**
@@ -101,6 +105,32 @@ export interface EnrichmentAttributeResult {
101
105
  enrichment_attempt_id?: string
102
106
  /** Why the attribute has no value when its outcome is `error` or `skipped`. */
103
107
  error_code?: string
108
+ /** What a model judge said about the value; without one, about the last value it rejected. */
109
+ verification?: EnrichmentVerification
110
+ /**
111
+ * How the value was mapped onto the attribute's type, for an attribute with
112
+ * a transform. `error_code: 'not_mappable'`: it maps onto nothing the
113
+ * attribute holds.
114
+ */
115
+ mapping?: EnrichmentValueMapping
116
+ }
117
+
118
+ /**
119
+ * How a found value becomes the attribute's: a value that fits as it is (an
120
+ * enum label, a number in text) is taken, anything else is mapped by a model.
121
+ */
122
+ export interface EnrichmentTransform {
123
+ instructions?: string
124
+ /** The model that maps; empty is the platform's default. */
125
+ model_id?: string
126
+ }
127
+
128
+ /** How a found value became the attribute's. */
129
+ export interface EnrichmentValueMapping {
130
+ /** The value that was found; for a derived attribute, the values it was worked out from, by attribute. */
131
+ from: unknown
132
+ method: 'exact' | 'model'
133
+ model_id?: string
104
134
  }
105
135
 
106
136
  /** The values `POST /enrich` found. Nothing is written to a record. */
@@ -223,6 +253,8 @@ export interface EnrichmentAttributeProvenance {
223
253
  enrichment_item_id: string
224
254
  enrichment_attempt_id?: string
225
255
  record_draft_id?: string
256
+ /** What a model judge said about the value. */
257
+ verification?: EnrichmentVerification
226
258
  /** When the run found the value. */
227
259
  enriched_at: string
228
260
  }
@@ -257,6 +289,10 @@ export interface EnrichmentBlock {
257
289
  fill_min_confidence?: EnrichmentConfidence
258
290
  /** How long a value is not enriched, or paid for, again. */
259
291
  max_age_days?: number
292
+ /** Maps what was found onto the attribute's type; with it, the path may be of any type. */
293
+ transform?: EnrichmentTransform
294
+ /** Other attributes the value is worked out from, by `transform`, without a provider call. */
295
+ derive_from?: string[]
260
296
  /** The input key the attribute's value provides. */
261
297
  input?: string
262
298
  /** The company input keys the related record lends. */
@@ -299,11 +335,61 @@ export interface WaterfallStep {
299
335
  provider?: string
300
336
  /** The enrichment connection of a `connection` step. */
301
337
  enrichment_connection_id?: string
338
+ /** A switched-off step is left out of runs; a waterfall needs one step switched on. */
339
+ is_disabled?: boolean
340
+ /**
341
+ * What a `provider` step asks its provider for when that is not the
342
+ * waterfall's type, such as `company_profile` for an org's own type.
343
+ */
344
+ source_type?: string
345
+ /**
346
+ * Where in the step's answer each part of the waterfall's type is found:
347
+ * `{ value: 'employee_count' }` for a type with a single value, or by
348
+ * output path. A `connection` step's mapping reads its routine's result,
349
+ * in place of its connection's mapping.
350
+ */
351
+ output_mapping?: Record<string, string>
302
352
  }
303
353
 
304
354
  /** Checks every hit through the default waterfall of another enrichment type. */
355
+ export type ValidationKind = 'waterfall' | 'model'
356
+ export type EvaluatorKind = 'decide' | 'reason'
357
+
358
+ /**
359
+ * Checks every hit: through the default waterfall of another enrichment type
360
+ * (`kind` `waterfall`, the default), or by a model judge (`kind` `model`).
361
+ */
305
362
  export interface WaterfallValidation {
306
- enrichment_type: string
363
+ kind?: ValidationKind
364
+ /** The type whose default waterfall checks a hit, for kind `waterfall`. */
365
+ enrichment_type?: string
366
+ /** How the judge runs: a calibrated yes or no (`decide`) or a written verdict (`reason`). */
367
+ evaluator?: { kind: EvaluatorKind; model_id?: string }
368
+ /** What the judge is told about every check. */
369
+ instructions?: string
370
+ /** The parts that are judged, by output path (`value` for a type with one value). */
371
+ checks?: Record<string, ValueCheck>
372
+ /** The record attributes the judge sees; all when empty. */
373
+ context?: string[]
374
+ /** A decide judge accepts at or above this probability (default 0.8). */
375
+ accept_min_probability?: number
376
+ /** A decide judge rejects at or below this probability (default 0.3). */
377
+ reject_max_probability?: number
378
+ }
379
+
380
+ export interface ValueCheck {
381
+ instructions: string
382
+ criteria?: { true: string; false: string }
383
+ }
384
+
385
+ /** A model judge's verdict on one part of a hit. */
386
+ export interface EnrichmentVerification {
387
+ verdict: 'accepted' | 'rejected' | 'unverified'
388
+ probability?: number
389
+ why?: string
390
+ model_id?: string
391
+ value?: unknown
392
+ step_index: number
307
393
  }
308
394
 
309
395
  /**
@@ -351,14 +437,53 @@ export interface PatchWaterfallRequest {
351
437
  }
352
438
 
353
439
  /** One thing that can be asked for. */
440
+ /** A value type of an enrichment type or of one of its paths. */
441
+ export type EnrichmentOutputType = 'string' | 'number' | 'boolean' | 'string_list' | 'object'
442
+
443
+ export interface EnrichmentOutputPath {
444
+ name: string
445
+ type: string
446
+ /** What the path holds, for an org's own type. */
447
+ description?: string
448
+ }
449
+
450
+ export interface EnrichmentOutputSchema {
451
+ type: string
452
+ paths?: EnrichmentOutputPath[]
453
+ }
454
+
455
+ /**
456
+ * One thing enrichment can find. `org_id` `''` is one of the platform's
457
+ * types; any other is the org's own, which only its connection steps fill.
458
+ */
354
459
  export interface EnrichmentType {
355
460
  key: string
461
+ /** The org's own types are named and described; the platform's are not. */
462
+ name?: string
463
+ description?: string
464
+ org_id?: string
356
465
  /** The sets of input keys any one of which is enough. */
357
466
  input_schema: string[][]
358
- output_schema: {
359
- type: string
360
- paths?: Array<{ name: string; type: string }>
361
- }
467
+ output_schema: EnrichmentOutputSchema
468
+ created_at?: string
469
+ updated_at?: string
470
+ }
471
+
472
+ /** Defines one of the org's own types. Its key must not be a platform type's. */
473
+ export interface CreateEnrichmentTypeRequest {
474
+ key: string
475
+ name: string
476
+ description: string
477
+ input_schema: string[][]
478
+ output_schema: EnrichmentOutputSchema
479
+ }
480
+
481
+ /** Changes the members it names. Paths can be added; existing ones keep their name and type. */
482
+ export interface PatchEnrichmentTypeRequest {
483
+ name?: string
484
+ description?: string
485
+ input_schema?: string[][]
486
+ output_schema?: EnrichmentOutputSchema
362
487
  }
363
488
 
364
489
  /** The catalog of enrichment types, with the input keys an entity's attributes can provide. */
@@ -407,6 +532,8 @@ export interface EnrichmentConnectionConfig {
407
532
  * value, or `{ title: 'job.title' }` by output path for a profile.
408
533
  */
409
534
  output_mapping: Record<string, string>
535
+ /** A value the routine always gets, by its input name: `{ country: 'DE' }`. An input is mapped or fixed, not both. */
536
+ fixed_inputs?: Record<string, string>
410
537
  }
411
538
 
412
539
  /**
@@ -442,6 +569,28 @@ export interface PatchEnrichmentConnectionRequest {
442
569
  status?: 'active' | 'inactive'
443
570
  }
444
571
 
572
+ /**
573
+ * Runs a routine once with a config that may not be saved yet, with a value
574
+ * for each input key it maps. Spends one run of the org's own credits.
575
+ */
576
+ export interface TestEnrichmentConnectionRequest {
577
+ connection_id: string
578
+ config: EnrichmentConnectionConfig
579
+ input: Record<string, string>
580
+ }
581
+
582
+ /** One value of a routine's result, by the dotted path an output mapping reads it with. */
583
+ export interface ResultField {
584
+ path: string
585
+ value: unknown
586
+ }
587
+
588
+ /** What the routine returned, as it came and as its non-empty values by path. */
589
+ export interface TestEnrichmentConnectionResponse {
590
+ result: Record<string, unknown>
591
+ fields: ResultField[]
592
+ }
593
+
445
594
  export type ResearchDefinitionStatus = 'active' | 'inactive'
446
595
 
447
596
  /**
package/src/index.ts CHANGED
@@ -753,6 +753,7 @@ export { DiscoveryClient } from './discovery/index.js'
753
753
  export type {
754
754
  CreateEnrichmentConnectionRequest,
755
755
  CreateEnrichmentRunRequest,
756
+ CreateEnrichmentTypeRequest,
756
757
  CreateResearchDefinitionRequest,
757
758
  CreateSignalMonitorRequest,
758
759
  CreateWaterfallRequest,
@@ -775,6 +776,9 @@ export type {
775
776
  EnrichmentMapping,
776
777
  EnrichmentMappingService,
777
778
  EnrichmentOutcome,
779
+ EnrichmentOutputPath,
780
+ EnrichmentOutputSchema,
781
+ EnrichmentOutputType,
778
782
  EnrichmentProvenance,
779
783
  EnrichmentProvider,
780
784
  EnrichmentProviderOffering,
@@ -787,15 +791,20 @@ export type {
787
791
  EnrichmentRunService,
788
792
  EnrichmentRunStatus,
789
793
  EnrichmentRunTrigger,
794
+ EnrichmentTransform,
790
795
  EnrichmentTrigger,
791
796
  EnrichmentType,
792
797
  EnrichmentTypesResponse,
798
+ EnrichmentValueMapping,
799
+ EnrichmentVerification,
793
800
  EnrichRequest,
794
801
  EnrichResponse,
802
+ EvaluatorKind,
795
803
  ListEnrichmentRunsQuery,
796
804
  ListResearchRunsQuery,
797
805
  ListSignalsQuery,
798
806
  PatchEnrichmentConnectionRequest,
807
+ PatchEnrichmentTypeRequest,
799
808
  PatchResearchDefinitionRequest,
800
809
  PatchSignalMonitorRequest,
801
810
  PatchWaterfallRequest,
@@ -816,6 +825,7 @@ export type {
816
825
  ResearchService,
817
826
  ResearchSource,
818
827
  ResearchUpdatePolicy,
828
+ ResultField,
819
829
  Signal,
820
830
  SignalCreateEffect,
821
831
  SignalEffects,
@@ -831,6 +841,10 @@ export type {
831
841
  SignalService,
832
842
  SignalUpdateEffect,
833
843
  SignalUpdatePolicy,
844
+ TestEnrichmentConnectionRequest,
845
+ TestEnrichmentConnectionResponse,
846
+ ValidationKind,
847
+ ValueCheck,
834
848
  Waterfall,
835
849
  WaterfallService,
836
850
  WaterfallStatus,
@@ -1300,6 +1314,19 @@ export {
1300
1314
  resolveOptions,
1301
1315
  UserRefSchema,
1302
1316
  } from './types/index.js'
1317
+ // Usage types (usage-service: the metering ledger and the org's usage limits)
1318
+ export type {
1319
+ EffectiveUsageLimit,
1320
+ Meter,
1321
+ MeterAggregation,
1322
+ MeterUnit,
1323
+ UsageLimit,
1324
+ UsageLimitPeriod,
1325
+ UsageLimitSource,
1326
+ UsageSummaryQuery,
1327
+ UsageSummaryRow,
1328
+ } from './usage/index.js'
1329
+ export { UsageClient } from './usage/index.js'
1303
1330
  export type {
1304
1331
  AgentActionParams,
1305
1332
  BinaryRef,
@@ -0,0 +1,49 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import type { EffectiveUsageLimit, Meter, UsageSummaryQuery, UsageSummaryRow } from './types.js'
3
+
4
+ export * from './types.js'
5
+
6
+ const USAGE_BASE_PATH = '/usage/v1'
7
+
8
+ /**
9
+ * Facade for usage-service: the metering ledger (read-only) and the org's
10
+ * usage limits. Quantities only, never money.
11
+ *
12
+ * ```ts
13
+ * const usage = new UsageClient(client)
14
+ * const meters = await usage.meters()
15
+ * const rows = await usage.summary({ from, to, group_by: 'day' })
16
+ * const limits = await usage.limits()
17
+ * ```
18
+ */
19
+ export class UsageClient {
20
+ constructor(private readonly client: ProteosClient) {}
21
+
22
+ /** The meter catalogue. */
23
+ async meters(): Promise<Meter[]> {
24
+ const response = await this.client.request<{ data: Meter[] }>(
25
+ 'GET',
26
+ `${USAGE_BASE_PATH}/meters`,
27
+ )
28
+ return response.data
29
+ }
30
+
31
+ /** Totals per meter over a period: sum meters from the ledger, latest meters from snapshots. */
32
+ async summary(query: UsageSummaryQuery): Promise<UsageSummaryRow[]> {
33
+ const response = await this.client.requestWithQuery<{ data: UsageSummaryRow[] }>(
34
+ 'GET',
35
+ `${USAGE_BASE_PATH}/summary`,
36
+ query,
37
+ )
38
+ return response.data
39
+ }
40
+
41
+ /** The org's limits active now, with their usage in the current window. */
42
+ async limits(): Promise<EffectiveUsageLimit[]> {
43
+ const response = await this.client.request<{ data: EffectiveUsageLimit[] }>(
44
+ 'GET',
45
+ `${USAGE_BASE_PATH}/limits`,
46
+ )
47
+ return response.data
48
+ }
49
+ }
@@ -0,0 +1,93 @@
1
+ import type { UserRef } from '../types/index.js'
2
+
3
+ /** How a meter's records combine over a period: summed, or a daily level. */
4
+ export type MeterAggregation = 'sum' | 'latest'
5
+
6
+ /** Raw base unit of a meter's quantity. */
7
+ export type MeterUnit = 'count' | 'seconds' | 'bytes' | 'tokens'
8
+
9
+ /** One metered quantity from the catalogue (`GET /usage/v1/meters`). */
10
+ export interface Meter {
11
+ key: string
12
+ aggregation: MeterAggregation
13
+ unit: MeterUnit
14
+ /** Dimension keys a record of this meter may carry. */
15
+ dimensions: string[]
16
+ description: string
17
+ }
18
+
19
+ /** One group of a usage summary. Fields of groups not asked for are absent. */
20
+ export interface UsageSummaryRow {
21
+ meter_key: string
22
+ aggregation: MeterAggregation
23
+ unit: MeterUnit
24
+ actor?: UserRef
25
+ on_behalf_of?: UserRef
26
+ /** Start of the UTC day or month bucket, with `group_by` day or month. */
27
+ period_start?: string
28
+ dimensions?: Record<string, string>
29
+ /** Sum meters: the sum. Latest meters: the level on the last measured day. */
30
+ quantity: number
31
+ record_count?: number
32
+ average?: number
33
+ max?: number
34
+ day_count?: number
35
+ }
36
+
37
+ /**
38
+ * A usage summary over `[from, to)` (ISO timestamps, at most 366 days).
39
+ * `group_by` is a comma-separated list of actor, on_behalf_of, day or month,
40
+ * and dimension:<key>; `meter` a comma-separated list of meter keys.
41
+ */
42
+ export interface UsageSummaryQuery {
43
+ from: string
44
+ to: string
45
+ meter?: string
46
+ group_by?: string
47
+ actor?: string
48
+ }
49
+
50
+ export type UsageLimitPeriod =
51
+ | 'rolling_1h'
52
+ | 'rolling_24h'
53
+ | 'day'
54
+ | 'month'
55
+ | 'quarter'
56
+ | 'year'
57
+ | 'none'
58
+
59
+ export interface UsageLimitSource {
60
+ /** base (from code, every org), manual (platform staff), later module, credit_pack. */
61
+ type: string
62
+ id?: string
63
+ }
64
+
65
+ /** One stored or base contribution to a limit. */
66
+ export interface UsageLimit {
67
+ id: string
68
+ org_id?: string
69
+ applies_to?: UserRef
70
+ meter_key: string
71
+ dimensions: Record<string, string>
72
+ period: UsageLimitPeriod
73
+ quantity: number
74
+ source: UsageLimitSource
75
+ valid_from?: string
76
+ valid_until?: string
77
+ }
78
+
79
+ /** An org's limit for one (meter, dimensions, period), measured now. */
80
+ export interface EffectiveUsageLimit {
81
+ applies_to?: UserRef
82
+ meter_key: string
83
+ aggregation: MeterAggregation
84
+ unit: MeterUnit
85
+ dimensions: Record<string, string>
86
+ period: UsageLimitPeriod
87
+ /** Start of the current window; absent for period none. */
88
+ window_start?: string
89
+ limit: number
90
+ used: number
91
+ remaining: number
92
+ contributions: UsageLimit[]
93
+ }