@hashgraphonline/standards-sdk 0.1.184 → 0.1.185
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/browser/hcs-25/identifiers.d.ts +24 -0
- package/dist/browser/hcs-25/identifiers.d.ts.map +1 -0
- package/dist/browser/hcs-25/index.d.ts +4 -0
- package/dist/browser/hcs-25/index.d.ts.map +1 -0
- package/dist/browser/hcs-25/scoring.d.ts +32 -0
- package/dist/browser/hcs-25/scoring.d.ts.map +1 -0
- package/dist/browser/hcs-25/types.d.ts +363 -0
- package/dist/browser/hcs-25/types.d.ts.map +1 -0
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser-root/hcs-25/identifiers.d.ts +24 -0
- package/dist/browser-root/hcs-25/identifiers.d.ts.map +1 -0
- package/dist/browser-root/hcs-25/index.d.ts +4 -0
- package/dist/browser-root/hcs-25/index.d.ts.map +1 -0
- package/dist/browser-root/hcs-25/scoring.d.ts +32 -0
- package/dist/browser-root/hcs-25/scoring.d.ts.map +1 -0
- package/dist/browser-root/hcs-25/types.d.ts +363 -0
- package/dist/browser-root/hcs-25/types.d.ts.map +1 -0
- package/dist/browser-root/index.d.ts +1 -0
- package/dist/browser-root/index.d.ts.map +1 -1
- package/dist/cjs/hcs-25/identifiers.d.ts +24 -0
- package/dist/cjs/hcs-25/identifiers.d.ts.map +1 -0
- package/dist/cjs/hcs-25/index.d.ts +4 -0
- package/dist/cjs/hcs-25/index.d.ts.map +1 -0
- package/dist/cjs/hcs-25/scoring.d.ts +32 -0
- package/dist/cjs/hcs-25/scoring.d.ts.map +1 -0
- package/dist/cjs/hcs-25/types.d.ts +363 -0
- package/dist/cjs/hcs-25/types.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/hcs-25/identifiers.d.ts +24 -0
- package/dist/es/hcs-25/identifiers.d.ts.map +1 -0
- package/dist/es/hcs-25/index.d.ts +4 -0
- package/dist/es/hcs-25/index.d.ts.map +1 -0
- package/dist/es/hcs-25/scoring.d.ts +32 -0
- package/dist/es/hcs-25/scoring.d.ts.map +1 -0
- package/dist/es/hcs-25/types.d.ts +363 -0
- package/dist/es/hcs-25/types.d.ts.map +1 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +62 -40
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +2 -2
- package/dist/es/standards-sdk.es103.js +2 -2
- package/dist/es/standards-sdk.es104.js +1 -1
- package/dist/es/standards-sdk.es106.js +1 -1
- package/dist/es/standards-sdk.es108.js +2 -2
- package/dist/es/standards-sdk.es11.js +1 -1
- package/dist/es/standards-sdk.es110.js +1 -1
- package/dist/es/standards-sdk.es111.js +2 -2
- package/dist/es/standards-sdk.es115.js +3 -3
- package/dist/es/standards-sdk.es116.js +4 -4
- package/dist/es/standards-sdk.es117.js +19 -251
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es118.js +60 -475
- package/dist/es/standards-sdk.es118.js.map +1 -1
- package/dist/es/standards-sdk.es119.js +217 -86
- package/dist/es/standards-sdk.es119.js.map +1 -1
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es120.js +242 -150
- package/dist/es/standards-sdk.es120.js.map +1 -1
- package/dist/es/standards-sdk.es121.js +470 -26
- package/dist/es/standards-sdk.es121.js.map +1 -1
- package/dist/es/standards-sdk.es122.js +103 -10
- package/dist/es/standards-sdk.es122.js.map +1 -1
- package/dist/es/standards-sdk.es123.js +145 -167
- package/dist/es/standards-sdk.es123.js.map +1 -1
- package/dist/es/standards-sdk.es124.js +30 -25
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +10 -20
- package/dist/es/standards-sdk.es125.js.map +1 -1
- package/dist/es/standards-sdk.es126.js +159 -137
- package/dist/es/standards-sdk.es126.js.map +1 -1
- package/dist/es/standards-sdk.es127.js +27 -199
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +15 -783
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +157 -10
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es130.js +198 -564
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +703 -539
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +12 -12
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +567 -2
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +610 -71
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +12 -39
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +2 -2
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +42 -190
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +39 -1139
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +2 -306
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es140.js +231 -418
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +1135 -350
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +268 -1084
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +418 -204
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +350 -1562
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +1061 -1096
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +204 -13
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +1541 -233
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +1157 -4
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +15 -79
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es15.js +1 -1
- package/dist/es/standards-sdk.es150.js +250 -78
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +4 -60
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +80 -2546
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +80 -152
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +60 -7
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +2547 -86
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +144 -50
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +7 -30
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +86 -34
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +65 -48
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +5 -5
- package/dist/es/standards-sdk.es160.js +30 -138
- package/dist/es/standards-sdk.es160.js.map +1 -1
- package/dist/es/standards-sdk.es161.js +34 -42
- package/dist/es/standards-sdk.es161.js.map +1 -1
- package/dist/es/standards-sdk.es162.js +48 -12482
- package/dist/es/standards-sdk.es162.js.map +1 -1
- package/dist/es/standards-sdk.es163.js +12479 -53
- package/dist/es/standards-sdk.es163.js.map +1 -1
- package/dist/es/standards-sdk.es164.js +124 -97
- package/dist/es/standards-sdk.es164.js.map +1 -1
- package/dist/es/standards-sdk.es165.js +35 -74
- package/dist/es/standards-sdk.es165.js.map +1 -1
- package/dist/es/standards-sdk.es166.js +14 -197
- package/dist/es/standards-sdk.es166.js.map +1 -1
- package/dist/es/standards-sdk.es167.js +54 -15
- package/dist/es/standards-sdk.es167.js.map +1 -1
- package/dist/es/standards-sdk.es168.js +90 -651
- package/dist/es/standards-sdk.es168.js.map +1 -1
- package/dist/es/standards-sdk.es169.js +70 -161
- package/dist/es/standards-sdk.es169.js.map +1 -1
- package/dist/es/standards-sdk.es170.js +187 -309
- package/dist/es/standards-sdk.es170.js.map +1 -1
- package/dist/es/standards-sdk.es171.js +661 -335
- package/dist/es/standards-sdk.es171.js.map +1 -1
- package/dist/es/standards-sdk.es172.js +64 -444
- package/dist/es/standards-sdk.es172.js.map +1 -1
- package/dist/es/standards-sdk.es173.js +142 -301
- package/dist/es/standards-sdk.es173.js.map +1 -1
- package/dist/es/standards-sdk.es174.js +310 -64
- package/dist/es/standards-sdk.es174.js.map +1 -1
- package/dist/es/standards-sdk.es175.js +337 -64
- package/dist/es/standards-sdk.es175.js.map +1 -1
- package/dist/es/standards-sdk.es176.js +438 -124
- package/dist/es/standards-sdk.es176.js.map +1 -1
- package/dist/es/standards-sdk.es177.js +310 -496
- package/dist/es/standards-sdk.es177.js.map +1 -1
- package/dist/es/standards-sdk.es178.js +60 -243
- package/dist/es/standards-sdk.es178.js.map +1 -1
- package/dist/es/standards-sdk.es179.js +118 -175
- package/dist/es/standards-sdk.es179.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +12 -12
- package/dist/es/standards-sdk.es180.js +465 -67
- package/dist/es/standards-sdk.es180.js.map +1 -1
- package/dist/es/standards-sdk.es181.js +250 -143
- package/dist/es/standards-sdk.es181.js.map +1 -1
- package/dist/es/standards-sdk.es182.js +172 -160
- package/dist/es/standards-sdk.es182.js.map +1 -1
- package/dist/es/standards-sdk.es183.js +65 -630
- package/dist/es/standards-sdk.es183.js.map +1 -1
- package/dist/es/standards-sdk.es184.js +128 -161
- package/dist/es/standards-sdk.es184.js.map +1 -1
- package/dist/es/standards-sdk.es185.js +144 -195
- package/dist/es/standards-sdk.es185.js.map +1 -1
- package/dist/es/standards-sdk.es186.js +668 -223
- package/dist/es/standards-sdk.es186.js.map +1 -1
- package/dist/es/standards-sdk.es187.js +188 -0
- package/dist/es/standards-sdk.es187.js.map +1 -0
- package/dist/es/standards-sdk.es188.js +238 -0
- package/dist/es/standards-sdk.es188.js.map +1 -0
- package/dist/es/standards-sdk.es189.js +242 -0
- package/dist/es/standards-sdk.es189.js.map +1 -0
- package/dist/es/standards-sdk.es19.js +9 -9
- package/dist/es/standards-sdk.es2.js +2 -2
- package/dist/es/standards-sdk.es20.js +1 -1
- package/dist/es/standards-sdk.es21.js +1 -1
- package/dist/es/standards-sdk.es22.js +1 -1
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es24.js +1 -1
- package/dist/es/standards-sdk.es25.js +1 -1
- package/dist/es/standards-sdk.es26.js +1 -1
- package/dist/es/standards-sdk.es27.js +12 -12
- package/dist/es/standards-sdk.es30.js +2 -2
- package/dist/es/standards-sdk.es31.js +4 -4
- package/dist/es/standards-sdk.es32.js +1 -1
- package/dist/es/standards-sdk.es35.js +6 -6
- package/dist/es/standards-sdk.es36.js +4 -4
- package/dist/es/standards-sdk.es37.js +2 -2
- package/dist/es/standards-sdk.es38.js +2 -2
- package/dist/es/standards-sdk.es39.js +1 -1
- package/dist/es/standards-sdk.es4.js +2 -2
- package/dist/es/standards-sdk.es40.js +1 -1
- package/dist/es/standards-sdk.es41.js +2 -2
- package/dist/es/standards-sdk.es46.js +1 -1
- package/dist/es/standards-sdk.es5.js +2 -2
- package/dist/es/standards-sdk.es51.js +1 -1
- package/dist/es/standards-sdk.es53.js +1 -1
- package/dist/es/standards-sdk.es56.js +2 -2
- package/dist/es/standards-sdk.es59.js +1 -1
- package/dist/es/standards-sdk.es6.js +2 -2
- package/dist/es/standards-sdk.es60.js +1 -1
- package/dist/es/standards-sdk.es62.js +1 -1
- package/dist/es/standards-sdk.es63.js +2 -2
- package/dist/es/standards-sdk.es64.js +1 -1
- package/dist/es/standards-sdk.es65.js +1 -1
- package/dist/es/standards-sdk.es66.js +1 -1
- package/dist/es/standards-sdk.es67.js +7 -7
- package/dist/es/standards-sdk.es69.js +1 -1
- package/dist/es/standards-sdk.es7.js +1 -1
- package/dist/es/standards-sdk.es71.js +2 -2
- package/dist/es/standards-sdk.es72.js +3 -3
- package/dist/es/standards-sdk.es75.js +5 -5
- package/dist/es/standards-sdk.es76.js +3 -3
- package/dist/es/standards-sdk.es77.js +2 -2
- package/dist/es/standards-sdk.es78.js +1 -1
- package/dist/es/standards-sdk.es81.js +2 -2
- package/dist/es/standards-sdk.es83.js +2 -2
- package/dist/es/standards-sdk.es84.js +4 -4
- package/dist/es/standards-sdk.es85.js +1 -1
- package/dist/es/standards-sdk.es88.js +1 -1
- package/dist/es/standards-sdk.es89.js +2 -2
- package/dist/es/standards-sdk.es9.js +2 -2
- package/dist/es/standards-sdk.es90.js +4 -4
- package/dist/es/standards-sdk.es94.js +3 -3
- package/dist/es/standards-sdk.es96.js +2 -2
- package/dist/es/standards-sdk.es98.js +1 -1
- package/dist/es/standards-sdk.es99.js +3 -3
- package/package.json +1 -1
|
@@ -1,122 +1,520 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { toJsonObject } from "./standards-sdk.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { createSessionResponseSchema, chatSessionResumeResponseSchema, chatReadinessResponseSchema, chatHistoryCompactionResponseSchema, sessionEncryptionStatusResponseSchema, encryptionHandshakeResponseSchema, sendMessageResponseSchema, chatSessionEndResponseSchema } from "./standards-sdk.es155.js";
|
|
2
|
+
import { serialiseAuthConfig, toJsonObject } from "./standards-sdk.es189.js";
|
|
3
|
+
import { EncryptionUnavailableError } from "./standards-sdk.es181.js";
|
|
4
|
+
function createChatApi(client, encryptedManager) {
|
|
5
|
+
return {
|
|
6
|
+
start: (options) => client.startChat(options),
|
|
7
|
+
readiness: (payload) => client.checkChatReadiness(payload),
|
|
8
|
+
createSession: (payload) => client.createSession(payload),
|
|
9
|
+
resumeSession: (sessionId) => client.resumeSession(sessionId),
|
|
10
|
+
sendMessage: (payload) => client.sendMessage(payload),
|
|
11
|
+
retryMessage: (messageId, payload) => client.retryMessage(messageId, payload),
|
|
12
|
+
cancelSession: (sessionId) => client.cancelSession(sessionId),
|
|
13
|
+
endSession: (sessionId) => client.endSession(sessionId),
|
|
14
|
+
getHistory: (sessionId, options) => client.fetchHistorySnapshot(sessionId, options),
|
|
15
|
+
compactHistory: (payload) => client.compactHistory(payload),
|
|
16
|
+
getEncryptionStatus: (sessionId) => client.fetchEncryptionStatus(sessionId),
|
|
17
|
+
submitEncryptionHandshake: (sessionId, payload) => client.postEncryptionHandshake(sessionId, payload),
|
|
18
|
+
startConversation: (options) => client.startConversation(options),
|
|
19
|
+
acceptConversation: (options) => client.acceptConversation(options),
|
|
20
|
+
createEncryptedSession: (options) => encryptedManager.startSession(options),
|
|
21
|
+
acceptEncryptedSession: (options) => encryptedManager.acceptSession(options)
|
|
22
|
+
};
|
|
12
23
|
}
|
|
13
|
-
async function
|
|
14
|
-
const
|
|
15
|
-
|
|
24
|
+
async function checkChatReadiness(client, payload) {
|
|
25
|
+
const body = {};
|
|
26
|
+
const uaid = "uaid" in payload ? payload.uaid?.trim() : void 0;
|
|
27
|
+
const agentUrl = "agentUrl" in payload ? payload.agentUrl?.trim() : void 0;
|
|
28
|
+
if (!uaid && !agentUrl) {
|
|
29
|
+
throw new Error("uaid or agentUrl is required to check chat readiness");
|
|
30
|
+
}
|
|
31
|
+
if (uaid) {
|
|
32
|
+
body.uaid = uaid;
|
|
33
|
+
}
|
|
34
|
+
if (agentUrl) {
|
|
35
|
+
body.agentUrl = agentUrl;
|
|
36
|
+
}
|
|
37
|
+
if (payload.forceRefresh !== void 0) {
|
|
38
|
+
body.forceRefresh = payload.forceRefresh;
|
|
39
|
+
}
|
|
40
|
+
const raw = await client.requestJson("/chat/readiness", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
body,
|
|
43
|
+
headers: { "content-type": "application/json" }
|
|
16
44
|
});
|
|
17
45
|
return client.parseWithSchema(
|
|
18
46
|
raw,
|
|
19
|
-
|
|
20
|
-
"
|
|
47
|
+
chatReadinessResponseSchema,
|
|
48
|
+
"chat readiness response"
|
|
21
49
|
);
|
|
22
50
|
}
|
|
23
|
-
async function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
async function createSession(client, payload, allowHistoryAutoTopUp = true) {
|
|
52
|
+
const body = {};
|
|
53
|
+
if ("uaid" in payload && payload.uaid) {
|
|
54
|
+
body.uaid = payload.uaid;
|
|
55
|
+
}
|
|
56
|
+
if ("agentUrl" in payload && payload.agentUrl) {
|
|
57
|
+
body.agentUrl = payload.agentUrl;
|
|
58
|
+
}
|
|
59
|
+
if (payload.auth) {
|
|
60
|
+
body.auth = serialiseAuthConfig(payload.auth);
|
|
61
|
+
}
|
|
62
|
+
if (payload.historyTtlSeconds !== void 0) {
|
|
63
|
+
body.historyTtlSeconds = payload.historyTtlSeconds;
|
|
64
|
+
}
|
|
65
|
+
if (payload.encryptionRequested !== void 0) {
|
|
66
|
+
body.encryptionRequested = payload.encryptionRequested;
|
|
67
|
+
}
|
|
68
|
+
if (payload.senderUaid) {
|
|
69
|
+
body.senderUaid = payload.senderUaid;
|
|
70
|
+
}
|
|
71
|
+
if (payload.visibility) {
|
|
72
|
+
body.visibility = payload.visibility;
|
|
73
|
+
}
|
|
74
|
+
if (payload.idempotencyKey) {
|
|
75
|
+
body.idempotencyKey = payload.idempotencyKey;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const raw = await client.requestJson("/chat/session", {
|
|
79
|
+
method: "POST",
|
|
80
|
+
body,
|
|
81
|
+
headers: { "content-type": "application/json" }
|
|
82
|
+
});
|
|
83
|
+
return client.parseWithSchema(
|
|
84
|
+
raw,
|
|
85
|
+
createSessionResponseSchema,
|
|
86
|
+
"chat session response"
|
|
87
|
+
);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const maybeError = error instanceof Error ? error : null;
|
|
90
|
+
if (allowHistoryAutoTopUp && client.shouldAutoTopUpHistory(payload, maybeError)) {
|
|
91
|
+
await client.executeHistoryAutoTopUp("chat.session");
|
|
92
|
+
return createSession(client, payload, false);
|
|
28
93
|
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function resumeSession(client, sessionId) {
|
|
98
|
+
const normalized = sessionId.trim();
|
|
99
|
+
if (!normalized) {
|
|
100
|
+
throw new Error("sessionId is required to resume a chat session");
|
|
101
|
+
}
|
|
102
|
+
const raw = await client.requestJson(
|
|
103
|
+
`/chat/session/${encodeURIComponent(normalized)}/resume`,
|
|
104
|
+
{ method: "GET" }
|
|
29
105
|
);
|
|
30
106
|
return client.parseWithSchema(
|
|
31
107
|
raw,
|
|
32
|
-
|
|
33
|
-
"
|
|
108
|
+
chatSessionResumeResponseSchema,
|
|
109
|
+
"chat session resume response"
|
|
34
110
|
);
|
|
35
111
|
}
|
|
36
|
-
async function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
112
|
+
async function startChat(client, encryptedManager, options) {
|
|
113
|
+
if ("uaid" in options && options.uaid) {
|
|
114
|
+
return startConversation(client, encryptedManager, {
|
|
115
|
+
uaid: options.uaid,
|
|
116
|
+
senderUaid: options.senderUaid,
|
|
117
|
+
historyTtlSeconds: options.historyTtlSeconds,
|
|
118
|
+
auth: options.auth,
|
|
119
|
+
encryption: options.encryption,
|
|
120
|
+
onSessionCreated: options.onSessionCreated
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if ("agentUrl" in options && options.agentUrl) {
|
|
124
|
+
const session = await createSession(client, {
|
|
125
|
+
agentUrl: options.agentUrl,
|
|
126
|
+
auth: options.auth,
|
|
127
|
+
historyTtlSeconds: options.historyTtlSeconds,
|
|
128
|
+
senderUaid: options.senderUaid
|
|
129
|
+
});
|
|
130
|
+
options.onSessionCreated?.(session.sessionId);
|
|
131
|
+
return createPlaintextConversationHandle(
|
|
132
|
+
client,
|
|
133
|
+
session.sessionId,
|
|
134
|
+
session.encryption ?? null,
|
|
135
|
+
options.auth,
|
|
136
|
+
{ agentUrl: options.agentUrl, uaid: options.uaid }
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
throw new Error("startChat requires either uaid or agentUrl");
|
|
140
|
+
}
|
|
141
|
+
async function startConversation(client, encryptedManager, options) {
|
|
142
|
+
const preference = options.encryption?.preference ?? "preferred";
|
|
143
|
+
const requestEncryption = preference !== "disabled";
|
|
144
|
+
if (!requestEncryption) {
|
|
145
|
+
const session = await createSession(client, {
|
|
146
|
+
uaid: options.uaid,
|
|
147
|
+
auth: options.auth,
|
|
148
|
+
historyTtlSeconds: options.historyTtlSeconds,
|
|
149
|
+
senderUaid: options.senderUaid,
|
|
150
|
+
encryptionRequested: false
|
|
151
|
+
});
|
|
152
|
+
options.onSessionCreated?.(session.sessionId);
|
|
153
|
+
return createPlaintextConversationHandle(
|
|
154
|
+
client,
|
|
155
|
+
session.sessionId,
|
|
156
|
+
session.encryption ?? null,
|
|
157
|
+
options.auth,
|
|
158
|
+
{ uaid: options.uaid }
|
|
159
|
+
);
|
|
40
160
|
}
|
|
41
|
-
|
|
42
|
-
|
|
161
|
+
try {
|
|
162
|
+
const handle = await encryptedManager.startSession({
|
|
163
|
+
uaid: options.uaid,
|
|
164
|
+
senderUaid: options.senderUaid,
|
|
165
|
+
historyTtlSeconds: options.historyTtlSeconds,
|
|
166
|
+
handshakeTimeoutMs: options.encryption?.handshakeTimeoutMs,
|
|
167
|
+
pollIntervalMs: options.encryption?.pollIntervalMs,
|
|
168
|
+
onSessionCreated: (sessionId) => {
|
|
169
|
+
options.onSessionCreated?.(sessionId);
|
|
170
|
+
},
|
|
171
|
+
auth: options.auth
|
|
172
|
+
});
|
|
173
|
+
return handle;
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error instanceof EncryptionUnavailableError) {
|
|
176
|
+
if (preference === "required") {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
return createPlaintextConversationHandle(
|
|
180
|
+
client,
|
|
181
|
+
error.sessionId,
|
|
182
|
+
error.summary ?? null,
|
|
183
|
+
options.auth,
|
|
184
|
+
{ uaid: options.uaid }
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
throw error;
|
|
43
188
|
}
|
|
44
|
-
|
|
45
|
-
|
|
189
|
+
}
|
|
190
|
+
async function acceptConversation(client, encryptedManager, options) {
|
|
191
|
+
const preference = options.encryption?.preference ?? "preferred";
|
|
192
|
+
if (preference === "disabled") {
|
|
193
|
+
return createPlaintextConversationHandle(client, options.sessionId, null);
|
|
46
194
|
}
|
|
47
|
-
|
|
48
|
-
|
|
195
|
+
try {
|
|
196
|
+
const handle = await encryptedManager.acceptSession({
|
|
197
|
+
sessionId: options.sessionId,
|
|
198
|
+
responderUaid: options.responderUaid,
|
|
199
|
+
handshakeTimeoutMs: options.encryption?.handshakeTimeoutMs,
|
|
200
|
+
pollIntervalMs: options.encryption?.pollIntervalMs
|
|
201
|
+
});
|
|
202
|
+
return handle;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (error instanceof EncryptionUnavailableError && preference !== "required") {
|
|
205
|
+
return createPlaintextConversationHandle(
|
|
206
|
+
client,
|
|
207
|
+
options.sessionId,
|
|
208
|
+
null,
|
|
209
|
+
void 0,
|
|
210
|
+
{ uaid: options.responderUaid }
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function createPlaintextConversationHandle(client, sessionId, summary, defaultAuth, context) {
|
|
217
|
+
const uaid = context?.uaid?.trim();
|
|
218
|
+
const agentUrl = context?.agentUrl?.trim();
|
|
219
|
+
const fetchHistory = async (options) => {
|
|
220
|
+
const snapshot = await client.fetchHistorySnapshot(sessionId, options);
|
|
221
|
+
if (snapshot.decryptedHistory) {
|
|
222
|
+
return snapshot.decryptedHistory;
|
|
223
|
+
}
|
|
224
|
+
return snapshot.history.map((entry) => ({
|
|
225
|
+
entry,
|
|
226
|
+
plaintext: entry.content
|
|
227
|
+
}));
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
sessionId,
|
|
231
|
+
mode: "plaintext",
|
|
232
|
+
summary: summary ?? null,
|
|
233
|
+
send: async (options) => {
|
|
234
|
+
const plaintext = options.plaintext;
|
|
235
|
+
if (!plaintext || plaintext.trim().length === 0) {
|
|
236
|
+
throw new Error("plaintext is required for chat messages");
|
|
237
|
+
}
|
|
238
|
+
const message = options.message ?? plaintext;
|
|
239
|
+
return sendMessage(client, {
|
|
240
|
+
sessionId,
|
|
241
|
+
message,
|
|
242
|
+
streaming: options.streaming,
|
|
243
|
+
auth: options.auth ?? defaultAuth,
|
|
244
|
+
uaid,
|
|
245
|
+
agentUrl
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
decryptHistoryEntry: (entry) => entry.content,
|
|
249
|
+
fetchHistory
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
async function compactHistory(client, payload) {
|
|
253
|
+
if (!payload.sessionId || payload.sessionId.trim().length === 0) {
|
|
254
|
+
throw new Error("sessionId is required to compact chat history");
|
|
49
255
|
}
|
|
50
|
-
|
|
51
|
-
|
|
256
|
+
const body = {};
|
|
257
|
+
if (typeof payload.preserveEntries === "number" && Number.isFinite(payload.preserveEntries) && payload.preserveEntries >= 0) {
|
|
258
|
+
body.preserveEntries = Math.floor(payload.preserveEntries);
|
|
52
259
|
}
|
|
53
|
-
|
|
54
|
-
|
|
260
|
+
const raw = await client.requestJson(
|
|
261
|
+
`/chat/session/${encodeURIComponent(payload.sessionId)}/compact`,
|
|
262
|
+
{
|
|
263
|
+
method: "POST",
|
|
264
|
+
headers: { "content-type": "application/json" },
|
|
265
|
+
body
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
return client.parseWithSchema(
|
|
269
|
+
raw,
|
|
270
|
+
chatHistoryCompactionResponseSchema,
|
|
271
|
+
"chat history compaction response"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
async function fetchEncryptionStatus(client, sessionId) {
|
|
275
|
+
if (!sessionId || sessionId.trim().length === 0) {
|
|
276
|
+
throw new Error("sessionId is required for encryption status");
|
|
55
277
|
}
|
|
56
|
-
const suffix = params.size > 0 ? `?${params.toString()}` : "";
|
|
57
278
|
const raw = await client.requestJson(
|
|
58
|
-
`/
|
|
279
|
+
`/chat/session/${encodeURIComponent(sessionId)}/encryption`,
|
|
59
280
|
{
|
|
60
281
|
method: "GET"
|
|
61
282
|
}
|
|
62
283
|
);
|
|
63
284
|
return client.parseWithSchema(
|
|
64
285
|
raw,
|
|
65
|
-
|
|
66
|
-
"
|
|
286
|
+
sessionEncryptionStatusResponseSchema,
|
|
287
|
+
"session encryption status response"
|
|
67
288
|
);
|
|
68
289
|
}
|
|
69
|
-
async function
|
|
290
|
+
async function postEncryptionHandshake(client, sessionId, payload) {
|
|
291
|
+
if (!sessionId || sessionId.trim().length === 0) {
|
|
292
|
+
throw new Error("sessionId is required for encryption handshake");
|
|
293
|
+
}
|
|
70
294
|
const raw = await client.requestJson(
|
|
71
|
-
|
|
295
|
+
`/chat/session/${encodeURIComponent(sessionId)}/encryption-handshake`,
|
|
72
296
|
{
|
|
73
297
|
method: "POST",
|
|
74
298
|
headers: { "content-type": "application/json" },
|
|
75
|
-
body:
|
|
299
|
+
body: {
|
|
300
|
+
role: payload.role,
|
|
301
|
+
keyType: payload.keyType,
|
|
302
|
+
ephemeralPublicKey: payload.ephemeralPublicKey,
|
|
303
|
+
longTermPublicKey: payload.longTermPublicKey,
|
|
304
|
+
signature: payload.signature,
|
|
305
|
+
uaid: payload.uaid,
|
|
306
|
+
userId: payload.userId,
|
|
307
|
+
ledgerAccountId: payload.ledgerAccountId,
|
|
308
|
+
metadata: payload.metadata
|
|
309
|
+
}
|
|
76
310
|
}
|
|
77
311
|
);
|
|
78
|
-
const
|
|
312
|
+
const response = client.parseWithSchema(
|
|
79
313
|
raw,
|
|
80
|
-
|
|
81
|
-
"
|
|
314
|
+
encryptionHandshakeResponseSchema,
|
|
315
|
+
"encryption handshake response"
|
|
82
316
|
);
|
|
83
|
-
return
|
|
317
|
+
return response.handshake;
|
|
84
318
|
}
|
|
85
|
-
async function
|
|
319
|
+
async function sendMessage(client, payload) {
|
|
320
|
+
const body = {
|
|
321
|
+
message: payload.message
|
|
322
|
+
};
|
|
323
|
+
if (payload.streaming !== void 0) {
|
|
324
|
+
body.streaming = payload.streaming;
|
|
325
|
+
}
|
|
326
|
+
if (payload.idempotencyKey) {
|
|
327
|
+
body.idempotencyKey = payload.idempotencyKey;
|
|
328
|
+
}
|
|
329
|
+
if (payload.senderUaid) {
|
|
330
|
+
body.senderUaid = payload.senderUaid;
|
|
331
|
+
}
|
|
332
|
+
if (payload.transport) {
|
|
333
|
+
body.transport = payload.transport;
|
|
334
|
+
}
|
|
335
|
+
if (payload.auth) {
|
|
336
|
+
body.auth = serialiseAuthConfig(payload.auth);
|
|
337
|
+
}
|
|
338
|
+
if ("uaid" in payload) {
|
|
339
|
+
body.uaid = payload.uaid;
|
|
340
|
+
}
|
|
341
|
+
if ("sessionId" in payload && payload.sessionId) {
|
|
342
|
+
body.sessionId = payload.sessionId;
|
|
343
|
+
}
|
|
344
|
+
if ("agentUrl" in payload && payload.agentUrl) {
|
|
345
|
+
body.agentUrl = payload.agentUrl;
|
|
346
|
+
}
|
|
347
|
+
let cipherEnvelope = payload.cipherEnvelope ?? null;
|
|
348
|
+
if (payload.encryption) {
|
|
349
|
+
const sessionIdForEncryption = payload.encryption.sessionId ?? (typeof body.sessionId === "string" ? body.sessionId : void 0);
|
|
350
|
+
if (!sessionIdForEncryption) {
|
|
351
|
+
throw new Error(
|
|
352
|
+
"sessionId is required when using encrypted chat payloads"
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
if (!payload.encryption.recipients?.length) {
|
|
356
|
+
throw new Error("recipients are required for encrypted chat payloads");
|
|
357
|
+
}
|
|
358
|
+
cipherEnvelope = client.encryption.encryptCipherEnvelope({
|
|
359
|
+
...payload.encryption,
|
|
360
|
+
sessionId: sessionIdForEncryption
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (cipherEnvelope) {
|
|
364
|
+
body.cipherEnvelope = toJsonObject(cipherEnvelope);
|
|
365
|
+
}
|
|
366
|
+
const raw = await client.requestJson("/chat/message", {
|
|
367
|
+
method: "POST",
|
|
368
|
+
body,
|
|
369
|
+
headers: { "content-type": "application/json" }
|
|
370
|
+
});
|
|
371
|
+
return client.parseWithSchema(
|
|
372
|
+
raw,
|
|
373
|
+
sendMessageResponseSchema,
|
|
374
|
+
"chat message response"
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
async function endSession(client, sessionId) {
|
|
378
|
+
const normalizedSessionId = sessionId?.trim();
|
|
379
|
+
if (!normalizedSessionId) {
|
|
380
|
+
throw new Error("sessionId is required to end a chat session");
|
|
381
|
+
}
|
|
382
|
+
const response = await client.request(
|
|
383
|
+
`/chat/session/${encodeURIComponent(normalizedSessionId)}`,
|
|
384
|
+
{ method: "DELETE" }
|
|
385
|
+
);
|
|
386
|
+
if (response.status === 204) {
|
|
387
|
+
return {
|
|
388
|
+
message: "Session ended",
|
|
389
|
+
sessionId: normalizedSessionId,
|
|
390
|
+
state: "ended"
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const contentType = response.headers?.get("content-type") ?? "";
|
|
394
|
+
if (!contentType.toLowerCase().includes("json")) {
|
|
395
|
+
await response.text();
|
|
396
|
+
return {
|
|
397
|
+
message: "Session ended",
|
|
398
|
+
sessionId: normalizedSessionId,
|
|
399
|
+
state: "ended"
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
const responseBody = await response.text();
|
|
403
|
+
if (responseBody.trim().length === 0) {
|
|
404
|
+
return {
|
|
405
|
+
message: "Session ended",
|
|
406
|
+
sessionId: normalizedSessionId,
|
|
407
|
+
state: "ended"
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const raw = JSON.parse(responseBody);
|
|
411
|
+
return client.parseWithSchema(
|
|
412
|
+
raw,
|
|
413
|
+
chatSessionEndResponseSchema,
|
|
414
|
+
"chat session end response"
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
async function cancelSession(client, sessionId) {
|
|
418
|
+
const normalizedSessionId = sessionId?.trim();
|
|
419
|
+
if (!normalizedSessionId) {
|
|
420
|
+
throw new Error("sessionId is required to cancel a chat session");
|
|
421
|
+
}
|
|
86
422
|
const raw = await client.requestJson(
|
|
87
|
-
|
|
423
|
+
`/chat/session/${encodeURIComponent(normalizedSessionId)}/cancel`,
|
|
88
424
|
{
|
|
89
|
-
method: "POST"
|
|
90
|
-
headers: { "content-type": "application/json" },
|
|
91
|
-
body: toJsonObject(payload)
|
|
425
|
+
method: "POST"
|
|
92
426
|
}
|
|
93
427
|
);
|
|
94
428
|
return client.parseWithSchema(
|
|
95
429
|
raw,
|
|
96
|
-
|
|
97
|
-
"
|
|
430
|
+
chatSessionEndResponseSchema,
|
|
431
|
+
"chat session cancel response"
|
|
98
432
|
);
|
|
99
433
|
}
|
|
100
|
-
async function
|
|
434
|
+
async function retryMessage(client, messageId, payload) {
|
|
435
|
+
const normalizedMessageId = messageId?.trim();
|
|
436
|
+
const normalizedSessionId = payload.sessionId?.trim();
|
|
437
|
+
const normalizedMessage = payload.message?.trim();
|
|
438
|
+
if (!normalizedMessageId) {
|
|
439
|
+
throw new Error("messageId is required to retry a message");
|
|
440
|
+
}
|
|
441
|
+
if (!normalizedSessionId) {
|
|
442
|
+
throw new Error("sessionId is required to retry a message");
|
|
443
|
+
}
|
|
444
|
+
if (!normalizedMessage) {
|
|
445
|
+
throw new Error("message is required to retry a message");
|
|
446
|
+
}
|
|
447
|
+
const body = {
|
|
448
|
+
sessionId: normalizedSessionId,
|
|
449
|
+
message: payload.message
|
|
450
|
+
};
|
|
451
|
+
if (payload.streaming !== void 0) {
|
|
452
|
+
body.streaming = payload.streaming;
|
|
453
|
+
}
|
|
454
|
+
if (payload.transport) {
|
|
455
|
+
body.transport = payload.transport;
|
|
456
|
+
}
|
|
457
|
+
const uaid = payload.uaid?.trim();
|
|
458
|
+
const agentUrl = payload.agentUrl?.trim();
|
|
459
|
+
const idempotencyKey = payload.idempotencyKey?.trim();
|
|
460
|
+
const senderUaid = payload.senderUaid?.trim();
|
|
461
|
+
if (uaid) {
|
|
462
|
+
body.uaid = uaid;
|
|
463
|
+
}
|
|
464
|
+
if (agentUrl) {
|
|
465
|
+
body.agentUrl = agentUrl;
|
|
466
|
+
}
|
|
467
|
+
if (idempotencyKey) {
|
|
468
|
+
body.idempotencyKey = idempotencyKey;
|
|
469
|
+
}
|
|
470
|
+
if (senderUaid) {
|
|
471
|
+
body.senderUaid = senderUaid;
|
|
472
|
+
}
|
|
473
|
+
if (payload.auth) {
|
|
474
|
+
body.auth = serialiseAuthConfig(payload.auth);
|
|
475
|
+
}
|
|
476
|
+
let cipherEnvelope = payload.cipherEnvelope ?? null;
|
|
477
|
+
if (payload.encryption) {
|
|
478
|
+
if (!payload.encryption.recipients?.length) {
|
|
479
|
+
throw new Error("recipients are required for encrypted chat payloads");
|
|
480
|
+
}
|
|
481
|
+
cipherEnvelope = client.encryption.encryptCipherEnvelope({
|
|
482
|
+
...payload.encryption,
|
|
483
|
+
sessionId: payload.encryption.sessionId ?? normalizedSessionId
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
if (cipherEnvelope) {
|
|
487
|
+
body.cipherEnvelope = toJsonObject(cipherEnvelope);
|
|
488
|
+
}
|
|
101
489
|
const raw = await client.requestJson(
|
|
102
|
-
`/
|
|
490
|
+
`/chat/message/${encodeURIComponent(normalizedMessageId)}/retry`,
|
|
103
491
|
{
|
|
104
|
-
method: "
|
|
492
|
+
method: "POST",
|
|
493
|
+
body,
|
|
494
|
+
headers: { "content-type": "application/json" }
|
|
105
495
|
}
|
|
106
496
|
);
|
|
107
497
|
return client.parseWithSchema(
|
|
108
498
|
raw,
|
|
109
|
-
|
|
110
|
-
"
|
|
499
|
+
sendMessageResponseSchema,
|
|
500
|
+
"chat retry response"
|
|
111
501
|
);
|
|
112
502
|
}
|
|
113
503
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
504
|
+
acceptConversation,
|
|
505
|
+
cancelSession,
|
|
506
|
+
checkChatReadiness,
|
|
507
|
+
compactHistory,
|
|
508
|
+
createChatApi,
|
|
509
|
+
createPlaintextConversationHandle,
|
|
510
|
+
createSession,
|
|
511
|
+
endSession,
|
|
512
|
+
fetchEncryptionStatus,
|
|
513
|
+
postEncryptionHandshake,
|
|
514
|
+
resumeSession,
|
|
515
|
+
retryMessage,
|
|
516
|
+
sendMessage,
|
|
517
|
+
startChat,
|
|
518
|
+
startConversation
|
|
121
519
|
};
|
|
122
520
|
//# sourceMappingURL=standards-sdk.es180.js.map
|