@secondlayer/shared 11.19.3 → 11.21.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/dist/src/archive/range-digest.d.ts +61 -1
- package/dist/src/archive/semantic-digest-builder.d.ts +61 -1
- package/dist/src/classify/index.d.ts +83 -0
- package/dist/src/classify/index.js +464 -0
- package/dist/src/classify/index.js.map +18 -0
- package/dist/src/coverage/index.d.ts +61 -1
- package/dist/src/db/index.d.ts +72 -2
- package/dist/src/db/index.js +5 -1
- package/dist/src/db/index.js.map +3 -3
- package/dist/src/db/queries/chain-reorgs.d.ts +61 -1
- package/dist/src/db/queries/chain-reorgs.js +5 -1
- package/dist/src/db/queries/chain-reorgs.js.map +3 -3
- package/dist/src/db/queries/contracts.d.ts +61 -1
- package/dist/src/db/queries/instance.d.ts +61 -1
- package/dist/src/db/queries/integrity.d.ts +61 -1
- package/dist/src/db/queries/subgraph-gaps.d.ts +61 -1
- package/dist/src/db/queries/subgraph-operations.d.ts +61 -1
- package/dist/src/db/queries/subgraphs.d.ts +61 -1
- package/dist/src/db/queries/sync-scope.d.ts +61 -1
- package/dist/src/db/queries/webhooks.d.ts +61 -1
- package/dist/src/db/schema.d.ts +68 -2
- package/dist/src/error-envelope.d.ts +48 -0
- package/dist/src/error-envelope.js +76 -0
- package/dist/src/error-envelope.js.map +10 -0
- package/dist/src/index.d.ts +72 -2
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +3 -3
- package/dist/src/leader.d.ts +4 -1
- package/dist/src/leader.js +3 -1
- package/dist/src/leader.js.map +3 -3
- package/dist/src/node/local-client.d.ts +71 -2
- package/dist/src/node/local-client.js +4 -2
- package/dist/src/node/local-client.js.map +3 -3
- package/dist/src/queue/listener.js +5 -1
- package/dist/src/queue/listener.js.map +3 -3
- package/dist/src/types.d.ts +0 -1
- package/migrations/0153_vm_events_height_ordinal_pk.ts +80 -0
- package/migrations/0154_state_writes.ts +62 -0
- package/migrations/0155_api_failed_requests.ts +37 -0
- package/migrations/0156_feedback_tickets.ts +47 -0
- package/package.json +17 -1
|
@@ -87,7 +87,6 @@ interface EventsArchiveTable {
|
|
|
87
87
|
archived_at: Generated<Date>;
|
|
88
88
|
}
|
|
89
89
|
interface VmEventsTable {
|
|
90
|
-
id: Generated<string>;
|
|
91
90
|
tx_id: string;
|
|
92
91
|
block_height: number;
|
|
93
92
|
ordinal: number;
|
|
@@ -97,6 +96,7 @@ interface VmEventsTable {
|
|
|
97
96
|
}
|
|
98
97
|
interface VmEventsArchiveTable {
|
|
99
98
|
archive_id: Generated<string>;
|
|
99
|
+
/** `block_height:ordinal`; rows archived before migration 0153 hold the old uuid. */
|
|
100
100
|
id: string;
|
|
101
101
|
tx_id: string;
|
|
102
102
|
block_height: number;
|
|
@@ -107,6 +107,25 @@ interface VmEventsArchiveTable {
|
|
|
107
107
|
orphaned_block_hash: string | null;
|
|
108
108
|
archived_at: Generated<Date>;
|
|
109
109
|
}
|
|
110
|
+
interface StateWritesTable {
|
|
111
|
+
block_height: number;
|
|
112
|
+
ordinal: number;
|
|
113
|
+
tx_index: number | null;
|
|
114
|
+
key: string;
|
|
115
|
+
value_hex: string;
|
|
116
|
+
}
|
|
117
|
+
interface StateWritesArchiveTable {
|
|
118
|
+
archive_id: Generated<string>;
|
|
119
|
+
/** `block_height:ordinal`. */
|
|
120
|
+
id: string;
|
|
121
|
+
block_height: number;
|
|
122
|
+
ordinal: number;
|
|
123
|
+
tx_index: number | null;
|
|
124
|
+
key: string;
|
|
125
|
+
value_hex: string;
|
|
126
|
+
orphaned_block_hash: string | null;
|
|
127
|
+
archived_at: Generated<Date>;
|
|
128
|
+
}
|
|
110
129
|
interface DeadLetterEventsTable {
|
|
111
130
|
id: Generated<string>;
|
|
112
131
|
block_height: number;
|
|
@@ -768,9 +787,11 @@ interface Database {
|
|
|
768
787
|
transactions: TransactionsTable;
|
|
769
788
|
events: EventsTable;
|
|
770
789
|
vm_events: VmEventsTable;
|
|
790
|
+
state_writes: StateWritesTable;
|
|
771
791
|
transactions_archive: TransactionsArchiveTable;
|
|
772
792
|
events_archive: EventsArchiveTable;
|
|
773
793
|
vm_events_archive: VmEventsArchiveTable;
|
|
794
|
+
state_writes_archive: StateWritesArchiveTable;
|
|
774
795
|
dead_letter_events: DeadLetterEventsTable;
|
|
775
796
|
mempool_transactions: MempoolTransactionsTable;
|
|
776
797
|
index_progress: IndexProgressTable;
|
|
@@ -826,6 +847,8 @@ interface Database {
|
|
|
826
847
|
sentinel_accounts: SentinelAccountsTable;
|
|
827
848
|
waitlists: WaitlistsTable;
|
|
828
849
|
waitlist_signups: WaitlistSignupsTable;
|
|
850
|
+
api_failed_requests: ApiFailedRequestsTable;
|
|
851
|
+
feedback_tickets: FeedbackTicketsTable;
|
|
829
852
|
}
|
|
830
853
|
interface ServiceHeartbeatsTable {
|
|
831
854
|
name: string;
|
|
@@ -1034,6 +1057,43 @@ interface WaitlistSignupsTable {
|
|
|
1034
1057
|
created_at: Generated<Date>;
|
|
1035
1058
|
}
|
|
1036
1059
|
/**
|
|
1060
|
+
* 24h hosted record of a failed API request, keyed by `request_id` and
|
|
1061
|
+
* scoped to the account that made it. `query` is redacted before insert.
|
|
1062
|
+
*/
|
|
1063
|
+
interface ApiFailedRequestsTable {
|
|
1064
|
+
request_id: string;
|
|
1065
|
+
account_id: string;
|
|
1066
|
+
method: string;
|
|
1067
|
+
path: string;
|
|
1068
|
+
status: number;
|
|
1069
|
+
code: string;
|
|
1070
|
+
message: Generated<string>;
|
|
1071
|
+
query: Record<string, unknown>;
|
|
1072
|
+
origin: string | null;
|
|
1073
|
+
created_at: Generated<Date>;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Hosted problem report. `attempted` is the server's own copy of the failed
|
|
1077
|
+
* request (never caller-supplied); `status` starts `new` until classified.
|
|
1078
|
+
*/
|
|
1079
|
+
interface FeedbackTicketsTable {
|
|
1080
|
+
id: Generated<string>;
|
|
1081
|
+
account_id: string;
|
|
1082
|
+
idempotency_key: string | null;
|
|
1083
|
+
request_id: string | null;
|
|
1084
|
+
intent: string;
|
|
1085
|
+
expected: Record<string, unknown> | null;
|
|
1086
|
+
kind_hint: string | null;
|
|
1087
|
+
evidence: Record<string, unknown> | null;
|
|
1088
|
+
attempted: Record<string, unknown> | null;
|
|
1089
|
+
origin: string;
|
|
1090
|
+
status: Generated<"new" | "classified">;
|
|
1091
|
+
route: string | null;
|
|
1092
|
+
classification: Record<string, unknown> | null;
|
|
1093
|
+
classified_at: Date | null;
|
|
1094
|
+
created_at: Generated<Date>;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1037
1097
|
* Cheap, SQL-computed digests over a height range — the basis of a verify that
|
|
1038
1098
|
* runs in seconds instead of hours.
|
|
1039
1099
|
*
|
|
@@ -87,7 +87,6 @@ interface EventsArchiveTable {
|
|
|
87
87
|
archived_at: Generated<Date>;
|
|
88
88
|
}
|
|
89
89
|
interface VmEventsTable {
|
|
90
|
-
id: Generated<string>;
|
|
91
90
|
tx_id: string;
|
|
92
91
|
block_height: number;
|
|
93
92
|
ordinal: number;
|
|
@@ -97,6 +96,7 @@ interface VmEventsTable {
|
|
|
97
96
|
}
|
|
98
97
|
interface VmEventsArchiveTable {
|
|
99
98
|
archive_id: Generated<string>;
|
|
99
|
+
/** `block_height:ordinal`; rows archived before migration 0153 hold the old uuid. */
|
|
100
100
|
id: string;
|
|
101
101
|
tx_id: string;
|
|
102
102
|
block_height: number;
|
|
@@ -107,6 +107,25 @@ interface VmEventsArchiveTable {
|
|
|
107
107
|
orphaned_block_hash: string | null;
|
|
108
108
|
archived_at: Generated<Date>;
|
|
109
109
|
}
|
|
110
|
+
interface StateWritesTable {
|
|
111
|
+
block_height: number;
|
|
112
|
+
ordinal: number;
|
|
113
|
+
tx_index: number | null;
|
|
114
|
+
key: string;
|
|
115
|
+
value_hex: string;
|
|
116
|
+
}
|
|
117
|
+
interface StateWritesArchiveTable {
|
|
118
|
+
archive_id: Generated<string>;
|
|
119
|
+
/** `block_height:ordinal`. */
|
|
120
|
+
id: string;
|
|
121
|
+
block_height: number;
|
|
122
|
+
ordinal: number;
|
|
123
|
+
tx_index: number | null;
|
|
124
|
+
key: string;
|
|
125
|
+
value_hex: string;
|
|
126
|
+
orphaned_block_hash: string | null;
|
|
127
|
+
archived_at: Generated<Date>;
|
|
128
|
+
}
|
|
110
129
|
interface DeadLetterEventsTable {
|
|
111
130
|
id: Generated<string>;
|
|
112
131
|
block_height: number;
|
|
@@ -768,9 +787,11 @@ interface Database {
|
|
|
768
787
|
transactions: TransactionsTable;
|
|
769
788
|
events: EventsTable;
|
|
770
789
|
vm_events: VmEventsTable;
|
|
790
|
+
state_writes: StateWritesTable;
|
|
771
791
|
transactions_archive: TransactionsArchiveTable;
|
|
772
792
|
events_archive: EventsArchiveTable;
|
|
773
793
|
vm_events_archive: VmEventsArchiveTable;
|
|
794
|
+
state_writes_archive: StateWritesArchiveTable;
|
|
774
795
|
dead_letter_events: DeadLetterEventsTable;
|
|
775
796
|
mempool_transactions: MempoolTransactionsTable;
|
|
776
797
|
index_progress: IndexProgressTable;
|
|
@@ -826,6 +847,8 @@ interface Database {
|
|
|
826
847
|
sentinel_accounts: SentinelAccountsTable;
|
|
827
848
|
waitlists: WaitlistsTable;
|
|
828
849
|
waitlist_signups: WaitlistSignupsTable;
|
|
850
|
+
api_failed_requests: ApiFailedRequestsTable;
|
|
851
|
+
feedback_tickets: FeedbackTicketsTable;
|
|
829
852
|
}
|
|
830
853
|
interface ServiceHeartbeatsTable {
|
|
831
854
|
name: string;
|
|
@@ -1034,6 +1057,43 @@ interface WaitlistSignupsTable {
|
|
|
1034
1057
|
created_at: Generated<Date>;
|
|
1035
1058
|
}
|
|
1036
1059
|
/**
|
|
1060
|
+
* 24h hosted record of a failed API request, keyed by `request_id` and
|
|
1061
|
+
* scoped to the account that made it. `query` is redacted before insert.
|
|
1062
|
+
*/
|
|
1063
|
+
interface ApiFailedRequestsTable {
|
|
1064
|
+
request_id: string;
|
|
1065
|
+
account_id: string;
|
|
1066
|
+
method: string;
|
|
1067
|
+
path: string;
|
|
1068
|
+
status: number;
|
|
1069
|
+
code: string;
|
|
1070
|
+
message: Generated<string>;
|
|
1071
|
+
query: Record<string, unknown>;
|
|
1072
|
+
origin: string | null;
|
|
1073
|
+
created_at: Generated<Date>;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Hosted problem report. `attempted` is the server's own copy of the failed
|
|
1077
|
+
* request (never caller-supplied); `status` starts `new` until classified.
|
|
1078
|
+
*/
|
|
1079
|
+
interface FeedbackTicketsTable {
|
|
1080
|
+
id: Generated<string>;
|
|
1081
|
+
account_id: string;
|
|
1082
|
+
idempotency_key: string | null;
|
|
1083
|
+
request_id: string | null;
|
|
1084
|
+
intent: string;
|
|
1085
|
+
expected: Record<string, unknown> | null;
|
|
1086
|
+
kind_hint: string | null;
|
|
1087
|
+
evidence: Record<string, unknown> | null;
|
|
1088
|
+
attempted: Record<string, unknown> | null;
|
|
1089
|
+
origin: string;
|
|
1090
|
+
status: Generated<"new" | "classified">;
|
|
1091
|
+
route: string | null;
|
|
1092
|
+
classification: Record<string, unknown> | null;
|
|
1093
|
+
classified_at: Date | null;
|
|
1094
|
+
created_at: Generated<Date>;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1037
1097
|
* v1 canonical byte encoding for chain identity — the shape that lets
|
|
1038
1098
|
* independently-run runtimes agree on the same block.
|
|
1039
1099
|
*
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
type ClassifierName = "jev" | "kev" | "clef" | "rules";
|
|
2
|
+
type Question = {
|
|
3
|
+
type: "choice"
|
|
4
|
+
instructions: string
|
|
5
|
+
criteria: Record<string, string>
|
|
6
|
+
} | {
|
|
7
|
+
type: "score"
|
|
8
|
+
instructions: string
|
|
9
|
+
criteria: readonly string[]
|
|
10
|
+
} | {
|
|
11
|
+
type: "boolean"
|
|
12
|
+
instructions: string
|
|
13
|
+
criteria: {
|
|
14
|
+
true: string
|
|
15
|
+
false: string
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
type Answer = {
|
|
19
|
+
type: "choice"
|
|
20
|
+
choice: string
|
|
21
|
+
probabilities: Record<string, number>
|
|
22
|
+
confidence: number
|
|
23
|
+
} | {
|
|
24
|
+
type: "score"
|
|
25
|
+
score: number
|
|
26
|
+
probabilities: Record<string, number>
|
|
27
|
+
confidence: number
|
|
28
|
+
} | {
|
|
29
|
+
type: "boolean"
|
|
30
|
+
probability: number
|
|
31
|
+
confidence: number
|
|
32
|
+
} | {
|
|
33
|
+
type: "refusal"
|
|
34
|
+
};
|
|
35
|
+
type Answers<Q extends Record<string, Question>> = { [K in keyof Q] : Answer };
|
|
36
|
+
type ClassifyResult<Q extends Record<string, Question>> = {
|
|
37
|
+
provider: ClassifierName
|
|
38
|
+
/** response.modelId when the backend reports one. */
|
|
39
|
+
modelId: string
|
|
40
|
+
answers: Answers<Q>
|
|
41
|
+
};
|
|
42
|
+
/** Deterministic answers for the offline provider. Return a value per question
|
|
43
|
+
* it can decide; omitted questions come back as `{ type: "refusal" }`. */
|
|
44
|
+
type RuleValue = string | number | boolean;
|
|
45
|
+
type RulesFn<Q extends Record<string, Question>> = (state: string | Record<string, unknown>) => { [K in keyof Q]? : RuleValue } | null;
|
|
46
|
+
declare class ClassifierInputError extends Error {
|
|
47
|
+
constructor(message: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One classifier call over jev, kev, clef or offline rules.
|
|
51
|
+
* Returns null on any provider failure (fail-open: callers decide what null
|
|
52
|
+
* means). Only ClassifierInputError, a bad question definition, escapes.
|
|
53
|
+
* Never logs state or response bodies.
|
|
54
|
+
*/
|
|
55
|
+
declare function classify<const Q extends Record<string, Question>>(input: {
|
|
56
|
+
state: string | Record<string, unknown>
|
|
57
|
+
questions: Q
|
|
58
|
+
rules?: RulesFn<Q>
|
|
59
|
+
/** Overrides resolveProvider(); used by classifier-compare. */
|
|
60
|
+
provider?: ClassifierName
|
|
61
|
+
/** Overrides CLASSIFIER_MODEL / the provider default. */
|
|
62
|
+
modelId?: string
|
|
63
|
+
/** Default 5000. */
|
|
64
|
+
timeoutMs?: number
|
|
65
|
+
env?: Record<string, string | undefined>
|
|
66
|
+
/** Tests only (kev/clef). */
|
|
67
|
+
fetchImpl?: typeof fetch
|
|
68
|
+
}): Promise<ClassifyResult<Q> | null>;
|
|
69
|
+
type Env = Record<string, string | undefined>;
|
|
70
|
+
/** CLASSIFIER picks the backend; unset means jev when the gateway key is set,
|
|
71
|
+
* else offline rules. A backend missing credentials falls back to rules. */
|
|
72
|
+
declare function resolveProvider(env?: Env): {
|
|
73
|
+
name: ClassifierName
|
|
74
|
+
modelId: string
|
|
75
|
+
};
|
|
76
|
+
/** (p_max - 1/K) / (1 - 1/K). One option gives 1. */
|
|
77
|
+
declare function choiceConfidence(probabilities: Record<string, number>): number;
|
|
78
|
+
/** max(0, 1 - E|level - mode| / D); D = mean distance of a uniform
|
|
79
|
+
* distribution over the levels from the middle level. */
|
|
80
|
+
declare function scoreConfidence(probabilities: Record<string, number>, levels: number): number;
|
|
81
|
+
/** Host-defined: |2p - 1|. Not comparable with choice/score confidence. */
|
|
82
|
+
declare function booleanConfidence(p: number): number;
|
|
83
|
+
export { Answer, Answers, ClassifierInputError, ClassifierName, ClassifyResult, Question, RuleValue, RulesFn, booleanConfidence, choiceConfidence, classify, resolveProvider, scoreConfidence };
|