@segmentstream/ontology 0.124.0 → 0.126.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/CHANGELOG.md +19 -0
- package/README.md +1 -0
- package/dist/agent-chat.d.ts +4 -0
- package/dist/agent-chat.js +33 -11
- package/dist/analyze.js +4 -17
- package/dist/index.d.ts +1 -1
- package/dist/manifest.d.ts +405 -9
- package/dist/manifest.js +29 -2
- package/dist/migrate/model.d.ts +230 -6
- package/dist/runtime/agents.js +62 -2
- package/dist/service/agent/protocol.d.ts +10 -0
- package/dist/service/agent/protocol.js +12 -0
- package/dist/service/agent/server.js +31 -1
- package/dist/service/runtime-contract.d.ts +24 -0
- package/dist/service/schemas.d.ts +56 -0
- package/dist/service/webhooks.d.ts +22 -6
- package/dist/service/webhooks.js +131 -50
- package/dist/service/workflows.js +8 -6
- package/dist/webhooks.d.ts +105 -2
- package/dist/webhooks.js +293 -2
- package/dist/workflow.d.ts +10 -5
- package/dist/workflows.d.ts +1 -1
- package/package.json +1 -1
package/dist/migrate/model.d.ts
CHANGED
|
@@ -416,8 +416,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
416
416
|
};
|
|
417
417
|
} | undefined;
|
|
418
418
|
readonly attribution?: {
|
|
419
|
-
readonly template?: string | undefined;
|
|
420
419
|
readonly separator?: string | undefined;
|
|
420
|
+
readonly template?: string | undefined;
|
|
421
421
|
} | undefined;
|
|
422
422
|
} | undefined;
|
|
423
423
|
readonly workflows?: readonly {
|
|
@@ -449,6 +449,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
449
449
|
readonly signature?: {
|
|
450
450
|
readonly scheme: string;
|
|
451
451
|
readonly secret: string;
|
|
452
|
+
readonly message?: readonly (string | {
|
|
453
|
+
readonly body: true;
|
|
454
|
+
} | {
|
|
455
|
+
readonly header: string;
|
|
456
|
+
} | {
|
|
457
|
+
readonly timestamp: true;
|
|
458
|
+
})[] | undefined;
|
|
459
|
+
readonly key?: {
|
|
460
|
+
readonly decode: string;
|
|
461
|
+
readonly prefix?: string | undefined;
|
|
462
|
+
} | undefined;
|
|
463
|
+
readonly timestamp?: {
|
|
464
|
+
readonly unit?: string | undefined;
|
|
465
|
+
readonly entry?: string | undefined;
|
|
466
|
+
readonly tolerance?: number | undefined;
|
|
467
|
+
readonly header?: string | undefined;
|
|
468
|
+
} | undefined;
|
|
469
|
+
readonly algorithm?: string | undefined;
|
|
470
|
+
readonly encoding?: string | undefined;
|
|
471
|
+
readonly signatures?: {
|
|
472
|
+
readonly header: string;
|
|
473
|
+
readonly entries?: {
|
|
474
|
+
readonly separator: string;
|
|
475
|
+
readonly assign: string;
|
|
476
|
+
readonly name: string;
|
|
477
|
+
} | undefined;
|
|
478
|
+
readonly prefix?: string | undefined;
|
|
479
|
+
} | undefined;
|
|
452
480
|
} | undefined;
|
|
453
481
|
readonly verification?: {
|
|
454
482
|
readonly scheme: string;
|
|
@@ -736,8 +764,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
736
764
|
};
|
|
737
765
|
} | undefined;
|
|
738
766
|
readonly attribution?: {
|
|
739
|
-
readonly template?: string | undefined;
|
|
740
767
|
readonly separator?: string | undefined;
|
|
768
|
+
readonly template?: string | undefined;
|
|
741
769
|
} | undefined;
|
|
742
770
|
} | undefined;
|
|
743
771
|
readonly workflows?: readonly {
|
|
@@ -769,6 +797,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
769
797
|
readonly signature?: {
|
|
770
798
|
readonly scheme: string;
|
|
771
799
|
readonly secret: string;
|
|
800
|
+
readonly message?: readonly (string | {
|
|
801
|
+
readonly body: true;
|
|
802
|
+
} | {
|
|
803
|
+
readonly header: string;
|
|
804
|
+
} | {
|
|
805
|
+
readonly timestamp: true;
|
|
806
|
+
})[] | undefined;
|
|
807
|
+
readonly key?: {
|
|
808
|
+
readonly decode: string;
|
|
809
|
+
readonly prefix?: string | undefined;
|
|
810
|
+
} | undefined;
|
|
811
|
+
readonly timestamp?: {
|
|
812
|
+
readonly unit?: string | undefined;
|
|
813
|
+
readonly entry?: string | undefined;
|
|
814
|
+
readonly tolerance?: number | undefined;
|
|
815
|
+
readonly header?: string | undefined;
|
|
816
|
+
} | undefined;
|
|
817
|
+
readonly algorithm?: string | undefined;
|
|
818
|
+
readonly encoding?: string | undefined;
|
|
819
|
+
readonly signatures?: {
|
|
820
|
+
readonly header: string;
|
|
821
|
+
readonly entries?: {
|
|
822
|
+
readonly separator: string;
|
|
823
|
+
readonly assign: string;
|
|
824
|
+
readonly name: string;
|
|
825
|
+
} | undefined;
|
|
826
|
+
readonly prefix?: string | undefined;
|
|
827
|
+
} | undefined;
|
|
772
828
|
} | undefined;
|
|
773
829
|
readonly verification?: {
|
|
774
830
|
readonly scheme: string;
|
|
@@ -1056,8 +1112,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1056
1112
|
};
|
|
1057
1113
|
} | undefined;
|
|
1058
1114
|
readonly attribution?: {
|
|
1059
|
-
readonly template?: string | undefined;
|
|
1060
1115
|
readonly separator?: string | undefined;
|
|
1116
|
+
readonly template?: string | undefined;
|
|
1061
1117
|
} | undefined;
|
|
1062
1118
|
} | undefined;
|
|
1063
1119
|
readonly workflows?: readonly {
|
|
@@ -1091,6 +1147,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1091
1147
|
readonly signature?: {
|
|
1092
1148
|
readonly scheme: string;
|
|
1093
1149
|
readonly secret: string;
|
|
1150
|
+
readonly message?: readonly (string | {
|
|
1151
|
+
readonly body: true;
|
|
1152
|
+
} | {
|
|
1153
|
+
readonly header: string;
|
|
1154
|
+
} | {
|
|
1155
|
+
readonly timestamp: true;
|
|
1156
|
+
})[] | undefined;
|
|
1157
|
+
readonly key?: {
|
|
1158
|
+
readonly decode: string;
|
|
1159
|
+
readonly prefix?: string | undefined;
|
|
1160
|
+
} | undefined;
|
|
1161
|
+
readonly timestamp?: {
|
|
1162
|
+
readonly unit?: string | undefined;
|
|
1163
|
+
readonly entry?: string | undefined;
|
|
1164
|
+
readonly tolerance?: number | undefined;
|
|
1165
|
+
readonly header?: string | undefined;
|
|
1166
|
+
} | undefined;
|
|
1167
|
+
readonly algorithm?: string | undefined;
|
|
1168
|
+
readonly encoding?: string | undefined;
|
|
1169
|
+
readonly signatures?: {
|
|
1170
|
+
readonly header: string;
|
|
1171
|
+
readonly entries?: {
|
|
1172
|
+
readonly separator: string;
|
|
1173
|
+
readonly assign: string;
|
|
1174
|
+
readonly name: string;
|
|
1175
|
+
} | undefined;
|
|
1176
|
+
readonly prefix?: string | undefined;
|
|
1177
|
+
} | undefined;
|
|
1094
1178
|
} | undefined;
|
|
1095
1179
|
readonly verification?: {
|
|
1096
1180
|
readonly scheme: string;
|
|
@@ -1376,8 +1460,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1376
1460
|
};
|
|
1377
1461
|
} | undefined;
|
|
1378
1462
|
readonly attribution?: {
|
|
1379
|
-
readonly template?: string | undefined;
|
|
1380
1463
|
readonly separator?: string | undefined;
|
|
1464
|
+
readonly template?: string | undefined;
|
|
1381
1465
|
} | undefined;
|
|
1382
1466
|
} | undefined;
|
|
1383
1467
|
readonly workflows?: readonly {
|
|
@@ -1411,6 +1495,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1411
1495
|
readonly signature?: {
|
|
1412
1496
|
readonly scheme: string;
|
|
1413
1497
|
readonly secret: string;
|
|
1498
|
+
readonly message?: readonly (string | {
|
|
1499
|
+
readonly body: true;
|
|
1500
|
+
} | {
|
|
1501
|
+
readonly header: string;
|
|
1502
|
+
} | {
|
|
1503
|
+
readonly timestamp: true;
|
|
1504
|
+
})[] | undefined;
|
|
1505
|
+
readonly key?: {
|
|
1506
|
+
readonly decode: string;
|
|
1507
|
+
readonly prefix?: string | undefined;
|
|
1508
|
+
} | undefined;
|
|
1509
|
+
readonly timestamp?: {
|
|
1510
|
+
readonly unit?: string | undefined;
|
|
1511
|
+
readonly entry?: string | undefined;
|
|
1512
|
+
readonly tolerance?: number | undefined;
|
|
1513
|
+
readonly header?: string | undefined;
|
|
1514
|
+
} | undefined;
|
|
1515
|
+
readonly algorithm?: string | undefined;
|
|
1516
|
+
readonly encoding?: string | undefined;
|
|
1517
|
+
readonly signatures?: {
|
|
1518
|
+
readonly header: string;
|
|
1519
|
+
readonly entries?: {
|
|
1520
|
+
readonly separator: string;
|
|
1521
|
+
readonly assign: string;
|
|
1522
|
+
readonly name: string;
|
|
1523
|
+
} | undefined;
|
|
1524
|
+
readonly prefix?: string | undefined;
|
|
1525
|
+
} | undefined;
|
|
1414
1526
|
} | undefined;
|
|
1415
1527
|
readonly verification?: {
|
|
1416
1528
|
readonly scheme: string;
|
|
@@ -1846,6 +1958,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1846
1958
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
1847
1959
|
readonly scheme: Schema.String;
|
|
1848
1960
|
readonly secret: Schema.String;
|
|
1961
|
+
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
1962
|
+
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
1963
|
+
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
1964
|
+
readonly decode: Schema.String;
|
|
1965
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
1966
|
+
}>>;
|
|
1967
|
+
readonly signatures: Schema.optionalKey<Schema.Struct<{
|
|
1968
|
+
readonly header: Schema.String;
|
|
1969
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
1970
|
+
readonly entries: Schema.optionalKey<Schema.Struct<{
|
|
1971
|
+
readonly separator: Schema.String;
|
|
1972
|
+
readonly assign: Schema.String;
|
|
1973
|
+
readonly name: Schema.String;
|
|
1974
|
+
}>>;
|
|
1975
|
+
}>>;
|
|
1976
|
+
readonly timestamp: Schema.optionalKey<Schema.Struct<{
|
|
1977
|
+
readonly header: Schema.optionalKey<Schema.String>;
|
|
1978
|
+
readonly entry: Schema.optionalKey<Schema.String>;
|
|
1979
|
+
readonly unit: Schema.optionalKey<Schema.String>;
|
|
1980
|
+
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
1981
|
+
}>>;
|
|
1982
|
+
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
1983
|
+
readonly body: Schema.Literal<true>;
|
|
1984
|
+
}>, Schema.Struct<{
|
|
1985
|
+
readonly header: Schema.String;
|
|
1986
|
+
}>, Schema.Struct<{
|
|
1987
|
+
readonly timestamp: Schema.Literal<true>;
|
|
1988
|
+
}>]>>>;
|
|
1849
1989
|
}>>;
|
|
1850
1990
|
readonly verification: Schema.optionalKey<Schema.Struct<{
|
|
1851
1991
|
readonly scheme: Schema.String;
|
|
@@ -2162,6 +2302,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2162
2302
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
2163
2303
|
readonly scheme: Schema.String;
|
|
2164
2304
|
readonly secret: Schema.String;
|
|
2305
|
+
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
2306
|
+
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
2307
|
+
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
2308
|
+
readonly decode: Schema.String;
|
|
2309
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
2310
|
+
}>>;
|
|
2311
|
+
readonly signatures: Schema.optionalKey<Schema.Struct<{
|
|
2312
|
+
readonly header: Schema.String;
|
|
2313
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
2314
|
+
readonly entries: Schema.optionalKey<Schema.Struct<{
|
|
2315
|
+
readonly separator: Schema.String;
|
|
2316
|
+
readonly assign: Schema.String;
|
|
2317
|
+
readonly name: Schema.String;
|
|
2318
|
+
}>>;
|
|
2319
|
+
}>>;
|
|
2320
|
+
readonly timestamp: Schema.optionalKey<Schema.Struct<{
|
|
2321
|
+
readonly header: Schema.optionalKey<Schema.String>;
|
|
2322
|
+
readonly entry: Schema.optionalKey<Schema.String>;
|
|
2323
|
+
readonly unit: Schema.optionalKey<Schema.String>;
|
|
2324
|
+
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
2325
|
+
}>>;
|
|
2326
|
+
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
2327
|
+
readonly body: Schema.Literal<true>;
|
|
2328
|
+
}>, Schema.Struct<{
|
|
2329
|
+
readonly header: Schema.String;
|
|
2330
|
+
}>, Schema.Struct<{
|
|
2331
|
+
readonly timestamp: Schema.Literal<true>;
|
|
2332
|
+
}>]>>>;
|
|
2165
2333
|
}>>;
|
|
2166
2334
|
readonly verification: Schema.optionalKey<Schema.Struct<{
|
|
2167
2335
|
readonly scheme: Schema.String;
|
|
@@ -2341,8 +2509,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2341
2509
|
};
|
|
2342
2510
|
} | undefined;
|
|
2343
2511
|
readonly attribution?: {
|
|
2344
|
-
readonly template?: string | undefined;
|
|
2345
2512
|
readonly separator?: string | undefined;
|
|
2513
|
+
readonly template?: string | undefined;
|
|
2346
2514
|
} | undefined;
|
|
2347
2515
|
} | undefined;
|
|
2348
2516
|
readonly workflows?: readonly {
|
|
@@ -2374,6 +2542,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2374
2542
|
readonly signature?: {
|
|
2375
2543
|
readonly scheme: string;
|
|
2376
2544
|
readonly secret: string;
|
|
2545
|
+
readonly message?: readonly (string | {
|
|
2546
|
+
readonly body: true;
|
|
2547
|
+
} | {
|
|
2548
|
+
readonly header: string;
|
|
2549
|
+
} | {
|
|
2550
|
+
readonly timestamp: true;
|
|
2551
|
+
})[] | undefined;
|
|
2552
|
+
readonly key?: {
|
|
2553
|
+
readonly decode: string;
|
|
2554
|
+
readonly prefix?: string | undefined;
|
|
2555
|
+
} | undefined;
|
|
2556
|
+
readonly timestamp?: {
|
|
2557
|
+
readonly unit?: string | undefined;
|
|
2558
|
+
readonly entry?: string | undefined;
|
|
2559
|
+
readonly tolerance?: number | undefined;
|
|
2560
|
+
readonly header?: string | undefined;
|
|
2561
|
+
} | undefined;
|
|
2562
|
+
readonly algorithm?: string | undefined;
|
|
2563
|
+
readonly encoding?: string | undefined;
|
|
2564
|
+
readonly signatures?: {
|
|
2565
|
+
readonly header: string;
|
|
2566
|
+
readonly entries?: {
|
|
2567
|
+
readonly separator: string;
|
|
2568
|
+
readonly assign: string;
|
|
2569
|
+
readonly name: string;
|
|
2570
|
+
} | undefined;
|
|
2571
|
+
readonly prefix?: string | undefined;
|
|
2572
|
+
} | undefined;
|
|
2377
2573
|
} | undefined;
|
|
2378
2574
|
readonly verification?: {
|
|
2379
2575
|
readonly scheme: string;
|
|
@@ -2661,8 +2857,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2661
2857
|
};
|
|
2662
2858
|
} | undefined;
|
|
2663
2859
|
readonly attribution?: {
|
|
2664
|
-
readonly template?: string | undefined;
|
|
2665
2860
|
readonly separator?: string | undefined;
|
|
2861
|
+
readonly template?: string | undefined;
|
|
2666
2862
|
} | undefined;
|
|
2667
2863
|
} | undefined;
|
|
2668
2864
|
readonly workflows?: readonly {
|
|
@@ -2694,6 +2890,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2694
2890
|
readonly signature?: {
|
|
2695
2891
|
readonly scheme: string;
|
|
2696
2892
|
readonly secret: string;
|
|
2893
|
+
readonly message?: readonly (string | {
|
|
2894
|
+
readonly body: true;
|
|
2895
|
+
} | {
|
|
2896
|
+
readonly header: string;
|
|
2897
|
+
} | {
|
|
2898
|
+
readonly timestamp: true;
|
|
2899
|
+
})[] | undefined;
|
|
2900
|
+
readonly key?: {
|
|
2901
|
+
readonly decode: string;
|
|
2902
|
+
readonly prefix?: string | undefined;
|
|
2903
|
+
} | undefined;
|
|
2904
|
+
readonly timestamp?: {
|
|
2905
|
+
readonly unit?: string | undefined;
|
|
2906
|
+
readonly entry?: string | undefined;
|
|
2907
|
+
readonly tolerance?: number | undefined;
|
|
2908
|
+
readonly header?: string | undefined;
|
|
2909
|
+
} | undefined;
|
|
2910
|
+
readonly algorithm?: string | undefined;
|
|
2911
|
+
readonly encoding?: string | undefined;
|
|
2912
|
+
readonly signatures?: {
|
|
2913
|
+
readonly header: string;
|
|
2914
|
+
readonly entries?: {
|
|
2915
|
+
readonly separator: string;
|
|
2916
|
+
readonly assign: string;
|
|
2917
|
+
readonly name: string;
|
|
2918
|
+
} | undefined;
|
|
2919
|
+
readonly prefix?: string | undefined;
|
|
2920
|
+
} | undefined;
|
|
2697
2921
|
} | undefined;
|
|
2698
2922
|
readonly verification?: {
|
|
2699
2923
|
readonly scheme: string;
|
package/dist/runtime/agents.js
CHANGED
|
@@ -547,14 +547,70 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
547
547
|
title: String(chat.title),
|
|
548
548
|
purpose: nullableText(chat.purpose),
|
|
549
549
|
whenToUse: nullableText(chat.when_to_use),
|
|
550
|
-
// A member of staff took the chat over
|
|
551
|
-
|
|
550
|
+
// A member of staff took the chat over, or the agent handed the person over to staff:
|
|
551
|
+
// the agent records the person and answers none.
|
|
552
|
+
...(((chat.handled_by_id ?? null) !== null || (chat.handoff_at ?? null) !== null) &&
|
|
552
553
|
takeoverChannelsOf(ontology.manifest).has(input.provider)
|
|
553
554
|
? { handled: true }
|
|
554
555
|
: {}),
|
|
555
556
|
};
|
|
556
557
|
}));
|
|
557
558
|
}).pipe(Effect.orDie),
|
|
559
|
+
handOffChat: (input) => Effect.gen(function* () {
|
|
560
|
+
// Only a chat staff may take over is handed to them.
|
|
561
|
+
if (!takeoverChannelsOf(ontology.manifest).has(input.provider) ||
|
|
562
|
+
!isRecordId(input.memberId)) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
return yield* sql.withTransaction(Effect.gen(function* () {
|
|
566
|
+
yield* beginReplicationWrite(sql);
|
|
567
|
+
yield* rows(`SELECT pg_advisory_xact_lock(hashtext($1))`, [
|
|
568
|
+
`chat:${input.provider}:${input.externalId}`,
|
|
569
|
+
]);
|
|
570
|
+
const runtime = makeOntologyRuntime(ontology, sql, {
|
|
571
|
+
action: `${AgentChat.name}.handoff`,
|
|
572
|
+
actionId: randomUUID(),
|
|
573
|
+
principalId: null,
|
|
574
|
+
});
|
|
575
|
+
const [found] = yield* runtime.find({
|
|
576
|
+
entity: AgentChat.name,
|
|
577
|
+
options: {
|
|
578
|
+
where: { provider: input.provider, external_id: input.externalId, kind: "private" },
|
|
579
|
+
limit: 1,
|
|
580
|
+
forUpdate: true,
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
if (found === undefined) {
|
|
584
|
+
return undefined;
|
|
585
|
+
}
|
|
586
|
+
const id = String(found.id);
|
|
587
|
+
// Only the chat's own person is handed over: the agent reports the chat it answers.
|
|
588
|
+
const members = yield* runtime.related({
|
|
589
|
+
entity: AgentChat.name,
|
|
590
|
+
id,
|
|
591
|
+
relationship: "members",
|
|
592
|
+
query: { limit: MAX_QUERY_LIMIT },
|
|
593
|
+
});
|
|
594
|
+
if (!members.items.some((member) => String(member.id) === input.memberId)) {
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
// A member of staff holds the chat already, or a handoff waits: nothing changes, and
|
|
598
|
+
// the first handoff keeps its time and reason.
|
|
599
|
+
if ((found.handled_by_id ?? null) !== null) {
|
|
600
|
+
return { id, handoffAt: null, handled: true };
|
|
601
|
+
}
|
|
602
|
+
if ((found.handoff_at ?? null) !== null) {
|
|
603
|
+
return { id, handoffAt: timestampText(found.handoff_at) };
|
|
604
|
+
}
|
|
605
|
+
const at = new Date().toISOString();
|
|
606
|
+
yield* runtime.update({
|
|
607
|
+
entity: AgentChat.name,
|
|
608
|
+
id,
|
|
609
|
+
values: { handoff_at: at, handoff_reason: input.reason },
|
|
610
|
+
});
|
|
611
|
+
return { id, handoffAt: at };
|
|
612
|
+
}));
|
|
613
|
+
}).pipe(Effect.orDie),
|
|
558
614
|
seeGuestChat: (guestId) => Effect.gen(function* () {
|
|
559
615
|
// Only the visitors' chats of an inbox that takes the guests.
|
|
560
616
|
if (!isRecordId(guestId) || !inboxRolesOf(ontology.manifest).has(GUEST_ROLE)) {
|
|
@@ -710,3 +766,7 @@ function inInbox(ontology, input, resolution) {
|
|
|
710
766
|
? { ...resolution, inbox: true, takeover: true }
|
|
711
767
|
: { ...resolution, inbox: true };
|
|
712
768
|
}
|
|
769
|
+
/** A stored timestamp, as the wire carries it. */
|
|
770
|
+
function timestampText(value) {
|
|
771
|
+
return value instanceof Date ? value.toISOString() : String(value);
|
|
772
|
+
}
|
|
@@ -127,6 +127,16 @@ export declare const ChatSeenRequest: Schema.Struct<{
|
|
|
127
127
|
readonly recipient: Schema.optionalKey<Schema.String>;
|
|
128
128
|
readonly threadId: Schema.optionalKey<Schema.String>;
|
|
129
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* `POST /api/ontology/agent/chats/handoff`: the agent hands a person's private chat over to staff,
|
|
132
|
+
* saying what the person needs.
|
|
133
|
+
*/
|
|
134
|
+
export declare const ChatHandoffRequest: Schema.Struct<{
|
|
135
|
+
readonly provider: Schema.String;
|
|
136
|
+
readonly externalId: Schema.String;
|
|
137
|
+
readonly memberId: Schema.String;
|
|
138
|
+
readonly reason: Schema.String;
|
|
139
|
+
}>;
|
|
130
140
|
/**
|
|
131
141
|
* `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
|
|
132
142
|
* it answers. `key` names the reply, so a report repeated after a failure finds its review.
|
|
@@ -160,6 +160,18 @@ export const ChatSeenRequest = Schema.Struct({
|
|
|
160
160
|
})),
|
|
161
161
|
threadId: Schema.optionalKey(ChatId.annotate({ description: "The thread a reply in the private chat stays in." })),
|
|
162
162
|
});
|
|
163
|
+
/**
|
|
164
|
+
* `POST /api/ontology/agent/chats/handoff`: the agent hands a person's private chat over to staff,
|
|
165
|
+
* saying what the person needs.
|
|
166
|
+
*/
|
|
167
|
+
export const ChatHandoffRequest = Schema.Struct({
|
|
168
|
+
provider: Provider,
|
|
169
|
+
externalId: ChatId.annotate({ description: "The private chat's id on the channel." }),
|
|
170
|
+
memberId: Schema.String.annotate({ description: "The user id of the chat's person." }),
|
|
171
|
+
reason: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(1000)).annotate({
|
|
172
|
+
description: "What the person needs from staff, in the agent's words.",
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
163
175
|
/**
|
|
164
176
|
* `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
|
|
165
177
|
* it answers. `key` names the reply, so a report repeated after a failure finds its review.
|
|
@@ -13,7 +13,7 @@ import { secretHash } from "../oauth/protocol.js";
|
|
|
13
13
|
import { clientAddress, fixedWindowLimiter, } from "../rate-limit.js";
|
|
14
14
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
15
15
|
import { AGENT_TASK_HEADER, agentTaskSecret, logRuntimeRejection, } from "../runtime-identity.js";
|
|
16
|
-
import { ChatSeenRequest, ReviewRequest, ResolveIdentityRequest, IdentityNoticeRequest, LimitNoticeRequest, PAIRING_TTL_MS, PairingRequest, canonicalPairingCode, identityForWire, memberForWire, newPairingCode, } from "./protocol.js";
|
|
16
|
+
import { ChatHandoffRequest, ChatSeenRequest, ReviewRequest, ResolveIdentityRequest, IdentityNoticeRequest, LimitNoticeRequest, PAIRING_TTL_MS, PairingRequest, canonicalPairingCode, identityForWire, memberForWire, newPairingCode, } from "./protocol.js";
|
|
17
17
|
import { AGENT_TOKEN_LIMIT, BOT_CHECK_LIMIT, introspectAgentToken, issueAgentToken, issueVisitorToken, visitorPreflight, } from "./web-tokens.js";
|
|
18
18
|
import { GUEST_LINK_PATH, guestRoutesPreflight, guestSignUpRoutes, recordGuestUsage, } from "./guest-sign-up.js";
|
|
19
19
|
import { identityToken } from "../operations.js";
|
|
@@ -22,6 +22,7 @@ export const AGENT_PATH = `${BASE_PATH}/agent`;
|
|
|
22
22
|
const PAIRINGS_PATH = `${AGENT_PATH}/pairings`;
|
|
23
23
|
const IDENTITIES_PATH = `${AGENT_PATH}/identities`;
|
|
24
24
|
const CHATS_SEEN_PATH = `${AGENT_PATH}/chats/seen`;
|
|
25
|
+
const CHATS_HANDOFF_PATH = `${AGENT_PATH}/chats/handoff`;
|
|
25
26
|
const REVIEWS_PATH = `${AGENT_PATH}/reviews`;
|
|
26
27
|
/** Where a signed-in member gets an agent token, and where the agent asks whom one stands for. */
|
|
27
28
|
export const AGENT_TOKENS_PATH = `${AGENT_PATH}/tokens`;
|
|
@@ -265,6 +266,34 @@ function completeLimitNotice(store) {
|
|
|
265
266
|
return HttpServerResponse.empty({ status: 204, headers: NO_STORE });
|
|
266
267
|
});
|
|
267
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* `POST /api/ontology/agent/chats/handoff` (runtime): the agent hands a person's private chat over to
|
|
271
|
+
* staff. The chat must be registered, on a channel `inbox.takeover` lists, and the person's own;
|
|
272
|
+
* anything else answers 404. The answer is the chat's id and when the handoff began, or `handled`
|
|
273
|
+
* when a member of staff holds the chat already.
|
|
274
|
+
*/
|
|
275
|
+
function handOffChat(store) {
|
|
276
|
+
return (request) => Effect.gen(function* () {
|
|
277
|
+
const requestId = yield* RequestId;
|
|
278
|
+
const decoded = Schema.decodeUnknownResult(ChatHandoffRequest)(yield* jsonBody(request), {
|
|
279
|
+
errors: "all",
|
|
280
|
+
onExcessProperty: "error",
|
|
281
|
+
});
|
|
282
|
+
if (Result.isFailure(decoded)) {
|
|
283
|
+
return invalidBody(requestId, schemaIssues(decoded.failure));
|
|
284
|
+
}
|
|
285
|
+
const handed = yield* store.handOffChat(decoded.success);
|
|
286
|
+
if (handed === undefined) {
|
|
287
|
+
return toServerResponse(notFound(requestId, "The chat is not one staff take over."));
|
|
288
|
+
}
|
|
289
|
+
yield* Effect.logInfo("ontology.agent.chat_handed_off").pipe(Effect.annotateLogs({
|
|
290
|
+
requestId,
|
|
291
|
+
provider: decoded.success.provider,
|
|
292
|
+
chatId: decoded.success.externalId,
|
|
293
|
+
}));
|
|
294
|
+
return json(handed);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
268
297
|
/**
|
|
269
298
|
* `POST /api/ontology/agent/chats/seen` (runtime): the agent saw a message in a group chat. The chat
|
|
270
299
|
* is recorded, or its title kept current, a paired writer joins its members and a paired member who
|
|
@@ -484,6 +513,7 @@ export function agentLayer(options) {
|
|
|
484
513
|
})));
|
|
485
514
|
}
|
|
486
515
|
yield* router.add("POST", CHATS_SEEN_PATH, asRuntime(seeChat(store)));
|
|
516
|
+
yield* router.add("POST", CHATS_HANDOFF_PATH, asRuntime(handOffChat(store)));
|
|
487
517
|
yield* router.add("POST", REVIEWS_PATH, asRuntime(holdReply(store)));
|
|
488
518
|
yield* router.add("DELETE", `${IDENTITIES_PATH}/:id`, asMember((_, member) => revokeIdentity(store, member)));
|
|
489
519
|
if (store.web !== undefined && backend.oauth !== undefined) {
|
|
@@ -561,6 +561,24 @@ export interface SeenChat {
|
|
|
561
561
|
*/
|
|
562
562
|
readonly handled?: true;
|
|
563
563
|
}
|
|
564
|
+
/** A person's private chat the agent hands over to staff (`POST /api/ontology/agent/chats/handoff`). */
|
|
565
|
+
export interface HandoffInput {
|
|
566
|
+
/** The channel's name. */
|
|
567
|
+
readonly provider: string;
|
|
568
|
+
readonly externalId: string;
|
|
569
|
+
/** The chat's person, whom the agent answers there. */
|
|
570
|
+
readonly memberId: string;
|
|
571
|
+
/** What the person needs from staff, in the agent's words. */
|
|
572
|
+
readonly reason: string;
|
|
573
|
+
}
|
|
574
|
+
/** A handoff the ontology recorded, or found waiting. */
|
|
575
|
+
export interface Handoff {
|
|
576
|
+
readonly id: string;
|
|
577
|
+
/** When the agent handed the person over: the first handoff's time, while it waits. */
|
|
578
|
+
readonly handoffAt: string | null;
|
|
579
|
+
/** A member of staff holds the chat already: nothing changed. */
|
|
580
|
+
readonly handled?: true;
|
|
581
|
+
}
|
|
564
582
|
/**
|
|
565
583
|
* Where the app's agent keeps pairing codes and the identities they create: the runtime's agent
|
|
566
584
|
* tables in the workspace database. Codes are stored only as SHA-256 hashes. Expiry is checked
|
|
@@ -652,6 +670,12 @@ export interface AgentStore {
|
|
|
652
670
|
* stores that predate the inbox.
|
|
653
671
|
*/
|
|
654
672
|
readonly seeInboxChat?: (input: InboxChatInput) => Effect.Effect<SeenChat | undefined>;
|
|
673
|
+
/**
|
|
674
|
+
* Hands a registered private chat on a channel staff take chats over on to staff: its
|
|
675
|
+
* `handoffAt` and `handoffReason`. Undefined for any other chat, or when `memberId` is not its
|
|
676
|
+
* person.
|
|
677
|
+
*/
|
|
678
|
+
readonly handOffChat: (input: HandoffInput) => Effect.Effect<Handoff | undefined>;
|
|
655
679
|
/**
|
|
656
680
|
* Records a website visitor's chat with the agent, `guest:<id>` on the `web` channel, for the
|
|
657
681
|
* inbox: creates the `agent_chat` of kind `private`, without members, and records when it last
|
|
@@ -586,6 +586,34 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
586
586
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
587
587
|
readonly scheme: Schema.String;
|
|
588
588
|
readonly secret: Schema.String;
|
|
589
|
+
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
590
|
+
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
591
|
+
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
592
|
+
readonly decode: Schema.String;
|
|
593
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
594
|
+
}>>;
|
|
595
|
+
readonly signatures: Schema.optionalKey<Schema.Struct<{
|
|
596
|
+
readonly header: Schema.String;
|
|
597
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
598
|
+
readonly entries: Schema.optionalKey<Schema.Struct<{
|
|
599
|
+
readonly separator: Schema.String;
|
|
600
|
+
readonly assign: Schema.String;
|
|
601
|
+
readonly name: Schema.String;
|
|
602
|
+
}>>;
|
|
603
|
+
}>>;
|
|
604
|
+
readonly timestamp: Schema.optionalKey<Schema.Struct<{
|
|
605
|
+
readonly header: Schema.optionalKey<Schema.String>;
|
|
606
|
+
readonly entry: Schema.optionalKey<Schema.String>;
|
|
607
|
+
readonly unit: Schema.optionalKey<Schema.String>;
|
|
608
|
+
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
609
|
+
}>>;
|
|
610
|
+
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
611
|
+
readonly body: Schema.Literal<true>;
|
|
612
|
+
}>, Schema.Struct<{
|
|
613
|
+
readonly header: Schema.String;
|
|
614
|
+
}>, Schema.Struct<{
|
|
615
|
+
readonly timestamp: Schema.Literal<true>;
|
|
616
|
+
}>]>>>;
|
|
589
617
|
}>>;
|
|
590
618
|
readonly verification: Schema.optionalKey<Schema.Struct<{
|
|
591
619
|
readonly scheme: Schema.String;
|
|
@@ -915,6 +943,34 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
915
943
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
916
944
|
readonly scheme: Schema.String;
|
|
917
945
|
readonly secret: Schema.String;
|
|
946
|
+
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
947
|
+
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
948
|
+
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
949
|
+
readonly decode: Schema.String;
|
|
950
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
951
|
+
}>>;
|
|
952
|
+
readonly signatures: Schema.optionalKey<Schema.Struct<{
|
|
953
|
+
readonly header: Schema.String;
|
|
954
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
955
|
+
readonly entries: Schema.optionalKey<Schema.Struct<{
|
|
956
|
+
readonly separator: Schema.String;
|
|
957
|
+
readonly assign: Schema.String;
|
|
958
|
+
readonly name: Schema.String;
|
|
959
|
+
}>>;
|
|
960
|
+
}>>;
|
|
961
|
+
readonly timestamp: Schema.optionalKey<Schema.Struct<{
|
|
962
|
+
readonly header: Schema.optionalKey<Schema.String>;
|
|
963
|
+
readonly entry: Schema.optionalKey<Schema.String>;
|
|
964
|
+
readonly unit: Schema.optionalKey<Schema.String>;
|
|
965
|
+
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
966
|
+
}>>;
|
|
967
|
+
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
968
|
+
readonly body: Schema.Literal<true>;
|
|
969
|
+
}>, Schema.Struct<{
|
|
970
|
+
readonly header: Schema.String;
|
|
971
|
+
}>, Schema.Struct<{
|
|
972
|
+
readonly timestamp: Schema.Literal<true>;
|
|
973
|
+
}>]>>>;
|
|
918
974
|
}>>;
|
|
919
975
|
readonly verification: Schema.optionalKey<Schema.Struct<{
|
|
920
976
|
readonly scheme: Schema.String;
|