pi-radar 0.3.0 → 0.4.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/README.md +4 -2
- package/dist/extension/baseline.js +227 -402
- package/dist/extension/radar-client.js +53 -13
- package/dist/extension/radar-communication.js +5 -5
- package/dist/extension/radar-execution.js +168 -383
- package/dist/extension/radar-launch.js +13 -13
- package/dist/extension/radar-publication.js +160 -299
- package/dist/index.js +239 -414
- package/extension/generated-contracts.ts +1249 -13
- package/extension/radar-client.ts +92 -29
- package/extension/radar-communication.ts +5 -5
- package/extension/radar-execution.ts +11 -58
- package/extension/radar-launch.ts +21 -21
- package/extension/radar-publication.ts +209 -412
- package/package.json +3 -4
- package/schema/public/v1/handoff-publish-params.deserialize.schema.json +2 -2
- package/schema/public/v1/handoff-publish-params.serialize.schema.json +2 -2
- package/schema/public/v1/handoff-receipt.deserialize.schema.json +4 -4
- package/schema/public/v1/handoff-receipt.serialize.schema.json +4 -4
- package/schema/public/v1/handoff.deserialize.schema.json +4 -4
- package/schema/public/v1/handoff.serialize.schema.json +4 -4
- package/schema/public/v1/observation-get-params.deserialize.schema.json +46 -0
- package/schema/public/v1/observation-get-params.serialize.schema.json +52 -0
- package/schema/public/v1/observation-get-response.deserialize.schema.json +2731 -0
- package/schema/public/v1/observation-get-response.serialize.schema.json +2862 -0
- package/schema/public/v1/observation-snapshot.deserialize.schema.json +2616 -0
- package/schema/public/v1/observation-snapshot.serialize.schema.json +2741 -0
- package/schema/public/v1/presence-answer.deserialize.schema.json +40 -0
- package/schema/public/v1/presence-answer.serialize.schema.json +40 -0
- package/schema/public/v1/presence-release.deserialize.schema.json +51 -0
- package/schema/public/v1/presence-release.serialize.schema.json +52 -0
- package/schema/public/v1/presence-report.deserialize.schema.json +149 -0
- package/schema/public/v1/presence-report.serialize.schema.json +157 -0
- package/extension/radar-session-marker.ts +0 -146
- package/schema/public/v1/launch-identity-marker.deserialize.schema.json +0 -32
- package/schema/public/v1/launch-identity-marker.serialize.schema.json +0 -32
|
@@ -109,6 +109,25 @@ function recordAt(value, field) {
|
|
|
109
109
|
function isUuid(value) {
|
|
110
110
|
return typeof value === "string" && UUID.test(value);
|
|
111
111
|
}
|
|
112
|
+
function decodePresenceAnswer(value) {
|
|
113
|
+
const registrationId = recordAt(value, "registration_id");
|
|
114
|
+
const claimId = recordAt(value, "claim_id");
|
|
115
|
+
const standing = recordAt(value, "standing");
|
|
116
|
+
const subjectId = recordAt(value, "subject_id");
|
|
117
|
+
if (!isUuid(registrationId) || !isUuid(claimId) || !["pending", "granted", "duplicate", "released"].includes(String(standing)) || subjectId !== void 0 && !isUuid(subjectId) || standing === "granted" && !isUuid(subjectId))
|
|
118
|
+
return protocol("presence reply carries no valid claim standing");
|
|
119
|
+
return { ok: true, value };
|
|
120
|
+
}
|
|
121
|
+
function managementAt(value) {
|
|
122
|
+
const field = recordAt(value, "management");
|
|
123
|
+
const state = stringAt(field, "state");
|
|
124
|
+
if (state === "managed") {
|
|
125
|
+
const subjectId = stringAt(field, "subject_id");
|
|
126
|
+
return subjectId === void 0 ? void 0 : { state, subject_id: subjectId };
|
|
127
|
+
}
|
|
128
|
+
if (state === "duplicate" || state === "pending" || state === "unmanaged") return { state };
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
112
131
|
function stringAt(value, field) {
|
|
113
132
|
if (typeof value !== "object" || value === null) return void 0;
|
|
114
133
|
const found = value[field];
|
|
@@ -129,7 +148,7 @@ function handoffAt(value) {
|
|
|
129
148
|
const content = stringAt(value, "content");
|
|
130
149
|
const published = numberAt(value, "published_at_unix_ms");
|
|
131
150
|
const correlation = typeof value === "object" && value !== null ? value.correlation_id : void 0;
|
|
132
|
-
if (version !== 1 || !isUuid(id) || !isUuid(stringAt(sender, "
|
|
151
|
+
if (version !== 1 || !isUuid(id) || !isUuid(stringAt(sender, "registration_id")) || !isUuid(stringAt(sender, "session_id")) || !isUuid(stringAt(sender, "subject_id")) || !isUuid(stringAt(sender, "execution_id")) || !Number.isSafeInteger(senderGeneration) || (senderGeneration ?? 0) < 1 || !isUuid(target) || summary === void 0 || content === void 0 || published === void 0 || !Number.isSafeInteger(published) || published < 0 || correlation !== void 0 && correlation !== null && (typeof correlation !== "string" || correlation.length === 0 || Buffer.byteLength(correlation, "utf8") > 256 || new RegExp("\\p{Cc}", "u").test(correlation))) return void 0;
|
|
133
152
|
return value;
|
|
134
153
|
}
|
|
135
154
|
function handoffReceiptAt(value) {
|
|
@@ -138,7 +157,7 @@ function handoffReceiptAt(value) {
|
|
|
138
157
|
const recipient = recordAt(value, "recipient");
|
|
139
158
|
const generation = numberAt(recipient, "execution_generation");
|
|
140
159
|
const received = numberAt(value, "received_at_unix_ms");
|
|
141
|
-
if (version !== 1 || !isUuid(handoffId) || !isUuid(stringAt(recipient, "
|
|
160
|
+
if (version !== 1 || !isUuid(handoffId) || !isUuid(stringAt(recipient, "registration_id")) || !isUuid(stringAt(recipient, "session_id")) || !isUuid(stringAt(recipient, "subject_id")) || !isUuid(stringAt(recipient, "execution_id")) || !Number.isSafeInteger(generation) || (generation ?? 0) < 1 || received === void 0 || !Number.isSafeInteger(received) || received < 0) return void 0;
|
|
142
161
|
return value;
|
|
143
162
|
}
|
|
144
163
|
function writerBinding(value) {
|
|
@@ -296,7 +315,7 @@ function spawnEdge(value) {
|
|
|
296
315
|
const bound = recordAt(value, "bound");
|
|
297
316
|
const source = stringAt(bound, "source");
|
|
298
317
|
const incarnation = stringAt(bound, "incarnation");
|
|
299
|
-
const agentId = stringAt(bound, "
|
|
318
|
+
const agentId = stringAt(bound, "registration_id");
|
|
300
319
|
const exit = exitAt(recordAt(value, "exit_observation"));
|
|
301
320
|
return {
|
|
302
321
|
ok: true,
|
|
@@ -310,7 +329,7 @@ function spawnEdge(value) {
|
|
|
310
329
|
bound: {
|
|
311
330
|
source,
|
|
312
331
|
incarnation,
|
|
313
|
-
...isUuid(agentId) ? {
|
|
332
|
+
...isUuid(agentId) ? { registration_id: agentId } : {}
|
|
314
333
|
}
|
|
315
334
|
} : {},
|
|
316
335
|
...exit !== void 0 ? { exit_observation: exit } : {}
|
|
@@ -708,6 +727,22 @@ function createRadarClient(options = {}) {
|
|
|
708
727
|
return {
|
|
709
728
|
socketPath,
|
|
710
729
|
ping,
|
|
730
|
+
async presence(request) {
|
|
731
|
+
return withRegistry(async () => {
|
|
732
|
+
const answer = await call("agent.presence", { ...request });
|
|
733
|
+
if (!answer.ok) return answer;
|
|
734
|
+
return decodePresenceAnswer(answer.value);
|
|
735
|
+
});
|
|
736
|
+
},
|
|
737
|
+
async releasePresence(request) {
|
|
738
|
+
return withRegistry(async () => {
|
|
739
|
+
const answer = await call("agent.release", { ...request });
|
|
740
|
+
if (!answer.ok) return answer;
|
|
741
|
+
const decoded = decodePresenceAnswer(answer.value);
|
|
742
|
+
if (!decoded.ok) return decoded;
|
|
743
|
+
return decoded.value.standing === "released" ? decoded : protocol("release reply did not confirm the claim release");
|
|
744
|
+
});
|
|
745
|
+
},
|
|
711
746
|
async register(registration) {
|
|
712
747
|
return withRegistry(async () => {
|
|
713
748
|
const answer = await call("agent.register", {
|
|
@@ -723,15 +758,15 @@ function createRadarClient(options = {}) {
|
|
|
723
758
|
});
|
|
724
759
|
if (answer.ok === false) return answer;
|
|
725
760
|
const record = answer.value.registration;
|
|
726
|
-
const agentId = stringAt(record, "
|
|
727
|
-
if (!isUuid(agentId)) return protocol("registration reply carries no
|
|
728
|
-
return { ok: true, value: {
|
|
761
|
+
const agentId = stringAt(record, "registration_id");
|
|
762
|
+
if (!isUuid(agentId)) return protocol("registration reply carries no registration_id");
|
|
763
|
+
return { ok: true, value: { registration_id: agentId } };
|
|
729
764
|
});
|
|
730
765
|
},
|
|
731
766
|
async acquire(request) {
|
|
732
767
|
return withRegistryChannel(request.channel, async () => {
|
|
733
768
|
const answer = await call("agent.acquire", {
|
|
734
|
-
|
|
769
|
+
registration_id: request.registration_id,
|
|
735
770
|
channel: request.channel,
|
|
736
771
|
publisher: request.publisher,
|
|
737
772
|
...request.replace !== void 0 ? { replace: request.replace } : {}
|
|
@@ -760,7 +795,7 @@ function createRadarClient(options = {}) {
|
|
|
760
795
|
}
|
|
761
796
|
return withRegistryChannel(request.channel, async () => {
|
|
762
797
|
const answer = await call("agent.publish", {
|
|
763
|
-
|
|
798
|
+
registration_id: request.registration_id,
|
|
764
799
|
channel: request.channel,
|
|
765
800
|
writer_handle: request.writer_handle,
|
|
766
801
|
sequence: request.sequence,
|
|
@@ -779,7 +814,7 @@ function createRadarClient(options = {}) {
|
|
|
779
814
|
async context(request) {
|
|
780
815
|
return withRegistry(async () => {
|
|
781
816
|
const answer = await call("agent.context", {
|
|
782
|
-
|
|
817
|
+
registration_id: request.registration_id,
|
|
783
818
|
publisher: request.publisher,
|
|
784
819
|
...request.writer_handle !== void 0 ? { writer_handle: request.writer_handle } : {},
|
|
785
820
|
...request.replace !== void 0 ? { replace: request.replace } : {},
|
|
@@ -795,9 +830,14 @@ function createRadarClient(options = {}) {
|
|
|
795
830
|
if (writer === void 0)
|
|
796
831
|
return protocol("context reply carries no writer binding");
|
|
797
832
|
const warning = stringAt(answer.value, "warning");
|
|
833
|
+
const management = managementAt(answer.value);
|
|
798
834
|
return {
|
|
799
835
|
ok: true,
|
|
800
|
-
value: {
|
|
836
|
+
value: {
|
|
837
|
+
writer,
|
|
838
|
+
...warning !== void 0 ? { warning } : {},
|
|
839
|
+
...management !== void 0 ? { management } : {}
|
|
840
|
+
}
|
|
801
841
|
};
|
|
802
842
|
});
|
|
803
843
|
},
|
|
@@ -874,7 +914,7 @@ function createRadarClient(options = {}) {
|
|
|
874
914
|
message: "agent.get requires a canonical agent UUID"
|
|
875
915
|
};
|
|
876
916
|
return withRegistry(async () => {
|
|
877
|
-
const answer = await call("agent.get", {
|
|
917
|
+
const answer = await call("agent.get", { registration_id: agentId });
|
|
878
918
|
if (answer.ok === false) return answer;
|
|
879
919
|
return agentProcessAt(recordAt(answer.value, "agent"));
|
|
880
920
|
});
|
|
@@ -928,7 +968,7 @@ function createRadarClient(options = {}) {
|
|
|
928
968
|
async communicationPublish(request) {
|
|
929
969
|
return withContract(RADAR_COMMUNICATION_CONTRACT, async () => {
|
|
930
970
|
const answer = await call("communication.publish", {
|
|
931
|
-
|
|
971
|
+
sender_registration_id: request.sender_registration_id,
|
|
932
972
|
recipient_subject_id: request.recipient_subject_id,
|
|
933
973
|
...request.correlation_id !== void 0 ? { correlation_id: request.correlation_id } : {},
|
|
934
974
|
summary: request.summary,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function createRadarHandoffPort(client, publication, parentSubjectId = () => process.env.PI_RADAR_MANAGED_PARENT_SUBJECT_ID) {
|
|
3
3
|
async function agentId() {
|
|
4
4
|
const subject = await publication.subject();
|
|
5
|
-
return subject === void 0 ? { ok: false, code: "absent", message: "this process has no current Radar registration" } : { ok: true, value: subject.
|
|
5
|
+
return subject === void 0 ? { ok: false, code: "absent", message: "this process has no current Radar registration" } : { ok: true, value: subject.registration_id };
|
|
6
6
|
}
|
|
7
7
|
return {
|
|
8
8
|
async publish(request) {
|
|
@@ -13,24 +13,24 @@ function createRadarHandoffPort(client, publication, parentSubjectId = () => pro
|
|
|
13
13
|
return { ok: false, code: "absent", message: "this managed execution has no Radar parent subject" };
|
|
14
14
|
return client.communicationPublish({
|
|
15
15
|
...request,
|
|
16
|
-
|
|
16
|
+
sender_registration_id: identity.value,
|
|
17
17
|
recipient_subject_id: parent
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
20
|
async inbox() {
|
|
21
21
|
const identity = await agentId();
|
|
22
22
|
if (identity.ok === false) return identity;
|
|
23
|
-
return client.communicationInbox({
|
|
23
|
+
return client.communicationInbox({ registration_id: identity.value });
|
|
24
24
|
},
|
|
25
25
|
async get(handoff_id) {
|
|
26
26
|
const identity = await agentId();
|
|
27
27
|
if (identity.ok === false) return identity;
|
|
28
|
-
return client.communicationGet({
|
|
28
|
+
return client.communicationGet({ registration_id: identity.value, handoff_id });
|
|
29
29
|
},
|
|
30
30
|
async ack(handoff_id) {
|
|
31
31
|
const identity = await agentId();
|
|
32
32
|
if (identity.ok === false) return identity;
|
|
33
|
-
return client.communicationAck({
|
|
33
|
+
return client.communicationAck({ registration_id: identity.value, handoff_id });
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
}
|