bailinghub 0.10.1 → 0.11.1
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/CONTRIBUTING.md +20 -0
- package/README.en.md +6 -6
- package/README.md +6 -6
- package/SECURITY.md +20 -0
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_CONVERSATION_AUDIT.en.md +8 -2
- package/docs/AGENT_CONVERSATION_AUDIT.md +8 -1
- package/docs/CHANGELOG.en.md +18 -1
- package/docs/CHANGELOG.md +18 -1
- package/docs/IMPLEMENTATION_STATUS.en.md +3 -3
- package/docs/IMPLEMENTATION_STATUS.md +3 -3
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/MODEL_CONTINUATION.en.md +8 -0
- package/docs/MODEL_CONTINUATION.md +8 -0
- package/docs/MODEL_OUTPUT_BUDGET.en.md +1 -0
- package/docs/MODEL_OUTPUT_BUDGET.md +1 -0
- package/docs/README.en.md +4 -0
- package/docs/README.md +4 -0
- package/docs/RELEASE_NOTES_v0.11.0.en.md +19 -0
- package/docs/RELEASE_NOTES_v0.11.0.md +19 -0
- package/docs/RELEASE_NOTES_v0.11.1.en.md +25 -0
- package/docs/RELEASE_NOTES_v0.11.1.md +25 -0
- package/docs/UPGRADE_v0.11.0.en.md +24 -0
- package/docs/UPGRADE_v0.11.0.md +24 -0
- package/docs/UPGRADE_v0.11.1.en.md +28 -0
- package/docs/UPGRADE_v0.11.1.md +28 -0
- package/docs/security/GRC_EVIDENCE.md +54 -0
- package/docs/user-guide/console-map.md +2 -2
- package/package.json +1 -1
- package/scripts/check-doc-links.mjs +4 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/copy-acr-platform-image.sh +42 -0
- package/scripts/e2e-console-runtime-audit.mjs +7 -0
- package/scripts/e2e-console-troubleshooting-extra.mjs +4 -4
- package/scripts/e2e-console.mjs +90 -23
- package/scripts/install.sh +1 -1
- package/scripts/notification-console-test.mjs +2 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +8 -0
- package/scripts/restore-ghcr-version.sh +48 -0
- package/scripts/test-acr-platform-copy.sh +152 -0
- package/scripts/verify-github-repo.mjs +8 -0
- package/src/core/config/console-task-location.test.ts +12 -24
- package/src/core/runtime/credential-resolver.ts +3 -3
- package/src/infrastructure/config/config-agent-conversation-audit-repository.test.ts +29 -0
- package/src/infrastructure/config/config-agent-conversation-audit-repository.ts +142 -9
- package/src/infrastructure/config/config-conversation-feed.integration.test.ts +134 -0
- package/src/infrastructure/config/config-conversation-ledger.test.ts +47 -1
- package/src/infrastructure/config/config-conversation-ledger.ts +24 -8
- package/src/infrastructure/config/config-observability-ledger.ts +32 -4
- package/src/infrastructure/config/config-recent-jobs.integration.test.ts +45 -0
- package/src/infrastructure/config/configstore.ts +4 -4
- package/src/infrastructure/config/conversation-delivery-message.ts +12 -0
- package/src/modules/usage/contracts.ts +1 -0
- package/src/modules/usage/model-context.test.ts +106 -0
- package/src/modules/usage/model-context.ts +54 -0
- package/src/modules/usage/model-continuation.test.ts +27 -0
- package/src/modules/usage/provider.test.ts +40 -0
- package/src/modules/usage/provider.ts +21 -3
- package/src/modules/usage/repository.ts +2 -1
- package/src/routes/admin-conversation-audit.ts +20 -3
- package/src/routes/admin-history-cursor.ts +12 -0
- package/src/routes/admin-runtime.test.ts +47 -0
- package/src/routes/admin-runtime.ts +32 -3
- package/src/routes/admin-usage.ts +12 -1
- package/src/routes/admin.ts +6 -1
- package/src/routes/agent-conversation-audit.test.ts +47 -3
- package/src/test-support/agent-conversation-audit-fixture.ts +9 -1
- package/web/console/assets/{Accounts-Dhyw-7wF.js → Accounts-B1Ne8Xx2.js} +1 -1
- package/web/console/assets/AgentClients-CiGQ-n2i.js +1 -0
- package/web/console/assets/AgentClients-xEIfsj7w.css +1 -0
- package/web/console/assets/AgentTasks-CaCeYv60.css +1 -0
- package/web/console/assets/AgentTasks-CylHZHHq.js +2 -0
- package/web/console/assets/{Approvals-CQx1YWxW.js → Approvals-wD4Iv80G.js} +1 -1
- package/web/console/assets/{Audit--QcdVlMh.js → Audit-BStlxkPw.js} +1 -1
- package/web/console/assets/{BrandLockup-DQcaW4Nt.js → BrandLockup-BAhrPnhy.js} +1 -1
- package/web/console/assets/Channels-DAlIgNxo.js +105 -0
- package/web/console/assets/Channels-WwRHFKJn.css +1 -0
- package/web/console/assets/ChatEntries-CPx-E9aJ.js +7 -0
- package/web/console/assets/ChatEntries-DALYfRDP.css +1 -0
- package/web/console/assets/Clients-gqNFusNW.css +1 -0
- package/web/console/assets/Clients-w97QPpFD.js +3 -0
- package/web/console/assets/Cost-CNDZaif-.css +1 -0
- package/web/console/assets/Cost-CxtN0mca.js +1 -0
- package/web/console/assets/Credentials-6c6aktzZ.css +1 -0
- package/web/console/assets/Credentials-BhpoH-hR.js +1 -0
- package/web/console/assets/{Diagnostics-CyoM1XrZ.js → Diagnostics-DnC-ODuy.js} +1 -1
- package/web/console/assets/Executors-CCTYuZf4.js +1 -0
- package/web/console/assets/Executors-CQ8iw3kK.css +1 -0
- package/web/console/assets/{HelpTip-DLlhaGQp.js → HelpTip-piedkqU-.js} +1 -1
- package/web/console/assets/Kb-CFCa-7LY.css +1 -0
- package/web/console/assets/Kb-DKp3mwWB.js +2 -0
- package/web/console/assets/Login-g_aZWHQd.js +1 -0
- package/web/console/assets/Login-krXZsvoF.css +1 -0
- package/web/console/assets/Projects-BexeaCxT.css +1 -0
- package/web/console/assets/Projects-DurExYV9.js +1 -0
- package/web/console/assets/Routes-CKoIjkCM.css +1 -0
- package/web/console/assets/Routes-CX7Q7bkz.js +138 -0
- package/web/console/assets/Runs-C48kdEwk.css +1 -0
- package/web/console/assets/Runs-CQKEDsrH.js +3 -0
- package/web/console/assets/Setup-CtWCXXpj.css +1 -0
- package/web/console/assets/Setup-DzI8rEAc.js +1 -0
- package/web/console/assets/Shell-BQ-g_O7K.js +1 -0
- package/web/console/assets/Shell-Y2fZK5LV.css +1 -0
- package/web/console/assets/StorageBuckets-CWxzIh0x.css +1 -0
- package/web/console/assets/StorageBuckets-DoZIzA7B.js +1 -0
- package/web/console/assets/SystemSettings-C3pFFzAQ.js +1 -0
- package/web/console/assets/SystemSettings-C5nv0K2a.css +1 -0
- package/web/console/assets/SystemStatus-Bbxu2dp4.css +1 -0
- package/web/console/assets/SystemStatus-BgekIK52.js +1 -0
- package/web/console/assets/Targets-CbLq7rgm.css +1 -0
- package/web/console/assets/Targets-DH1ZcK0J.js +1 -0
- package/web/console/assets/Tools-CMS1wVOm.js +5 -0
- package/web/console/assets/Tools-Qk1c5Rp8.css +1 -0
- package/web/console/assets/Usage-C0OkK7Jg.js +1 -0
- package/web/console/assets/Usage-Cue7CYnT.css +1 -0
- package/web/console/assets/UsageAccess-CHdWXvE8.js +1 -0
- package/web/console/assets/UsageAccess-nOa03hGb.css +1 -0
- package/web/console/assets/{UsageHelp-BmuiE1Ew.js → UsageHelp-BkIsuFUj.js} +1 -1
- package/web/console/assets/{console-location-Csv-xsnl.js → console-location-C_az_xHo.js} +1 -1
- package/web/console/assets/index-CbI5fbiD.js +2 -0
- package/web/console/assets/{index-B_5UfiTw.js → index-DwlsLKwM.js} +1 -1
- package/web/console/assets/request-WgSVj8ie.js +1 -0
- package/web/console/assets/{schema-o3mK4mid.js → schema-rb4T_2cj.js} +1 -1
- package/web/console/assets/task-page-location-BGxGar7H.js +1 -0
- package/web/console/assets/{use-list-location-cIPy2cKM.js → use-list-location-DeVfTTII.js} +1 -1
- package/web/console/assets/{use-unsaved-form-DScKD0h9.js → use-unsaved-form-B10XHC-n.js} +1 -1
- package/web/console/assets/{util-B40VqOwl.js → util-C0YJ70YU.js} +1 -1
- package/web/console/assets/{vendor-element-BT8tHCFk.js → vendor-element-BCC2kYn_.js} +7 -7
- package/web/console/assets/{vendor-mammoth-CVIXVxTN.js → vendor-mammoth-C7l0Q30g.js} +1 -1
- package/web/console/index.html +2 -2
- package/web-admin/scripts/agent-task-control-smoke.mjs +26 -3
- package/web-admin/src/components/AgentSetupPanel.vue +19 -15
- package/web-admin/src/components/ChannelThread.vue +441 -0
- package/web-admin/src/components/ClientConversations.vue +397 -134
- package/web-admin/src/components/ConversationSourceTag.vue +24 -0
- package/web-admin/src/components/JobStatusTag.vue +18 -0
- package/web-admin/src/components/NotificationOutboxPanel.vue +5 -2
- package/web-admin/src/components/UsageServiceReferences.vue +6 -24
- package/web-admin/src/components/conversation-audit.ts +67 -2
- package/web-admin/src/components/conversation-reading-position.ts +27 -0
- package/web-admin/src/layout/Shell.vue +15 -17
- package/web-admin/src/onboarding-state.ts +5 -5
- package/web-admin/src/pages/AgentClients.vue +33 -27
- package/web-admin/src/pages/AgentTasks.vue +88 -43
- package/web-admin/src/pages/Channels.vue +15 -41
- package/web-admin/src/pages/ChatEntries.vue +13 -51
- package/web-admin/src/pages/Clients.vue +2 -2
- package/web-admin/src/pages/Cost.vue +10 -51
- package/web-admin/src/pages/Credentials.vue +1 -1
- package/web-admin/src/pages/Executors.vue +4 -3
- package/web-admin/src/pages/Kb.vue +4 -4
- package/web-admin/src/pages/Login.vue +7 -8
- package/web-admin/src/pages/Projects.vue +1 -1
- package/web-admin/src/pages/Routes.vue +46 -83
- package/web-admin/src/pages/Runs.vue +239 -567
- package/web-admin/src/pages/Setup.vue +20 -20
- package/web-admin/src/pages/StorageBuckets.vue +1 -1
- package/web-admin/src/pages/SystemSettings.vue +1 -2
- package/web-admin/src/pages/SystemStatus.vue +4 -6
- package/web-admin/src/pages/Targets.vue +0 -2
- package/web-admin/src/pages/Tools.vue +31 -22
- package/web-admin/src/pages/Usage.vue +110 -60
- package/web-admin/src/pages/UsageAccess.vue +2 -5
- package/web-admin/src/request.ts +5 -1
- package/web-admin/src/task-page-location.ts +6 -12
- package/web-admin/src/task-trace-presentation.ts +143 -0
- package/web-admin/tests/conversation-audit.test.mjs +23 -1
- package/web-admin/tests/model-context.browser.mjs +238 -0
- package/web-admin/tests/model-output-budget.browser.mjs +1 -0
- package/web/console/assets/AgentClients-BA0M26-I.css +0 -1
- package/web/console/assets/AgentClients-DWxb8-ko.js +0 -1
- package/web/console/assets/AgentTasks-DOyxANnx.css +0 -1
- package/web/console/assets/AgentTasks-DUHD4dzr.js +0 -2
- package/web/console/assets/Channels-DJJU3ksE.css +0 -1
- package/web/console/assets/Channels-cGS5WfQ-.js +0 -105
- package/web/console/assets/ChatEntries-BYpji27B.css +0 -1
- package/web/console/assets/ChatEntries-nh23Iz5O.js +0 -7
- package/web/console/assets/Clients-CX5EeYio.js +0 -3
- package/web/console/assets/Clients-CbZAou8E.css +0 -1
- package/web/console/assets/Cost-C6oQvz9P.css +0 -1
- package/web/console/assets/Cost-DOZfdNS9.js +0 -1
- package/web/console/assets/Credentials--aHs57yV.css +0 -1
- package/web/console/assets/Credentials-sy6W9Sac.js +0 -1
- package/web/console/assets/Executors-2Upi6bOS.css +0 -1
- package/web/console/assets/Executors-BQqqiFwt.js +0 -1
- package/web/console/assets/Kb-5R3ce4UU.js +0 -5
- package/web/console/assets/Kb-BM_PYi11.css +0 -1
- package/web/console/assets/Login-YKeUwdgo.js +0 -1
- package/web/console/assets/Login-xtPwDB5_.css +0 -1
- package/web/console/assets/Projects-DHwHrPT9.css +0 -1
- package/web/console/assets/Projects-Grgb6fOv.js +0 -1
- package/web/console/assets/Routes-DR_Yf02e.css +0 -1
- package/web/console/assets/Routes-DYgrXlRJ.js +0 -138
- package/web/console/assets/Runs-CwTddJJj.js +0 -3
- package/web/console/assets/Runs-D4FOvNfu.css +0 -1
- package/web/console/assets/Setup-Ca0b1d1-.css +0 -1
- package/web/console/assets/Setup-D_xUPNDq.js +0 -1
- package/web/console/assets/Shell-BTg8Vw_L.css +0 -1
- package/web/console/assets/Shell-Dfam2Uoj.js +0 -1
- package/web/console/assets/StorageBuckets-7QLBpV4a.css +0 -1
- package/web/console/assets/StorageBuckets-CP6e50wI.js +0 -1
- package/web/console/assets/SystemSettings-BRYKyJNa.js +0 -1
- package/web/console/assets/SystemSettings-HsXGx0aH.css +0 -1
- package/web/console/assets/SystemStatus-B-VfRsQd.css +0 -1
- package/web/console/assets/SystemStatus-CbPsDsGt.js +0 -1
- package/web/console/assets/Targets-1j4-g6rC.css +0 -1
- package/web/console/assets/Targets-C2LkR2AF.js +0 -1
- package/web/console/assets/Tools-C9HPJqJb.css +0 -1
- package/web/console/assets/Tools-C9JNJUS0.js +0 -2
- package/web/console/assets/Usage-D1Mv6vGY.js +0 -1
- package/web/console/assets/Usage-DMOzUsqh.css +0 -1
- package/web/console/assets/UsageAccess-77LmGCm6.js +0 -1
- package/web/console/assets/UsageAccess-C6ZGxEgJ.css +0 -1
- package/web/console/assets/index-MjZJEFIN.js +0 -2
- package/web/console/assets/request-rqm6MT0s.js +0 -1
- package/web/console/assets/task-page-location-DWiGtAln.js +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Return the verified GHCR version digest. Existing version tags keep their full index.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
acr_repo=${1:?ACR repository required}
|
|
6
|
+
ghcr_repo=${2:?GHCR repository required}
|
|
7
|
+
version=${3:?version required}
|
|
8
|
+
|
|
9
|
+
manifest_digest() {
|
|
10
|
+
local checksum
|
|
11
|
+
checksum=$(skopeo inspect --retry-times 3 --raw "docker://$1" | sha256sum) || return
|
|
12
|
+
printf 'sha256:%s\n' "${checksum%% *}"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
runtime_config() {
|
|
16
|
+
# Older mirrors may use a different manifest media type. Compare the complete runnable config,
|
|
17
|
+
# including the ordered rootfs diff IDs, rather than treating the index itself as the platform.
|
|
18
|
+
skopeo --override-os linux --override-arch amd64 inspect --retry-times 3 --config "docker://$1" |
|
|
19
|
+
jq -ceS --arg version "$version" '
|
|
20
|
+
select(.os == "linux" and .architecture == "amd64" and
|
|
21
|
+
.config.Labels["org.opencontainers.image.version"] == $version and
|
|
22
|
+
(.config.Labels["org.opencontainers.image.revision"] | test("^[0-9a-f]{40}$")) and
|
|
23
|
+
(.rootfs.diff_ids | type == "array" and length > 0))' |
|
|
24
|
+
sha256sum | cut -d ' ' -f 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
acr_digest=$(manifest_digest "$acr_repo:$version")
|
|
28
|
+
expected=$(runtime_config "$acr_repo@$acr_digest")
|
|
29
|
+
probe_error=$(mktemp)
|
|
30
|
+
trap 'rm -f "$probe_error"' EXIT
|
|
31
|
+
if ! ghcr_digest=$(manifest_digest "$ghcr_repo:$version" 2>"$probe_error"); then
|
|
32
|
+
if ! grep -Eiq '(: |")manifest unknown([: "].*)?$' "$probe_error"; then
|
|
33
|
+
cat "$probe_error" >&2
|
|
34
|
+
exit 1
|
|
35
|
+
fi
|
|
36
|
+
# Require a successful authenticated tag listing as a second check before creating a missing tag.
|
|
37
|
+
skopeo list-tags --retry-times 3 "docker://$ghcr_repo" |
|
|
38
|
+
jq -e --arg version "$version" '.Tags | type == "array" and index($version) == null' >/dev/null
|
|
39
|
+
skopeo copy --retry-times 3 --all --preserve-digests "docker://$acr_repo@$acr_digest" "docker://$ghcr_repo:$version" >&2
|
|
40
|
+
ghcr_digest=$(manifest_digest "$ghcr_repo:$version")
|
|
41
|
+
[[ "$ghcr_digest" == "$acr_digest" ]] || { echo "Restored GHCR version digest differs from ACR." >&2; exit 1; }
|
|
42
|
+
fi
|
|
43
|
+
actual=$(runtime_config "$ghcr_repo@$ghcr_digest")
|
|
44
|
+
if [[ "$actual" != "$expected" ]]; then
|
|
45
|
+
echo "GHCR $version and ACR $version have different runnable configurations; stopping recovery." >&2
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
printf '%s\n' "$ghcr_digest"
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Exercise release image copying with two disposable loopback-only TLS registries.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
6
|
+
tmp=$(mktemp -d)
|
|
7
|
+
registries=()
|
|
8
|
+
cleanup() {
|
|
9
|
+
for container in "${registries[@]}"; do docker rm -fv "$container" >/dev/null; done
|
|
10
|
+
rm -rf "$tmp"
|
|
11
|
+
}
|
|
12
|
+
trap cleanup EXIT
|
|
13
|
+
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj '/CN=localhost' \
|
|
14
|
+
-addext 'subjectAltName=IP:127.0.0.1' -keyout "$tmp/key.pem" -out "$tmp/cert.pem" 2>/dev/null
|
|
15
|
+
export SSL_CERT_FILE="$tmp/cert.pem" REGISTRY_AUTH_FILE="$tmp/auth.json"
|
|
16
|
+
printf '{"auths":{}}\n' > "$REGISTRY_AUTH_FILE"
|
|
17
|
+
|
|
18
|
+
for side in source target; do
|
|
19
|
+
container=$(docker create -p 127.0.0.1::5000 \
|
|
20
|
+
-e REGISTRY_HTTP_TLS_CERTIFICATE=/etc/docker/registry/cert.pem \
|
|
21
|
+
-e REGISTRY_HTTP_TLS_KEY=/etc/docker/registry/key.pem \
|
|
22
|
+
registry:2.8.3@sha256:a3d8aaa63ed8681a604f1dea0aa03f100d5895b6a58ace528858a7b332415373)
|
|
23
|
+
registries+=("$container")
|
|
24
|
+
docker cp "$tmp/cert.pem" "$container:/etc/docker/registry/cert.pem"
|
|
25
|
+
docker cp "$tmp/key.pem" "$container:/etc/docker/registry/key.pem"
|
|
26
|
+
docker start "$container" >/dev/null
|
|
27
|
+
endpoint=$(docker port "$container" 5000/tcp)
|
|
28
|
+
curl -fsS --cacert "$SSL_CERT_FILE" --retry 15 --retry-all-errors --retry-delay 1 "https://$endpoint/v2/" >/dev/null
|
|
29
|
+
printf -v "${side}_repo" '%s/test/image' "$endpoint"
|
|
30
|
+
done
|
|
31
|
+
|
|
32
|
+
version=v1.2.3
|
|
33
|
+
revision=1234567890abcdef1234567890abcdef12345678
|
|
34
|
+
# A deterministic OCI layout with two platforms and BuildKit-style provenance.
|
|
35
|
+
python3 - "$tmp" "$version" "$revision" <<'PY'
|
|
36
|
+
import gzip, hashlib, io, json, pathlib, sys, tarfile
|
|
37
|
+
root = pathlib.Path(sys.argv[1]) / 'layout'
|
|
38
|
+
blobs = root / 'blobs' / 'sha256'
|
|
39
|
+
blobs.mkdir(parents=True)
|
|
40
|
+
oci = 'application/vnd.oci.image.'
|
|
41
|
+
def encode(obj):
|
|
42
|
+
return json.dumps(obj, separators=(',', ':')).encode()
|
|
43
|
+
def blob(media, data):
|
|
44
|
+
if not isinstance(data, bytes):
|
|
45
|
+
data = encode(data)
|
|
46
|
+
key = hashlib.sha256(data).hexdigest()
|
|
47
|
+
(blobs / key).write_bytes(data)
|
|
48
|
+
return {'mediaType': media, 'digest': 'sha256:' + key, 'size': len(data)}
|
|
49
|
+
def manifest(config, layers, **properties):
|
|
50
|
+
media = oci + 'manifest.v1+json'
|
|
51
|
+
return blob(media, {'schemaVersion': 2, 'mediaType': media, 'config': config, 'layers': layers, **properties})
|
|
52
|
+
|
|
53
|
+
payload = b'platform copy test\n'
|
|
54
|
+
tar = io.BytesIO()
|
|
55
|
+
with tarfile.open(fileobj=tar, mode='w') as archive:
|
|
56
|
+
entry = tarfile.TarInfo('fixture.txt')
|
|
57
|
+
entry.size = len(payload)
|
|
58
|
+
archive.addfile(entry, io.BytesIO(payload))
|
|
59
|
+
raw = tar.getvalue()
|
|
60
|
+
layer = blob(oci + 'layer.v1.tar+gzip', gzip.compress(raw, mtime=0))
|
|
61
|
+
images = []
|
|
62
|
+
for arch in ['amd64', 'arm64']:
|
|
63
|
+
platform = {'os': 'linux', 'architecture': arch}
|
|
64
|
+
config = blob(oci + 'config.v1+json', {**platform, 'rootfs': {'type':'layers','diff_ids':['sha256:' + hashlib.sha256(raw).hexdigest()]},
|
|
65
|
+
'config': {'Labels': {'org.opencontainers.image.version':sys.argv[2], 'org.opencontainers.image.revision':sys.argv[3]}}})
|
|
66
|
+
images.append({**manifest(config, [layer]), 'platform': platform})
|
|
67
|
+
proof = blob('application/vnd.in-toto+json', {'_type':'https://in-toto.io/Statement/v0.1', 'subject':[{'name':'fixture','digest':{'sha256':images[0]['digest'][7:]}}],
|
|
68
|
+
'predicateType':'https://slsa.dev/provenance/v0.2', 'predicate':{}})
|
|
69
|
+
unknown = {'os':'unknown', 'architecture':'unknown'}
|
|
70
|
+
config = blob('application/vnd.oci.empty.v1+json', {})
|
|
71
|
+
subject = {key: images[0][key] for key in ['mediaType', 'digest', 'size']}
|
|
72
|
+
artifact = manifest(config, [proof], artifactType='application/vnd.docker.attestation.manifest.v1+json', subject=subject)
|
|
73
|
+
attestation = {**artifact, 'platform':unknown, 'annotations':{'vnd.docker.reference.type':'attestation-manifest','vnd.docker.reference.digest':images[0]['digest']}}
|
|
74
|
+
index = {'schemaVersion':2, 'mediaType':oci+'index.v1+json', 'manifests':[*images, attestation]}
|
|
75
|
+
descriptor = blob(index['mediaType'], index)
|
|
76
|
+
(root/'oci-layout').write_text('{"imageLayoutVersion":"1.0.0"}')
|
|
77
|
+
(root/'index.json').write_bytes(encode({**index,'manifests':[{**descriptor,'annotations':{'org.opencontainers.image.ref.name':'fixture'}}]}))
|
|
78
|
+
PY
|
|
79
|
+
skopeo copy --all --preserve-digests "oci:$tmp/layout:fixture" "docker://$source_repo:$version" >/dev/null
|
|
80
|
+
|
|
81
|
+
# Read the v2 registry protocol directly for independent verification.
|
|
82
|
+
request() {
|
|
83
|
+
local repo=$1 path=$2
|
|
84
|
+
curl -fsS --cacert "$SSL_CERT_FILE" \
|
|
85
|
+
-H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json' \
|
|
86
|
+
"https://${repo%%/*}/v2/${repo#*/}/$path"
|
|
87
|
+
}
|
|
88
|
+
digest() { printf 'sha256:%s\n' "$(sha256sum "$1" | cut -d ' ' -f 1)"; }
|
|
89
|
+
request "$source_repo" "manifests/$version" > "$tmp/index"
|
|
90
|
+
index_digest=$(digest "$tmp/index")
|
|
91
|
+
runtime=$(jq -er '.manifests[] | select(.platform.architecture == "amd64") | .digest' "$tmp/index")
|
|
92
|
+
other=$(jq -er '.manifests[] | select(.platform.architecture == "arm64") | .digest' "$tmp/index")
|
|
93
|
+
proof=$(jq -er --arg runtime "$runtime" '.manifests[] | select(.annotations["vnd.docker.reference.type"] == "attestation-manifest" and .annotations["vnd.docker.reference.digest"] == $runtime) | .digest' "$tmp/index")
|
|
94
|
+
request "$source_repo" "manifests/$runtime" > "$tmp/runtime"
|
|
95
|
+
for tag in "$version" latest; do
|
|
96
|
+
"$here/copy-acr-platform-image.sh" "$source_repo" "$index_digest" "$target_repo" "$tag" "$revision" "$version"
|
|
97
|
+
request "$target_repo" "manifests/$tag" > "$tmp/published"
|
|
98
|
+
cmp "$tmp/runtime" "$tmp/published"
|
|
99
|
+
for blob in $(jq -r '.config.digest, .layers[].digest' "$tmp/runtime"); do
|
|
100
|
+
request "$target_repo" "blobs/$blob" > "$tmp/blob"
|
|
101
|
+
[[ $(digest "$tmp/blob") == "$blob" ]]
|
|
102
|
+
done
|
|
103
|
+
done
|
|
104
|
+
# Existing single-platform Docker schema 2 images must also copy unchanged.
|
|
105
|
+
skopeo copy --format v2s2 "docker://$source_repo@$runtime" "docker://$source_repo:legacy" >/dev/null
|
|
106
|
+
request "$source_repo" manifests/legacy > "$tmp/legacy"
|
|
107
|
+
jq -e '.mediaType == "application/vnd.docker.distribution.manifest.v2+json"' "$tmp/legacy" >/dev/null
|
|
108
|
+
"$here/copy-acr-platform-image.sh" "$source_repo" "$(digest "$tmp/legacy")" "$target_repo" legacy "$revision" "$version"
|
|
109
|
+
request "$target_repo" manifests/legacy > "$tmp/published"
|
|
110
|
+
cmp "$tmp/legacy" "$tmp/published"
|
|
111
|
+
|
|
112
|
+
for scenario in wrong-platform wrong-revision wrong-version; do
|
|
113
|
+
input=$index_digest want_revision=$revision want_version=$version
|
|
114
|
+
case "$scenario" in
|
|
115
|
+
wrong-platform) input=$other ;;
|
|
116
|
+
wrong-revision) want_revision=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ;;
|
|
117
|
+
wrong-version) want_version=v2.0.0 ;;
|
|
118
|
+
esac
|
|
119
|
+
if "$here/copy-acr-platform-image.sh" "$source_repo" "$input" "$target_repo" "$scenario" "$want_revision" "$want_version"; then
|
|
120
|
+
echo "Unexpectedly accepted $scenario" >&2; exit 1
|
|
121
|
+
fi
|
|
122
|
+
done
|
|
123
|
+
request "$target_repo" tags/list | jq -e --arg version "$version" '.tags | sort == ([$version, "latest", "legacy"] | sort)' >/dev/null
|
|
124
|
+
for absent in "$index_digest" "$proof" "$other"; do
|
|
125
|
+
status=$(curl -sS --cacert "$SSL_CERT_FILE" -o /dev/null -w '%{http_code}' \
|
|
126
|
+
-H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json' \
|
|
127
|
+
"https://${target_repo%%/*}/v2/${target_repo#*/}/manifests/$absent")
|
|
128
|
+
[[ $status == 404 ]] || { echo "Unexpected destination response for $absent: $status" >&2; exit 1; }
|
|
129
|
+
done
|
|
130
|
+
request "$source_repo" "manifests/$version" > "$tmp/after"
|
|
131
|
+
cmp "$tmp/index" "$tmp/after"
|
|
132
|
+
request "$source_repo" "manifests/$proof" > "$tmp/attestation"
|
|
133
|
+
[[ $(digest "$tmp/attestation") == "$proof" ]]
|
|
134
|
+
jq -e --arg runtime "$runtime" '.config.mediaType == "application/vnd.oci.empty.v1+json" and
|
|
135
|
+
.artifactType == "application/vnd.docker.attestation.manifest.v1+json" and .subject.digest == $runtime' "$tmp/attestation" >/dev/null
|
|
136
|
+
request "$source_repo" "blobs/$(jq -er '.layers[0].digest' "$tmp/attestation")" | jq -e '.predicateType | startswith("https://slsa.dev/provenance/")' >/dev/null
|
|
137
|
+
# Recovery must leave an existing full index intact when its fallback is flattened.
|
|
138
|
+
restored=$("$here/restore-ghcr-version.sh" "$target_repo" "$source_repo" "$version")
|
|
139
|
+
[[ $restored == "$index_digest" ]]
|
|
140
|
+
request "$source_repo" "manifests/$version" > "$tmp/recovered"
|
|
141
|
+
cmp "$tmp/index" "$tmp/recovered"
|
|
142
|
+
# A historical fallback may itself be an index. Seed an existing repository missing this version.
|
|
143
|
+
recovery_repo="${target_repo%%/*}/test/recovery"
|
|
144
|
+
skopeo copy --preserve-digests "docker://$source_repo@$runtime" "docker://$recovery_repo:prior" >/dev/null
|
|
145
|
+
restored=$("$here/restore-ghcr-version.sh" "$source_repo" "$recovery_repo" "$version")
|
|
146
|
+
[[ $restored == "$index_digest" ]]
|
|
147
|
+
request "$recovery_repo" "manifests/$version" > "$tmp/recovered"
|
|
148
|
+
cmp "$tmp/index" "$tmp/recovered"
|
|
149
|
+
request "$recovery_repo" "manifests/$proof" > "$tmp/recovered"
|
|
150
|
+
cmp "$tmp/attestation" "$tmp/recovered"
|
|
151
|
+
printf 'PASS: source index %s and attestation %s retained; target %s and latest share runnable %s; legacy, rejection and recovery checks passed\n' \
|
|
152
|
+
"$index_digest" "$proof" "$version" "$runtime"
|
|
@@ -153,6 +153,14 @@ const requiredFiles = [
|
|
|
153
153
|
'docs/RELEASE_NOTES_v0.10.1.en.md',
|
|
154
154
|
'docs/UPGRADE_v0.10.1.md',
|
|
155
155
|
'docs/UPGRADE_v0.10.1.en.md',
|
|
156
|
+
'docs/RELEASE_NOTES_v0.11.1.md',
|
|
157
|
+
'docs/RELEASE_NOTES_v0.11.1.en.md',
|
|
158
|
+
'docs/UPGRADE_v0.11.1.md',
|
|
159
|
+
'docs/UPGRADE_v0.11.1.en.md',
|
|
160
|
+
'docs/RELEASE_NOTES_v0.11.0.md',
|
|
161
|
+
'docs/RELEASE_NOTES_v0.11.0.en.md',
|
|
162
|
+
'docs/UPGRADE_v0.11.0.md',
|
|
163
|
+
'docs/UPGRADE_v0.11.0.en.md',
|
|
156
164
|
'docs/RELEASE_NOTES_v0.6.1.md',
|
|
157
165
|
'docs/RELEASE_NOTES_v0.6.0.md',
|
|
158
166
|
'docs/CHANGELOG.md',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import test from 'node:test';
|
|
3
|
-
import {
|
|
3
|
+
import { jobStatusLabel } from '../../../web-admin/src/task-trace-presentation';
|
|
4
|
+
import { runFilterParams, patchTaskQuery, readOutboxLocation, readRunFilters, readRunsLocation, RUN_FILTER_STATUSES, runsTabQuery, safeTaskReturnPath } from '../../../web-admin/src/task-page-location';
|
|
4
5
|
|
|
5
6
|
test('task tabs restore canonical and legacy links without a job stealing an explicit delivery tab', () => {
|
|
6
7
|
assert.equal(readRunsLocation({ tab: 'outbox', job: 'original' }).tab, 'notifications');
|
|
@@ -37,28 +38,15 @@ test('job filters accept the actual job status contract and keep diagnostic and
|
|
|
37
38
|
assert.deepEqual(readRunFilters(query), { status: '', route: 'orders', period: '7d' });
|
|
38
39
|
assert.equal(query.detail, 'original-job'); assert.equal(query.return_to, '/diagnostics'); assert.equal(query.future, 'kept');
|
|
39
40
|
});
|
|
40
|
-
test('
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{ id: 'wrong-status', status: 'done', route_key: 'orders', created_at: '2026-10-21T00:00:00Z' },
|
|
46
|
-
{ id: 'old', status: 'error', route_key: 'orders', created_at: '2026-10-10T00:00:00Z' },
|
|
47
|
-
];
|
|
48
|
-
const found = filterLoadedRuns(rows, { status: 'error', route: 'orders', period: '24h' }, Date.parse('2026-10-21T10:00:00Z'));
|
|
49
|
-
assert.deepEqual(found.map(row => row.id), ['match']);
|
|
50
|
-
assert.equal(rows.length, 5, 'filtering does not mutate or replace the loaded snapshot');
|
|
51
|
-
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: 'all' }, 0), rows);
|
|
41
|
+
test('dispatch filters are sent to the server, including routes outside the loaded page', () => {
|
|
42
|
+
const filters = readRunFilters({ run_status: 'error', run_route: 'orders & returns', run_period: '24h' });
|
|
43
|
+
assert.deepEqual(Object.fromEntries(runFilterParams(filters)), { status: 'error', route_key: 'orders & returns', period: '24h' });
|
|
44
|
+
assert.equal(runFilterParams(readRunFilters({})).toString(), '');
|
|
45
|
+
assert.deepEqual(Object.fromEntries(runFilterParams(readRunFilters({ run_period: '7d' }))), { period: '7d' });
|
|
52
46
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{ id: 'older', created_at: new Date(now - 7 * 86400000 - 1).toISOString() },
|
|
59
|
-
{ id: 'future', created_at: new Date(now + 1).toISOString() },
|
|
60
|
-
{ id: 'invalid', created_at: 'unknown' },
|
|
61
|
-
];
|
|
62
|
-
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: '24h' }, now).map(row => row.id), ['24h']);
|
|
63
|
-
assert.deepEqual(filterLoadedRuns(rows, { status: '', route: '', period: '7d' }, now).map(row => row.id), ['24h', '7d']);
|
|
47
|
+
|
|
48
|
+
test('job status labels cover the job lifecycle and preserve unknown raw values', () => {
|
|
49
|
+
assert.deepEqual(RUN_FILTER_STATUSES.map(jobStatusLabel), ['等待执行', '执行中', '已派发', '已完成', '执行错误', '已拒绝']);
|
|
50
|
+
for (const status of [undefined, null, ' ', '']) assert.equal(jobStatusLabel(status), '未记录');
|
|
51
|
+
for (const status of ['paused', 'completed', 'constructor', 'toString', '__proto__']) assert.equal(jobStatusLabel(status), status);
|
|
64
52
|
});
|
|
@@ -27,15 +27,15 @@ function usableDbCredential(c: Credential | null): ResolvedLlmCredential | null
|
|
|
27
27
|
export async function resolveLlmCredential(
|
|
28
28
|
name: string,
|
|
29
29
|
cfg: Pick<AppConfig, 'llmCredentials'>,
|
|
30
|
-
store?: CredentialStoreLike | null,
|
|
30
|
+
store?: (Pick<CredentialStoreLike, 'get'> & Partial<Pick<CredentialStoreLike, 'touch'>>) | null,
|
|
31
31
|
): Promise<ResolvedCredentialRef | null> {
|
|
32
32
|
const credName = String(name ?? '').trim();
|
|
33
33
|
if (!credName) return null;
|
|
34
|
-
const fileCred = cfg.llmCredentials[credName]
|
|
34
|
+
const fileCred = Object.hasOwn(cfg.llmCredentials, credName) ? cfg.llmCredentials[credName] : undefined;
|
|
35
35
|
if (fileCred) return { name: credName, source: 'config', credential: fileCred };
|
|
36
36
|
const dbCred = usableDbCredential(store ? await store.get(credName).catch(() => null) : null);
|
|
37
37
|
if (!dbCred) return null;
|
|
38
|
-
void store?.touch(credName).catch(() => { /* 观测字段 */ });
|
|
38
|
+
void store?.touch?.(credName).catch(() => { /* 观测字段 */ });
|
|
39
39
|
return { name: credName, source: 'db', credential: dbCred };
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -68,6 +68,35 @@ test('full visible events are stored once, paginated without truncation, and lin
|
|
|
68
68
|
for (const id of [AUDIT_SESSION_A, AUDIT_SESSION_B]) assert.ok(fx.queries.slice(0, writeIndex).some(({ sql, params, transactional }) => sql.includes('FROM bz_agent_sessions') && sql.includes('FOR UPDATE') && params[0] === id && transactional));
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
+
test('admin titles take a bounded preview from the first user message of each exact archive', async () => {
|
|
72
|
+
const fx = conversationAuditFixture();
|
|
73
|
+
const first = await fx.ready();
|
|
74
|
+
const input = fx.input({ client_archive_id: '423e4567-e89b-42d3-a456-426614174001' });
|
|
75
|
+
const other = await fx.repo.create(fx.auth(), input);
|
|
76
|
+
await fx.repo.confirm(fx.auth(AUDIT_SESSION_B), other.conversation_id);
|
|
77
|
+
const turn = { client_turn_id: 'turn-1' };
|
|
78
|
+
const start = { ...turn, sequence: 1, event_id: 'start', kind: 'turn_start' as const };
|
|
79
|
+
const assistant = { ...turn, sequence: 2, event_id: 'reply', kind: 'assistant_message' as const, content: 'Assistant-only record' };
|
|
80
|
+
const preview = '门'.repeat(95) + '🚀';
|
|
81
|
+
await fx.repo.append(fx.auth(), first.conversation_id, [
|
|
82
|
+
start, assistant, { ...turn, sequence: 3, event_id: 'user-1', kind: 'user_message', content: preview + 'TAIL' },
|
|
83
|
+
{ ...turn, sequence: 4, event_id: 'user-2', kind: 'user_message', content: 'Later message' },
|
|
84
|
+
]);
|
|
85
|
+
await fx.repo.append(fx.auth(), other.conversation_id, [start, assistant]);
|
|
86
|
+
|
|
87
|
+
const queryCount = fx.queries.length;
|
|
88
|
+
const list = await fx.repo.listForAdmin();
|
|
89
|
+
assert.equal(fx.queries.length - queryCount, 1);
|
|
90
|
+
assert.deepEqual(new Map(list.items.map((row: any) => [row.conversation_id, row.first_user_preview])), new Map([
|
|
91
|
+
[first.conversation_id, preview], [other.conversation_id, null],
|
|
92
|
+
]));
|
|
93
|
+
const afterUser = await fx.repo.detailForAdmin(first.conversation_id, 3, 1);
|
|
94
|
+
assert.equal(afterUser!.conversation.first_user_preview, preview);
|
|
95
|
+
assert.equal(afterUser!.events[0].content, 'Later message');
|
|
96
|
+
const retry = await fx.repo.create(fx.auth(), fx.input());
|
|
97
|
+
assert.ok(!Object.hasOwn(retry, 'first_user_preview'));
|
|
98
|
+
});
|
|
99
|
+
|
|
71
100
|
test('changed retries, gaps and event-id reuse fail atomically', async () => {
|
|
72
101
|
const fx = conversationAuditFixture();
|
|
73
102
|
const created = await fx.ready();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { CHANNEL_DELIVERY_MESSAGE_SQL } from './conversation-delivery-message';
|
|
2
3
|
import { dt, rowClient, rowRoute } from '../../core/config/config-codec';
|
|
3
4
|
import type { AgentSession, Client, Route } from '../../core/contracts/types';
|
|
4
5
|
import {
|
|
5
|
-
assertAuditMemberActive, auditError, auditHash, auditIdentityHash,
|
|
6
|
+
assertAuditMemberActive, auditError, auditHash, auditIdentityHash, auditUuid, ConversationAuditError,
|
|
6
7
|
CONVERSATION_AUDIT_MAX_BYTES, CONVERSATION_AUDIT_MAX_EVENTS,
|
|
7
8
|
type CreateConversationAuditInput, type ConversationAuditEventInput,
|
|
8
9
|
type CreateCrossBindingConversationAuditInput,
|
|
@@ -10,6 +11,22 @@ import {
|
|
|
10
11
|
|
|
11
12
|
type Auth = { session: AgentSession; client: Client };
|
|
12
13
|
type Row = Record<string, any>;
|
|
14
|
+
export const ADMIN_CONVERSATION_SOURCES = ['all', 'client', 'web', 'wecom', 'delivery', 'other'] as const;
|
|
15
|
+
export type AdminConversationSource = (typeof ADMIN_CONVERSATION_SOURCES)[number];
|
|
16
|
+
type FeedCursor = { at: Date; kind: 'audit' | 'thread'; id: number | string; position: number };
|
|
17
|
+
|
|
18
|
+
function readFeedCursor(raw: string, source: AdminConversationSource): FeedCursor {
|
|
19
|
+
const parts = raw.split('|');
|
|
20
|
+
const [issuedFor, time, kind, id, position] = parts;
|
|
21
|
+
const at = new Date(time ?? '');
|
|
22
|
+
if (parts.length !== 5 || issuedFor !== source || !time || !Number.isFinite(at.getTime()) ||
|
|
23
|
+
at.toISOString() !== time || !position || !/^\d+$/.test(position) || !Number.isSafeInteger(Number(position)) ||
|
|
24
|
+
!id || (kind !== 'audit' && (kind !== 'thread' || !/^[1-9]\d*$/.test(id) || !Number.isSafeInteger(Number(id))))) {
|
|
25
|
+
throw new ConversationAuditError(400, 'invalid_request', 'Invalid conversation feed cursor.');
|
|
26
|
+
}
|
|
27
|
+
return { at, kind, id: kind === 'audit' ? auditUuid(id) : Number(id), position: Number(position) };
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
const SESSION_COLUMNS = 'session_id,client_app_id,device_label,principal_json,on_behalf_of,allowed_routes,created_at,access_expires_at,refresh_expires_at,revoked_at';
|
|
14
31
|
|
|
15
32
|
function json(value: unknown): any {
|
|
@@ -39,6 +56,18 @@ function head(row: Row): Row {
|
|
|
39
56
|
};
|
|
40
57
|
}
|
|
41
58
|
|
|
59
|
+
// Admin-only projection. The primary key (conversation_id, sequence) scopes the
|
|
60
|
+
// lookup to this archive and orders it in the same sequence as the transcript.
|
|
61
|
+
const ADMIN_HEAD_COLUMNS = `a.*, (
|
|
62
|
+
SELECT LEFT(e.content, 96) FROM bz_agent_conversation_events e
|
|
63
|
+
WHERE e.conversation_id = a.conversation_id AND e.kind = 'user_message'
|
|
64
|
+
ORDER BY e.sequence LIMIT 1
|
|
65
|
+
) AS first_user_preview`;
|
|
66
|
+
|
|
67
|
+
function adminHead(row: Row): Row {
|
|
68
|
+
return { ...head(row), first_user_preview: row.first_user_preview ?? null };
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
function eventView(row: Row): Row {
|
|
43
72
|
return {
|
|
44
73
|
event_id: row.event_id, sequence: Number(row.sequence), client_turn_id: row.client_turn_id, kind: row.kind,
|
|
@@ -324,28 +353,132 @@ export class AgentConversationAuditRepository {
|
|
|
324
353
|
async listForAdmin(limit = 50, offset = 0): Promise<Row> {
|
|
325
354
|
const n = Math.min(Math.max(Math.floor(limit) || 50, 1), 100);
|
|
326
355
|
const off = Math.max(Math.floor(offset) || 0, 0);
|
|
327
|
-
const [rows] = await this.pool.query(
|
|
328
|
-
|
|
356
|
+
const [rows] = await this.pool.query(`SELECT ${ADMIN_HEAD_COLUMNS} FROM (
|
|
357
|
+
SELECT conversation_id, updated_at FROM bz_agent_conversation_audits
|
|
358
|
+
ORDER BY updated_at DESC, conversation_id DESC LIMIT ? OFFSET ?
|
|
359
|
+
) page JOIN bz_agent_conversation_audits a ON a.conversation_id = page.conversation_id
|
|
360
|
+
ORDER BY page.updated_at DESC, page.conversation_id DESC`, [n + 1, off]);
|
|
361
|
+
const items = (rows as Row[]).slice(0, n).map(adminHead);
|
|
329
362
|
return { items, has_more: rows.length > n, next_offset: rows.length > n ? off + n : null };
|
|
330
363
|
}
|
|
331
364
|
|
|
332
|
-
|
|
333
|
-
|
|
365
|
+
/** Read-only union of client archives, independent inbound threads and delivery-only threads. */
|
|
366
|
+
async listFeedForAdmin(source: AdminConversationSource, limit = 50, offset = 0, after?: string): Promise<Row> {
|
|
367
|
+
const n = Math.min(Math.max(Math.floor(limit) || 50, 1), 100);
|
|
368
|
+
const off = Math.max(Math.floor(offset) || 0, 0);
|
|
369
|
+
const cursor = after === undefined ? null : readFeedCursor(after, source);
|
|
370
|
+
if (cursor && off) throw new ConversationAuditError(400, 'invalid_request', 'Choose cursor or offset pagination.');
|
|
371
|
+
const candidateLimit = Math.min(Number.MAX_SAFE_INTEGER, off + n + 1);
|
|
372
|
+
// At identical times archives precede threads; within each kind IDs descend.
|
|
373
|
+
let archiveWindow = '', threadWindow = '';
|
|
374
|
+
const archiveArgs: unknown[] = [], threadArgs: unknown[] = [];
|
|
375
|
+
if (cursor?.kind === 'audit') {
|
|
376
|
+
archiveWindow = ' AND (a.updated_at, a.conversation_id) < (?, ?)';
|
|
377
|
+
archiveArgs.push(cursor.at, cursor.id);
|
|
378
|
+
threadWindow = ' AND t.last_active_at <= ?';
|
|
379
|
+
threadArgs.push(cursor.at);
|
|
380
|
+
} else if (cursor) {
|
|
381
|
+
archiveWindow = ' AND a.updated_at < ?';
|
|
382
|
+
archiveArgs.push(cursor.at);
|
|
383
|
+
threadWindow = ' AND (t.last_active_at, t.thread_id) < (?, ?)';
|
|
384
|
+
threadArgs.push(cursor.at, cursor.id);
|
|
385
|
+
}
|
|
386
|
+
// Thread identity is not a substitute for a run link. A thread can contain a
|
|
387
|
+
// mixture of archived and unarchived runs. Keep it if any incoming message
|
|
388
|
+
// remains independent; use that message for its title and channel.
|
|
389
|
+
const [rows] = await this.pool.query(`WITH candidates AS (
|
|
390
|
+
(SELECT 'audit' AS kind, 'client' AS source, a.conversation_id, NULL AS thread_id,
|
|
391
|
+
NULL AS first_message_id, a.updated_at
|
|
392
|
+
FROM bz_agent_conversation_audits a WHERE ? IN ('all','client')${archiveWindow}
|
|
393
|
+
ORDER BY a.updated_at DESC, a.conversation_id DESC LIMIT ?)
|
|
394
|
+
UNION ALL
|
|
395
|
+
(SELECT 'thread' AS kind, CASE
|
|
396
|
+
WHEN first_message.channel LIKE 'agent:%' THEN 'client'
|
|
397
|
+
WHEN first_message.channel LIKE 'chat:%' THEN 'web'
|
|
398
|
+
WHEN first_message.channel LIKE 'wecom:%' THEN 'wecom'
|
|
399
|
+
ELSE 'other' END AS source,
|
|
400
|
+
NULL AS conversation_id, t.thread_id, first_message.id AS first_message_id, t.last_active_at AS updated_at
|
|
401
|
+
FROM bz_threads t JOIN bz_messages first_message ON first_message.id=(
|
|
402
|
+
SELECT m.id FROM bz_messages m FORCE INDEX (idx_thread)
|
|
403
|
+
WHERE m.thread_id=t.thread_id AND m.direction='in'
|
|
404
|
+
AND (m.agent_run_id IS NULL OR NOT EXISTS (SELECT 1 FROM bz_agent_conversation_events e
|
|
405
|
+
WHERE e.run_id=m.agent_run_id AND e.thread_id=m.thread_id AND e.kind='run_link'))
|
|
406
|
+
ORDER BY m.id LIMIT 1)
|
|
407
|
+
WHERE ? <> 'delivery'${threadWindow}
|
|
408
|
+
HAVING ?='all' OR source=?
|
|
409
|
+
ORDER BY t.last_active_at DESC, t.thread_id DESC LIMIT ?)
|
|
410
|
+
UNION ALL
|
|
411
|
+
(SELECT 'thread' AS kind, 'delivery' AS source, NULL AS conversation_id, t.thread_id,
|
|
412
|
+
(SELECT m.id FROM bz_messages m FORCE INDEX (idx_thread)
|
|
413
|
+
WHERE m.thread_id=t.thread_id AND ${CHANNEL_DELIVERY_MESSAGE_SQL}
|
|
414
|
+
ORDER BY m.id LIMIT 1) AS first_message_id, t.last_active_at AS updated_at
|
|
415
|
+
FROM bz_threads t
|
|
416
|
+
WHERE ? IN ('all','delivery')${threadWindow}
|
|
417
|
+
AND NOT EXISTS (SELECT 1 FROM bz_messages inbound WHERE inbound.thread_id=t.thread_id AND inbound.direction='in')
|
|
418
|
+
HAVING first_message_id IS NOT NULL
|
|
419
|
+
ORDER BY t.last_active_at DESC, t.thread_id DESC LIMIT ?)
|
|
420
|
+
), page AS (
|
|
421
|
+
SELECT * FROM candidates ORDER BY updated_at DESC, kind ASC, conversation_id DESC, thread_id DESC LIMIT ? OFFSET ?
|
|
422
|
+
)
|
|
423
|
+
SELECT p.kind, p.source, p.conversation_id, p.thread_id, p.updated_at,
|
|
424
|
+
CASE WHEN p.kind='audit' THEN (
|
|
425
|
+
SELECT LEFT(e.content,96) FROM bz_agent_conversation_events e
|
|
426
|
+
WHERE e.conversation_id=p.conversation_id AND e.kind='user_message' ORDER BY e.sequence LIMIT 1
|
|
427
|
+
) ELSE LEFT(m.content,96) END AS title,
|
|
428
|
+
CASE WHEN p.source='delivery' THEN
|
|
429
|
+
CASE WHEN t.scope_key LIKE 'wecom:%:%' THEN SUBSTRING_INDEX(SUBSTRING(t.scope_key,7),':',1)
|
|
430
|
+
ELSE '' END
|
|
431
|
+
ELSE COALESCE(a.client_app_id, ce.name, c.name, m.channel) END AS source_label,
|
|
432
|
+
COALESCE(a.route_key,t.route_key) AS route_key, COALESCE(a.message_count,t.message_count) AS message_count,
|
|
433
|
+
a.turn_count, a.last_turn_status, a.state, a.client_conversation_id,
|
|
434
|
+
COALESCE(a.client_app_id, c.app_id, IF(p.source='client', SUBSTRING(m.channel,7), NULL)) AS client_app_id
|
|
435
|
+
FROM page p
|
|
436
|
+
LEFT JOIN bz_agent_conversation_audits a ON a.conversation_id=p.conversation_id
|
|
437
|
+
LEFT JOIN bz_threads t ON t.thread_id=p.thread_id
|
|
438
|
+
LEFT JOIN bz_messages m ON m.id=p.first_message_id
|
|
439
|
+
LEFT JOIN bz_chat_entries ce ON p.source='web' AND ce.entry_key=SUBSTRING(m.channel,6)
|
|
440
|
+
LEFT JOIN bz_clients c ON p.kind='thread' AND p.source IN ('client','other')
|
|
441
|
+
AND c.app_id=IF(p.source='client', SUBSTRING(m.channel,7), m.channel)
|
|
442
|
+
ORDER BY p.updated_at DESC, p.kind ASC, p.conversation_id DESC, p.thread_id DESC`,
|
|
443
|
+
[source, ...archiveArgs, candidateLimit, source, ...threadArgs, source, source, candidateLimit,
|
|
444
|
+
source, ...threadArgs, candidateLimit, n + 1, off]);
|
|
445
|
+
const items: Row[] = (rows as Row[]).slice(0, n).map(row => ({
|
|
446
|
+
...row, thread_id: row.thread_id == null ? null : Number(row.thread_id),
|
|
447
|
+
updated_at: iso(row.updated_at), message_count: Number(row.message_count),
|
|
448
|
+
turn_count: row.turn_count == null ? null : Number(row.turn_count),
|
|
449
|
+
}));
|
|
450
|
+
const last = items.at(-1);
|
|
451
|
+
const nextOffset = rows.length > n ? (cursor?.position ?? off) + n : null;
|
|
452
|
+
return { items, has_more: nextOffset !== null, next_offset: nextOffset,
|
|
453
|
+
next_cursor: nextOffset !== null && last
|
|
454
|
+
? [source, last.updated_at, last.kind, last.conversation_id ?? last.thread_id, nextOffset].join('|') : null };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async detailForAdmin(conversationId: string, afterSequence = 0, limit = 100, beforeSequence?: number | null): Promise<Row | null> {
|
|
458
|
+
const [rows] = await this.pool.query(`SELECT ${ADMIN_HEAD_COLUMNS} FROM bz_agent_conversation_audits a WHERE a.conversation_id=?`, [conversationId]);
|
|
334
459
|
if (!rows[0]) return null;
|
|
335
460
|
const n = Math.min(Math.max(Math.floor(limit) || 100, 1), 200);
|
|
336
461
|
const after = Math.max(Math.floor(afterSequence) || 0, 0);
|
|
337
462
|
const [members] = await this.pool.query('SELECT * FROM bz_agent_conversation_members WHERE conversation_id=? ORDER BY session_id', [conversationId]);
|
|
338
|
-
const
|
|
463
|
+
const backward = beforeSequence !== undefined;
|
|
464
|
+
const [rowsOfEvents] = backward
|
|
465
|
+
? await this.pool.query('SELECT * FROM bz_agent_conversation_events WHERE conversation_id=? AND sequence<? ORDER BY sequence DESC LIMIT ?',
|
|
466
|
+
[conversationId, beforeSequence ?? Number(rows[0].last_sequence) + 1, n + 1])
|
|
467
|
+
: await this.pool.query('SELECT * FROM bz_agent_conversation_events WHERE conversation_id=? AND sequence>? ORDER BY sequence LIMIT ?', [conversationId, after, n + 1]);
|
|
468
|
+
const hasMore = rowsOfEvents.length > n;
|
|
339
469
|
const events = (rowsOfEvents as Row[]).slice(0, n).map(eventView);
|
|
470
|
+
if (backward) events.reverse();
|
|
340
471
|
return {
|
|
341
|
-
conversation:
|
|
472
|
+
conversation: adminHead(rows[0]), members: (members as Row[]).map((member) => ({
|
|
342
473
|
session_id: member.session_id, display_label: member.display_label, confirmed: Boolean(member.confirmed_at),
|
|
343
474
|
...(Number(rows[0].membership_version) === 2 ? {
|
|
344
475
|
client_app_id: member.client_app_id, client_name: member.client_name, route_key: member.route_key,
|
|
345
476
|
} : {}),
|
|
346
477
|
...(member.confirmed_at ? { principal: json(member.principal_json), on_behalf_of: member.on_behalf_of } : {}),
|
|
347
|
-
})), events,
|
|
348
|
-
|
|
478
|
+
})), events,
|
|
479
|
+
...(backward
|
|
480
|
+
? { has_earlier: hasMore, next_before_sequence: hasMore ? events[0]!.sequence : null }
|
|
481
|
+
: { has_more: hasMore, next_after_sequence: events.length ? events.at(-1)!.sequence : after }),
|
|
349
482
|
};
|
|
350
483
|
}
|
|
351
484
|
|