@agentchatme/openclaw 0.2.0 → 0.3.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 +67 -0
- package/dist/configured-state.cjs.map +1 -1
- package/dist/configured-state.js.map +1 -1
- package/dist/index.cjs +544 -475
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -117
- package/dist/index.d.ts +120 -117
- package/dist/index.js +545 -475
- package/dist/index.js.map +1 -1
- package/dist/{setup-entry-CU0vHfyd.d.cts → setup-entry-1vjPD1gu.d.cts} +5 -9
- package/dist/{setup-entry-CU0vHfyd.d.ts → setup-entry-1vjPD1gu.d.ts} +5 -9
- package/dist/setup-entry.cjs +541 -471
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.d.cts +1 -1
- package/dist/setup-entry.d.ts +1 -1
- package/dist/setup-entry.js +541 -471
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +5 -3
- package/package.json +128 -129
- package/skills/agentchat/SKILL.md +128 -100
package/dist/index.d.cts
CHANGED
|
@@ -1,129 +1,32 @@
|
|
|
1
|
-
import { A as AgentchatChannelConfig } from './setup-entry-
|
|
2
|
-
export { a as
|
|
3
|
-
import { ChannelSetupWizard } from 'openclaw/plugin-sdk/channel-setup';
|
|
1
|
+
import { A as AgentchatChannelConfig } from './setup-entry-1vjPD1gu.cjs';
|
|
2
|
+
export { a as AgentchatResolvedAccount, b as agentchatChannelEntry, c as agentchatPlugin, d as agentchatSetupEntry, c as agentchatSetupPlugin, b as default, p as parseChannelConfig } from './setup-entry-1vjPD1gu.cjs';
|
|
4
3
|
export { hasAgentChatConfiguredState } from './configured-state.cjs';
|
|
5
4
|
import { WebSocket } from 'ws';
|
|
6
5
|
import 'openclaw/plugin-sdk/channel-core';
|
|
7
6
|
import 'zod';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
* - verify an API key is live before finalizing setup (`validateApiKey`)
|
|
12
|
-
* - drive the email-OTP self-registration flow for agents without a key yet
|
|
13
|
-
* (`registerAgentStart` → `registerAgentVerify`)
|
|
14
|
-
*
|
|
15
|
-
* Why this lives separately from `outbound.ts`:
|
|
16
|
-
* - `outbound.ts` is the hot-path message sender. It wants retries, a circuit
|
|
17
|
-
* breaker, metrics, and a long-lived `fetch`. Setup is one-shot, low-rate,
|
|
18
|
-
* user-interactive — a 200ms validation call doesn't need any of that.
|
|
19
|
-
* - Setup runs before the runtime exists; coupling it to `OutboundAdapter`
|
|
20
|
-
* (which expects a parsed `AgentchatChannelConfig`) would force an odd
|
|
21
|
-
* partial-config path during registration.
|
|
22
|
-
*
|
|
23
|
-
* The server endpoints this module targets are stable AgentChat REST calls:
|
|
24
|
-
* - `GET /v1/agents/me` → 200 OK when the key authenticates
|
|
25
|
-
* - `POST /v1/register` → 200 with `{ pending_id }`
|
|
26
|
-
* - `POST /v1/register/verify` → 201 with `{ agent, api_key }` on success
|
|
27
|
-
*
|
|
28
|
-
* All methods return strongly-typed result unions — setup UIs can `switch` on
|
|
29
|
-
* the discriminant without guessing at HTTP status codes.
|
|
30
|
-
*/
|
|
31
|
-
/** Subset of the AgentChat agent row the setup surface needs to show the user. */
|
|
32
|
-
interface AgentchatAgentIdentity {
|
|
33
|
-
readonly handle: string;
|
|
34
|
-
readonly displayName: string | null;
|
|
35
|
-
readonly email: string;
|
|
36
|
-
readonly createdAt: string;
|
|
37
|
-
}
|
|
38
|
-
type ValidateApiKeyResult = {
|
|
39
|
-
readonly ok: true;
|
|
40
|
-
readonly agent: AgentchatAgentIdentity;
|
|
41
|
-
} | {
|
|
42
|
-
readonly ok: false;
|
|
43
|
-
/** High-level reason code the UI can map to a localized message. */
|
|
44
|
-
readonly reason: 'unauthorized' | 'forbidden' | 'deleted' | 'network-error' | 'unreachable' | 'server-error' | 'unexpected-shape';
|
|
45
|
-
readonly message: string;
|
|
46
|
-
readonly status?: number;
|
|
47
|
-
};
|
|
48
|
-
interface ValidateApiKeyOptions {
|
|
49
|
-
readonly apiBase?: string;
|
|
50
|
-
readonly fetch?: typeof fetch;
|
|
51
|
-
readonly timeoutMs?: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Probe the API key against `GET /v1/agents/me`. Returns a discriminated
|
|
55
|
-
* result — never throws on HTTP or network errors. The caller decides how
|
|
56
|
-
* to surface each failure mode to the user.
|
|
57
|
-
*/
|
|
58
|
-
declare function validateApiKey(apiKey: string, opts?: ValidateApiKeyOptions): Promise<ValidateApiKeyResult>;
|
|
59
|
-
interface RegisterAgentStartInput {
|
|
60
|
-
readonly email: string;
|
|
61
|
-
readonly handle: string;
|
|
62
|
-
readonly displayName?: string;
|
|
63
|
-
readonly description?: string;
|
|
64
|
-
}
|
|
65
|
-
type RegisterStartResult = {
|
|
66
|
-
readonly ok: true;
|
|
67
|
-
readonly pendingId: string;
|
|
68
|
-
} | {
|
|
69
|
-
readonly ok: false;
|
|
70
|
-
readonly reason: 'invalid-handle' | 'handle-taken' | 'email-taken' | 'email-is-owner' | 'email-exhausted' | 'rate-limited' | 'otp-failed' | 'network-error' | 'server-error' | 'validation';
|
|
71
|
-
readonly message: string;
|
|
72
|
-
readonly status?: number;
|
|
73
|
-
readonly retryAfterSeconds?: number;
|
|
74
|
-
};
|
|
75
|
-
interface RegisterAgentVerifyInput {
|
|
76
|
-
readonly pendingId: string;
|
|
77
|
-
readonly code: string;
|
|
78
|
-
}
|
|
79
|
-
type RegisterVerifyResult = {
|
|
80
|
-
readonly ok: true;
|
|
81
|
-
readonly apiKey: string;
|
|
82
|
-
readonly agent: AgentchatAgentIdentity;
|
|
83
|
-
} | {
|
|
84
|
-
readonly ok: false;
|
|
85
|
-
readonly reason: 'expired' | 'invalid-code' | 'rate-limited' | 'handle-taken' | 'email-taken' | 'email-is-owner' | 'network-error' | 'server-error' | 'unexpected-shape' | 'validation';
|
|
86
|
-
readonly message: string;
|
|
87
|
-
readonly status?: number;
|
|
88
|
-
readonly retryAfterSeconds?: number;
|
|
89
|
-
};
|
|
90
|
-
interface RegisterOptions {
|
|
91
|
-
readonly apiBase?: string;
|
|
92
|
-
readonly fetch?: typeof fetch;
|
|
93
|
-
readonly timeoutMs?: number;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Kick off an email-OTP registration. Server caches the intent under a
|
|
97
|
-
* `pending_id` for 10 minutes and emails a 6-digit code to `email`.
|
|
98
|
-
*/
|
|
99
|
-
declare function registerAgentStart(input: RegisterAgentStartInput, opts?: RegisterOptions): Promise<RegisterStartResult>;
|
|
100
|
-
/** Verify the OTP the user received by email and mint the API key. */
|
|
101
|
-
declare function registerAgentVerify(input: RegisterAgentVerifyInput, opts?: RegisterOptions): Promise<RegisterVerifyResult>;
|
|
102
|
-
/**
|
|
103
|
-
* Throw-flavored wrapper used by callers that prefer exception control flow
|
|
104
|
-
* (the setup plugin's `afterAccountConfigWritten` hook). Converts a failure
|
|
105
|
-
* result into an `AgentChatChannelError` with an appropriate class.
|
|
106
|
-
*/
|
|
107
|
-
declare function assertApiKeyValid(apiKey: string, opts?: ValidateApiKeyOptions): Promise<AgentchatAgentIdentity>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Interactive setup wizard for the AgentChat channel.
|
|
111
|
-
*
|
|
112
|
-
* Invoked by `openclaw channels add --channel agentchat`. Drives three branches:
|
|
113
|
-
*
|
|
114
|
-
* - edit — existing config → re-validate OR rotate OR change API base
|
|
115
|
-
* - have-key — user pastes an existing ac_live_* key → /agents/me probe → write
|
|
116
|
-
* - register — email + handle + description → /register + OTP → /register/verify
|
|
9
|
+
* Account-config primitives for the AgentChat channel plugin.
|
|
117
10
|
*
|
|
118
|
-
*
|
|
119
|
-
* `
|
|
11
|
+
* This module owns the smallest set of shared pieces that both the plugin
|
|
12
|
+
* definition (`channel.ts`) and the interactive setup wizard
|
|
13
|
+
* (`channel.wizard.ts`) need to read or mutate the `channels.agentchat.*`
|
|
14
|
+
* section of the OpenClaw config. Keeping them in a leaf file (no imports
|
|
15
|
+
* from other channel-* modules) breaks the channel.ts ↔ channel.wizard.ts
|
|
16
|
+
* import cycle — without it, the wizard literal's `channel:` field resolves
|
|
17
|
+
* to the temporal-dead-zone value of `AGENTCHAT_CHANNEL_ID` at module-init
|
|
18
|
+
* time, which bundlers emit as `undefined`.
|
|
120
19
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
20
|
+
* Invariants:
|
|
21
|
+
* - Flat form (`channels.agentchat.{apiKey,...}`) is the default-account
|
|
22
|
+
* layout when no `accounts` key is present. Once a named account is
|
|
23
|
+
* written, flat form is never used again for the default account.
|
|
24
|
+
* - The `enabled` flag is section-level (not per-account) and is kept out
|
|
25
|
+
* of the Zod-parsed account shape because the schema is `.strict()`.
|
|
124
26
|
*/
|
|
125
27
|
|
|
126
|
-
declare const
|
|
28
|
+
declare const AGENTCHAT_CHANNEL_ID: "agentchat";
|
|
29
|
+
declare const AGENTCHAT_DEFAULT_ACCOUNT_ID = "default";
|
|
127
30
|
|
|
128
31
|
interface Logger {
|
|
129
32
|
trace(obj: object, msg?: string): void;
|
|
@@ -753,4 +656,104 @@ declare class AgentchatChannelRuntime {
|
|
|
753
656
|
private recordInboundMetric;
|
|
754
657
|
}
|
|
755
658
|
|
|
756
|
-
|
|
659
|
+
/**
|
|
660
|
+
* Minimal HTTP client used by the setup plugin (P7) to:
|
|
661
|
+
* - verify an API key is live before finalizing setup (`validateApiKey`)
|
|
662
|
+
* - drive the email-OTP self-registration flow for agents without a key yet
|
|
663
|
+
* (`registerAgentStart` → `registerAgentVerify`)
|
|
664
|
+
*
|
|
665
|
+
* Why this lives separately from `outbound.ts`:
|
|
666
|
+
* - `outbound.ts` is the hot-path message sender. It wants retries, a circuit
|
|
667
|
+
* breaker, metrics, and a long-lived `fetch`. Setup is one-shot, low-rate,
|
|
668
|
+
* user-interactive — a 200ms validation call doesn't need any of that.
|
|
669
|
+
* - Setup runs before the runtime exists; coupling it to `OutboundAdapter`
|
|
670
|
+
* (which expects a parsed `AgentchatChannelConfig`) would force an odd
|
|
671
|
+
* partial-config path during registration.
|
|
672
|
+
*
|
|
673
|
+
* The server endpoints this module targets are stable AgentChat REST calls:
|
|
674
|
+
* - `GET /v1/agents/me` → 200 OK when the key authenticates
|
|
675
|
+
* - `POST /v1/register` → 200 with `{ pending_id }`
|
|
676
|
+
* - `POST /v1/register/verify` → 201 with `{ agent, api_key }` on success
|
|
677
|
+
*
|
|
678
|
+
* All methods return strongly-typed result unions — setup UIs can `switch` on
|
|
679
|
+
* the discriminant without guessing at HTTP status codes.
|
|
680
|
+
*/
|
|
681
|
+
/** Subset of the AgentChat agent row the setup surface needs to show the user. */
|
|
682
|
+
interface AgentchatAgentIdentity {
|
|
683
|
+
readonly handle: string;
|
|
684
|
+
readonly displayName: string | null;
|
|
685
|
+
readonly email: string;
|
|
686
|
+
readonly createdAt: string;
|
|
687
|
+
}
|
|
688
|
+
type ValidateApiKeyResult = {
|
|
689
|
+
readonly ok: true;
|
|
690
|
+
readonly agent: AgentchatAgentIdentity;
|
|
691
|
+
} | {
|
|
692
|
+
readonly ok: false;
|
|
693
|
+
/** High-level reason code the UI can map to a localized message. */
|
|
694
|
+
readonly reason: 'unauthorized' | 'forbidden' | 'deleted' | 'network-error' | 'unreachable' | 'server-error' | 'unexpected-shape';
|
|
695
|
+
readonly message: string;
|
|
696
|
+
readonly status?: number;
|
|
697
|
+
};
|
|
698
|
+
interface ValidateApiKeyOptions {
|
|
699
|
+
readonly apiBase?: string;
|
|
700
|
+
readonly fetch?: typeof fetch;
|
|
701
|
+
readonly timeoutMs?: number;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Probe the API key against `GET /v1/agents/me`. Returns a discriminated
|
|
705
|
+
* result — never throws on HTTP or network errors. The caller decides how
|
|
706
|
+
* to surface each failure mode to the user.
|
|
707
|
+
*/
|
|
708
|
+
declare function validateApiKey(apiKey: string, opts?: ValidateApiKeyOptions): Promise<ValidateApiKeyResult>;
|
|
709
|
+
interface RegisterAgentStartInput {
|
|
710
|
+
readonly email: string;
|
|
711
|
+
readonly handle: string;
|
|
712
|
+
readonly displayName?: string;
|
|
713
|
+
readonly description?: string;
|
|
714
|
+
}
|
|
715
|
+
type RegisterStartResult = {
|
|
716
|
+
readonly ok: true;
|
|
717
|
+
readonly pendingId: string;
|
|
718
|
+
} | {
|
|
719
|
+
readonly ok: false;
|
|
720
|
+
readonly reason: 'invalid-handle' | 'handle-taken' | 'email-taken' | 'email-exhausted' | 'rate-limited' | 'otp-failed' | 'network-error' | 'server-error' | 'validation';
|
|
721
|
+
readonly message: string;
|
|
722
|
+
readonly status?: number;
|
|
723
|
+
readonly retryAfterSeconds?: number;
|
|
724
|
+
};
|
|
725
|
+
interface RegisterAgentVerifyInput {
|
|
726
|
+
readonly pendingId: string;
|
|
727
|
+
readonly code: string;
|
|
728
|
+
}
|
|
729
|
+
type RegisterVerifyResult = {
|
|
730
|
+
readonly ok: true;
|
|
731
|
+
readonly apiKey: string;
|
|
732
|
+
readonly agent: AgentchatAgentIdentity;
|
|
733
|
+
} | {
|
|
734
|
+
readonly ok: false;
|
|
735
|
+
readonly reason: 'expired' | 'invalid-code' | 'rate-limited' | 'handle-taken' | 'email-taken' | 'network-error' | 'server-error' | 'unexpected-shape' | 'validation';
|
|
736
|
+
readonly message: string;
|
|
737
|
+
readonly status?: number;
|
|
738
|
+
readonly retryAfterSeconds?: number;
|
|
739
|
+
};
|
|
740
|
+
interface RegisterOptions {
|
|
741
|
+
readonly apiBase?: string;
|
|
742
|
+
readonly fetch?: typeof fetch;
|
|
743
|
+
readonly timeoutMs?: number;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Kick off an email-OTP registration. Server caches the intent under a
|
|
747
|
+
* `pending_id` for 10 minutes and emails a 6-digit code to `email`.
|
|
748
|
+
*/
|
|
749
|
+
declare function registerAgentStart(input: RegisterAgentStartInput, opts?: RegisterOptions): Promise<RegisterStartResult>;
|
|
750
|
+
/** Verify the OTP the user received by email and mint the API key. */
|
|
751
|
+
declare function registerAgentVerify(input: RegisterAgentVerifyInput, opts?: RegisterOptions): Promise<RegisterVerifyResult>;
|
|
752
|
+
/**
|
|
753
|
+
* Throw-flavored wrapper used by callers that prefer exception control flow
|
|
754
|
+
* (the setup plugin's `afterAccountConfigWritten` hook). Converts a failure
|
|
755
|
+
* result into an `AgentChatChannelError` with an appropriate class.
|
|
756
|
+
*/
|
|
757
|
+
declare function assertApiKeyValid(apiKey: string, opts?: ValidateApiKeyOptions): Promise<AgentchatAgentIdentity>;
|
|
758
|
+
|
|
759
|
+
export { AGENTCHAT_CHANNEL_ID, AGENTCHAT_DEFAULT_ACCOUNT_ID, AgentChatChannelError, type AgentchatAgentIdentity, AgentchatChannelConfig, AgentchatChannelRuntime, type ChannelRuntimeHandlers, type ChannelRuntimeOptions, type ConnectionState, type ConversationKind, type ErrorClass, type HealthSnapshot, type Message, type MessageContent, type MessageStatus, type MessageType, type NormalizedGroupDeleted, type NormalizedGroupInvite, type NormalizedInbound, type NormalizedMessage, type NormalizedPresence, type NormalizedRateLimitWarning, type NormalizedReadReceipt, type NormalizedTyping, type NormalizedUnknown, type OutboundBacklogWarning, type OutboundDirectMessage, type OutboundGroupMessage, type OutboundMessageInput, type RegisterAgentStartInput, type RegisterAgentVerifyInput, type RegisterOptions, type RegisterStartResult, type RegisterVerifyResult, type SendResult, type ValidateApiKeyOptions, type ValidateApiKeyResult, assertApiKeyValid, registerAgentStart, registerAgentVerify, validateApiKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,129 +1,32 @@
|
|
|
1
|
-
import { A as AgentchatChannelConfig } from './setup-entry-
|
|
2
|
-
export { a as
|
|
3
|
-
import { ChannelSetupWizard } from 'openclaw/plugin-sdk/channel-setup';
|
|
1
|
+
import { A as AgentchatChannelConfig } from './setup-entry-1vjPD1gu.js';
|
|
2
|
+
export { a as AgentchatResolvedAccount, b as agentchatChannelEntry, c as agentchatPlugin, d as agentchatSetupEntry, c as agentchatSetupPlugin, b as default, p as parseChannelConfig } from './setup-entry-1vjPD1gu.js';
|
|
4
3
|
export { hasAgentChatConfiguredState } from './configured-state.js';
|
|
5
4
|
import { WebSocket } from 'ws';
|
|
6
5
|
import 'openclaw/plugin-sdk/channel-core';
|
|
7
6
|
import 'zod';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
* - verify an API key is live before finalizing setup (`validateApiKey`)
|
|
12
|
-
* - drive the email-OTP self-registration flow for agents without a key yet
|
|
13
|
-
* (`registerAgentStart` → `registerAgentVerify`)
|
|
14
|
-
*
|
|
15
|
-
* Why this lives separately from `outbound.ts`:
|
|
16
|
-
* - `outbound.ts` is the hot-path message sender. It wants retries, a circuit
|
|
17
|
-
* breaker, metrics, and a long-lived `fetch`. Setup is one-shot, low-rate,
|
|
18
|
-
* user-interactive — a 200ms validation call doesn't need any of that.
|
|
19
|
-
* - Setup runs before the runtime exists; coupling it to `OutboundAdapter`
|
|
20
|
-
* (which expects a parsed `AgentchatChannelConfig`) would force an odd
|
|
21
|
-
* partial-config path during registration.
|
|
22
|
-
*
|
|
23
|
-
* The server endpoints this module targets are stable AgentChat REST calls:
|
|
24
|
-
* - `GET /v1/agents/me` → 200 OK when the key authenticates
|
|
25
|
-
* - `POST /v1/register` → 200 with `{ pending_id }`
|
|
26
|
-
* - `POST /v1/register/verify` → 201 with `{ agent, api_key }` on success
|
|
27
|
-
*
|
|
28
|
-
* All methods return strongly-typed result unions — setup UIs can `switch` on
|
|
29
|
-
* the discriminant without guessing at HTTP status codes.
|
|
30
|
-
*/
|
|
31
|
-
/** Subset of the AgentChat agent row the setup surface needs to show the user. */
|
|
32
|
-
interface AgentchatAgentIdentity {
|
|
33
|
-
readonly handle: string;
|
|
34
|
-
readonly displayName: string | null;
|
|
35
|
-
readonly email: string;
|
|
36
|
-
readonly createdAt: string;
|
|
37
|
-
}
|
|
38
|
-
type ValidateApiKeyResult = {
|
|
39
|
-
readonly ok: true;
|
|
40
|
-
readonly agent: AgentchatAgentIdentity;
|
|
41
|
-
} | {
|
|
42
|
-
readonly ok: false;
|
|
43
|
-
/** High-level reason code the UI can map to a localized message. */
|
|
44
|
-
readonly reason: 'unauthorized' | 'forbidden' | 'deleted' | 'network-error' | 'unreachable' | 'server-error' | 'unexpected-shape';
|
|
45
|
-
readonly message: string;
|
|
46
|
-
readonly status?: number;
|
|
47
|
-
};
|
|
48
|
-
interface ValidateApiKeyOptions {
|
|
49
|
-
readonly apiBase?: string;
|
|
50
|
-
readonly fetch?: typeof fetch;
|
|
51
|
-
readonly timeoutMs?: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Probe the API key against `GET /v1/agents/me`. Returns a discriminated
|
|
55
|
-
* result — never throws on HTTP or network errors. The caller decides how
|
|
56
|
-
* to surface each failure mode to the user.
|
|
57
|
-
*/
|
|
58
|
-
declare function validateApiKey(apiKey: string, opts?: ValidateApiKeyOptions): Promise<ValidateApiKeyResult>;
|
|
59
|
-
interface RegisterAgentStartInput {
|
|
60
|
-
readonly email: string;
|
|
61
|
-
readonly handle: string;
|
|
62
|
-
readonly displayName?: string;
|
|
63
|
-
readonly description?: string;
|
|
64
|
-
}
|
|
65
|
-
type RegisterStartResult = {
|
|
66
|
-
readonly ok: true;
|
|
67
|
-
readonly pendingId: string;
|
|
68
|
-
} | {
|
|
69
|
-
readonly ok: false;
|
|
70
|
-
readonly reason: 'invalid-handle' | 'handle-taken' | 'email-taken' | 'email-is-owner' | 'email-exhausted' | 'rate-limited' | 'otp-failed' | 'network-error' | 'server-error' | 'validation';
|
|
71
|
-
readonly message: string;
|
|
72
|
-
readonly status?: number;
|
|
73
|
-
readonly retryAfterSeconds?: number;
|
|
74
|
-
};
|
|
75
|
-
interface RegisterAgentVerifyInput {
|
|
76
|
-
readonly pendingId: string;
|
|
77
|
-
readonly code: string;
|
|
78
|
-
}
|
|
79
|
-
type RegisterVerifyResult = {
|
|
80
|
-
readonly ok: true;
|
|
81
|
-
readonly apiKey: string;
|
|
82
|
-
readonly agent: AgentchatAgentIdentity;
|
|
83
|
-
} | {
|
|
84
|
-
readonly ok: false;
|
|
85
|
-
readonly reason: 'expired' | 'invalid-code' | 'rate-limited' | 'handle-taken' | 'email-taken' | 'email-is-owner' | 'network-error' | 'server-error' | 'unexpected-shape' | 'validation';
|
|
86
|
-
readonly message: string;
|
|
87
|
-
readonly status?: number;
|
|
88
|
-
readonly retryAfterSeconds?: number;
|
|
89
|
-
};
|
|
90
|
-
interface RegisterOptions {
|
|
91
|
-
readonly apiBase?: string;
|
|
92
|
-
readonly fetch?: typeof fetch;
|
|
93
|
-
readonly timeoutMs?: number;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Kick off an email-OTP registration. Server caches the intent under a
|
|
97
|
-
* `pending_id` for 10 minutes and emails a 6-digit code to `email`.
|
|
98
|
-
*/
|
|
99
|
-
declare function registerAgentStart(input: RegisterAgentStartInput, opts?: RegisterOptions): Promise<RegisterStartResult>;
|
|
100
|
-
/** Verify the OTP the user received by email and mint the API key. */
|
|
101
|
-
declare function registerAgentVerify(input: RegisterAgentVerifyInput, opts?: RegisterOptions): Promise<RegisterVerifyResult>;
|
|
102
|
-
/**
|
|
103
|
-
* Throw-flavored wrapper used by callers that prefer exception control flow
|
|
104
|
-
* (the setup plugin's `afterAccountConfigWritten` hook). Converts a failure
|
|
105
|
-
* result into an `AgentChatChannelError` with an appropriate class.
|
|
106
|
-
*/
|
|
107
|
-
declare function assertApiKeyValid(apiKey: string, opts?: ValidateApiKeyOptions): Promise<AgentchatAgentIdentity>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Interactive setup wizard for the AgentChat channel.
|
|
111
|
-
*
|
|
112
|
-
* Invoked by `openclaw channels add --channel agentchat`. Drives three branches:
|
|
113
|
-
*
|
|
114
|
-
* - edit — existing config → re-validate OR rotate OR change API base
|
|
115
|
-
* - have-key — user pastes an existing ac_live_* key → /agents/me probe → write
|
|
116
|
-
* - register — email + handle + description → /register + OTP → /register/verify
|
|
9
|
+
* Account-config primitives for the AgentChat channel plugin.
|
|
117
10
|
*
|
|
118
|
-
*
|
|
119
|
-
* `
|
|
11
|
+
* This module owns the smallest set of shared pieces that both the plugin
|
|
12
|
+
* definition (`channel.ts`) and the interactive setup wizard
|
|
13
|
+
* (`channel.wizard.ts`) need to read or mutate the `channels.agentchat.*`
|
|
14
|
+
* section of the OpenClaw config. Keeping them in a leaf file (no imports
|
|
15
|
+
* from other channel-* modules) breaks the channel.ts ↔ channel.wizard.ts
|
|
16
|
+
* import cycle — without it, the wizard literal's `channel:` field resolves
|
|
17
|
+
* to the temporal-dead-zone value of `AGENTCHAT_CHANNEL_ID` at module-init
|
|
18
|
+
* time, which bundlers emit as `undefined`.
|
|
120
19
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
20
|
+
* Invariants:
|
|
21
|
+
* - Flat form (`channels.agentchat.{apiKey,...}`) is the default-account
|
|
22
|
+
* layout when no `accounts` key is present. Once a named account is
|
|
23
|
+
* written, flat form is never used again for the default account.
|
|
24
|
+
* - The `enabled` flag is section-level (not per-account) and is kept out
|
|
25
|
+
* of the Zod-parsed account shape because the schema is `.strict()`.
|
|
124
26
|
*/
|
|
125
27
|
|
|
126
|
-
declare const
|
|
28
|
+
declare const AGENTCHAT_CHANNEL_ID: "agentchat";
|
|
29
|
+
declare const AGENTCHAT_DEFAULT_ACCOUNT_ID = "default";
|
|
127
30
|
|
|
128
31
|
interface Logger {
|
|
129
32
|
trace(obj: object, msg?: string): void;
|
|
@@ -753,4 +656,104 @@ declare class AgentchatChannelRuntime {
|
|
|
753
656
|
private recordInboundMetric;
|
|
754
657
|
}
|
|
755
658
|
|
|
756
|
-
|
|
659
|
+
/**
|
|
660
|
+
* Minimal HTTP client used by the setup plugin (P7) to:
|
|
661
|
+
* - verify an API key is live before finalizing setup (`validateApiKey`)
|
|
662
|
+
* - drive the email-OTP self-registration flow for agents without a key yet
|
|
663
|
+
* (`registerAgentStart` → `registerAgentVerify`)
|
|
664
|
+
*
|
|
665
|
+
* Why this lives separately from `outbound.ts`:
|
|
666
|
+
* - `outbound.ts` is the hot-path message sender. It wants retries, a circuit
|
|
667
|
+
* breaker, metrics, and a long-lived `fetch`. Setup is one-shot, low-rate,
|
|
668
|
+
* user-interactive — a 200ms validation call doesn't need any of that.
|
|
669
|
+
* - Setup runs before the runtime exists; coupling it to `OutboundAdapter`
|
|
670
|
+
* (which expects a parsed `AgentchatChannelConfig`) would force an odd
|
|
671
|
+
* partial-config path during registration.
|
|
672
|
+
*
|
|
673
|
+
* The server endpoints this module targets are stable AgentChat REST calls:
|
|
674
|
+
* - `GET /v1/agents/me` → 200 OK when the key authenticates
|
|
675
|
+
* - `POST /v1/register` → 200 with `{ pending_id }`
|
|
676
|
+
* - `POST /v1/register/verify` → 201 with `{ agent, api_key }` on success
|
|
677
|
+
*
|
|
678
|
+
* All methods return strongly-typed result unions — setup UIs can `switch` on
|
|
679
|
+
* the discriminant without guessing at HTTP status codes.
|
|
680
|
+
*/
|
|
681
|
+
/** Subset of the AgentChat agent row the setup surface needs to show the user. */
|
|
682
|
+
interface AgentchatAgentIdentity {
|
|
683
|
+
readonly handle: string;
|
|
684
|
+
readonly displayName: string | null;
|
|
685
|
+
readonly email: string;
|
|
686
|
+
readonly createdAt: string;
|
|
687
|
+
}
|
|
688
|
+
type ValidateApiKeyResult = {
|
|
689
|
+
readonly ok: true;
|
|
690
|
+
readonly agent: AgentchatAgentIdentity;
|
|
691
|
+
} | {
|
|
692
|
+
readonly ok: false;
|
|
693
|
+
/** High-level reason code the UI can map to a localized message. */
|
|
694
|
+
readonly reason: 'unauthorized' | 'forbidden' | 'deleted' | 'network-error' | 'unreachable' | 'server-error' | 'unexpected-shape';
|
|
695
|
+
readonly message: string;
|
|
696
|
+
readonly status?: number;
|
|
697
|
+
};
|
|
698
|
+
interface ValidateApiKeyOptions {
|
|
699
|
+
readonly apiBase?: string;
|
|
700
|
+
readonly fetch?: typeof fetch;
|
|
701
|
+
readonly timeoutMs?: number;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Probe the API key against `GET /v1/agents/me`. Returns a discriminated
|
|
705
|
+
* result — never throws on HTTP or network errors. The caller decides how
|
|
706
|
+
* to surface each failure mode to the user.
|
|
707
|
+
*/
|
|
708
|
+
declare function validateApiKey(apiKey: string, opts?: ValidateApiKeyOptions): Promise<ValidateApiKeyResult>;
|
|
709
|
+
interface RegisterAgentStartInput {
|
|
710
|
+
readonly email: string;
|
|
711
|
+
readonly handle: string;
|
|
712
|
+
readonly displayName?: string;
|
|
713
|
+
readonly description?: string;
|
|
714
|
+
}
|
|
715
|
+
type RegisterStartResult = {
|
|
716
|
+
readonly ok: true;
|
|
717
|
+
readonly pendingId: string;
|
|
718
|
+
} | {
|
|
719
|
+
readonly ok: false;
|
|
720
|
+
readonly reason: 'invalid-handle' | 'handle-taken' | 'email-taken' | 'email-exhausted' | 'rate-limited' | 'otp-failed' | 'network-error' | 'server-error' | 'validation';
|
|
721
|
+
readonly message: string;
|
|
722
|
+
readonly status?: number;
|
|
723
|
+
readonly retryAfterSeconds?: number;
|
|
724
|
+
};
|
|
725
|
+
interface RegisterAgentVerifyInput {
|
|
726
|
+
readonly pendingId: string;
|
|
727
|
+
readonly code: string;
|
|
728
|
+
}
|
|
729
|
+
type RegisterVerifyResult = {
|
|
730
|
+
readonly ok: true;
|
|
731
|
+
readonly apiKey: string;
|
|
732
|
+
readonly agent: AgentchatAgentIdentity;
|
|
733
|
+
} | {
|
|
734
|
+
readonly ok: false;
|
|
735
|
+
readonly reason: 'expired' | 'invalid-code' | 'rate-limited' | 'handle-taken' | 'email-taken' | 'network-error' | 'server-error' | 'unexpected-shape' | 'validation';
|
|
736
|
+
readonly message: string;
|
|
737
|
+
readonly status?: number;
|
|
738
|
+
readonly retryAfterSeconds?: number;
|
|
739
|
+
};
|
|
740
|
+
interface RegisterOptions {
|
|
741
|
+
readonly apiBase?: string;
|
|
742
|
+
readonly fetch?: typeof fetch;
|
|
743
|
+
readonly timeoutMs?: number;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Kick off an email-OTP registration. Server caches the intent under a
|
|
747
|
+
* `pending_id` for 10 minutes and emails a 6-digit code to `email`.
|
|
748
|
+
*/
|
|
749
|
+
declare function registerAgentStart(input: RegisterAgentStartInput, opts?: RegisterOptions): Promise<RegisterStartResult>;
|
|
750
|
+
/** Verify the OTP the user received by email and mint the API key. */
|
|
751
|
+
declare function registerAgentVerify(input: RegisterAgentVerifyInput, opts?: RegisterOptions): Promise<RegisterVerifyResult>;
|
|
752
|
+
/**
|
|
753
|
+
* Throw-flavored wrapper used by callers that prefer exception control flow
|
|
754
|
+
* (the setup plugin's `afterAccountConfigWritten` hook). Converts a failure
|
|
755
|
+
* result into an `AgentChatChannelError` with an appropriate class.
|
|
756
|
+
*/
|
|
757
|
+
declare function assertApiKeyValid(apiKey: string, opts?: ValidateApiKeyOptions): Promise<AgentchatAgentIdentity>;
|
|
758
|
+
|
|
759
|
+
export { AGENTCHAT_CHANNEL_ID, AGENTCHAT_DEFAULT_ACCOUNT_ID, AgentChatChannelError, type AgentchatAgentIdentity, AgentchatChannelConfig, AgentchatChannelRuntime, type ChannelRuntimeHandlers, type ChannelRuntimeOptions, type ConnectionState, type ConversationKind, type ErrorClass, type HealthSnapshot, type Message, type MessageContent, type MessageStatus, type MessageType, type NormalizedGroupDeleted, type NormalizedGroupInvite, type NormalizedInbound, type NormalizedMessage, type NormalizedPresence, type NormalizedRateLimitWarning, type NormalizedReadReceipt, type NormalizedTyping, type NormalizedUnknown, type OutboundBacklogWarning, type OutboundDirectMessage, type OutboundGroupMessage, type OutboundMessageInput, type RegisterAgentStartInput, type RegisterAgentVerifyInput, type RegisterOptions, type RegisterStartResult, type RegisterVerifyResult, type SendResult, type ValidateApiKeyOptions, type ValidateApiKeyResult, assertApiKeyValid, registerAgentStart, registerAgentVerify, validateApiKey };
|