-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclass-wp-agent-message-idempotency.php
More file actions
69 lines (60 loc) · 1.99 KB
/
Copy pathclass-wp-agent-message-idempotency.php
File metadata and controls
69 lines (60 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Inbound message idempotency facade.
*
* @package AgentsAPI
* @since 0.103.0
*/
namespace AgentsAPI\AI\Channels;
defined( 'ABSPATH' ) || exit;
final class WP_Agent_Message_Idempotency {
private static ?WP_Agent_Message_Idempotency_Store $store = null;
/**
* Replace the backing store. Pass null to restore the transient default.
*
* @param WP_Agent_Message_Idempotency_Store|null $store Store implementation.
*/
public static function set_store( ?WP_Agent_Message_Idempotency_Store $store ): void {
self::$store = $store;
}
/**
* Return the active backing store.
*
* @return WP_Agent_Message_Idempotency_Store
*/
public static function store(): WP_Agent_Message_Idempotency_Store {
if ( null === self::$store ) {
self::$store = new WP_Agent_Transient_Message_Idempotency_Store();
}
return self::$store;
}
/**
* Whether an inbound external message has already been processed.
*
* @param string $provider External provider or connector scope.
* @param string $message_id Opaque provider message id.
* @return bool True when the message was already marked seen.
*/
public static function seen( string $provider, string $message_id ): bool {
return self::store()->seen( $provider, $message_id );
}
/**
* Mark an inbound external message as processed for a bounded time.
*
* @param string $provider External provider or connector scope.
* @param string $message_id Opaque provider message id.
* @param int $ttl Time-to-live in seconds.
*/
public static function mark_seen( string $provider, string $message_id, int $ttl ): void {
self::store()->mark_seen( $provider, $message_id, $ttl );
}
/**
* Remove a processed marker, primarily for tests and manual recovery.
*
* @param string $provider External provider or connector scope.
* @param string $message_id Opaque provider message id.
*/
public static function forget( string $provider, string $message_id ): void {
self::store()->forget( $provider, $message_id );
}
}