@agentchatme/openclaw 0.2.0 → 0.4.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/dist/index.d.cts CHANGED
@@ -1,130 +1,10 @@
1
- import { A as AgentchatChannelConfig } from './setup-entry-CU0vHfyd.cjs';
2
- export { a as AGENTCHAT_CHANNEL_ID, b as AGENTCHAT_DEFAULT_ACCOUNT_ID, c as AgentchatResolvedAccount, d as agentchatChannelEntry, e as agentchatPlugin, f as agentchatSetupEntry, e as agentchatSetupPlugin, d as default, p as parseChannelConfig } from './setup-entry-CU0vHfyd.cjs';
3
- import { ChannelSetupWizard } from 'openclaw/plugin-sdk/channel-setup';
1
+ import { A as AgentchatChannelConfig } from './setup-entry-Cr6cKgzq.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-Cr6cKgzq.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
- /**
10
- * Minimal HTTP client used by the setup plugin (P7) to:
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
117
- *
118
- * All branches converge on `writeAccountPatch` which mutates
119
- * `channels.agentchat.<accountId>` in either flat or multi-account form.
120
- *
121
- * Every server-side failure mode surfaces as actionable copy — there are no
122
- * silent failures. The wizard only returns when the user has either finished
123
- * or explicitly chosen to abort.
124
- */
125
-
126
- declare const agentchatSetupWizard: ChannelSetupWizard;
127
-
128
8
  interface Logger {
129
9
  trace(obj: object, msg?: string): void;
130
10
  debug(obj: object, msg?: string): void;
@@ -753,4 +633,127 @@ declare class AgentchatChannelRuntime {
753
633
  private recordInboundMetric;
754
634
  }
755
635
 
756
- export { 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, agentchatSetupWizard, assertApiKeyValid, registerAgentStart, registerAgentVerify, validateApiKey };
636
+ /**
637
+ * Account-config primitives for the AgentChat channel plugin.
638
+ *
639
+ * This module owns the smallest set of shared pieces that both the plugin
640
+ * definition (`channel.ts`) and the interactive setup wizard
641
+ * (`channel.wizard.ts`) need to read or mutate the `channels.agentchat.*`
642
+ * section of the OpenClaw config. Keeping them in a leaf file (no imports
643
+ * from other channel-* modules) breaks the channel.ts ↔ channel.wizard.ts
644
+ * import cycle — without it, the wizard literal's `channel:` field resolves
645
+ * to the temporal-dead-zone value of `AGENTCHAT_CHANNEL_ID` at module-init
646
+ * time, which bundlers emit as `undefined`.
647
+ *
648
+ * Invariants:
649
+ * - Flat form (`channels.agentchat.{apiKey,...}`) is the default-account
650
+ * layout when no `accounts` key is present. Once a named account is
651
+ * written, flat form is never used again for the default account.
652
+ * - The `enabled` flag is section-level (not per-account) and is kept out
653
+ * of the Zod-parsed account shape because the schema is `.strict()`.
654
+ */
655
+
656
+ declare const AGENTCHAT_CHANNEL_ID: "agentchat";
657
+ declare const AGENTCHAT_DEFAULT_ACCOUNT_ID = "default";
658
+
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,130 +1,10 @@
1
- import { A as AgentchatChannelConfig } from './setup-entry-CU0vHfyd.js';
2
- export { a as AGENTCHAT_CHANNEL_ID, b as AGENTCHAT_DEFAULT_ACCOUNT_ID, c as AgentchatResolvedAccount, d as agentchatChannelEntry, e as agentchatPlugin, f as agentchatSetupEntry, e as agentchatSetupPlugin, d as default, p as parseChannelConfig } from './setup-entry-CU0vHfyd.js';
3
- import { ChannelSetupWizard } from 'openclaw/plugin-sdk/channel-setup';
1
+ import { A as AgentchatChannelConfig } from './setup-entry-Cr6cKgzq.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-Cr6cKgzq.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
- /**
10
- * Minimal HTTP client used by the setup plugin (P7) to:
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
117
- *
118
- * All branches converge on `writeAccountPatch` which mutates
119
- * `channels.agentchat.<accountId>` in either flat or multi-account form.
120
- *
121
- * Every server-side failure mode surfaces as actionable copy — there are no
122
- * silent failures. The wizard only returns when the user has either finished
123
- * or explicitly chosen to abort.
124
- */
125
-
126
- declare const agentchatSetupWizard: ChannelSetupWizard;
127
-
128
8
  interface Logger {
129
9
  trace(obj: object, msg?: string): void;
130
10
  debug(obj: object, msg?: string): void;
@@ -753,4 +633,127 @@ declare class AgentchatChannelRuntime {
753
633
  private recordInboundMetric;
754
634
  }
755
635
 
756
- export { 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, agentchatSetupWizard, assertApiKeyValid, registerAgentStart, registerAgentVerify, validateApiKey };
636
+ /**
637
+ * Account-config primitives for the AgentChat channel plugin.
638
+ *
639
+ * This module owns the smallest set of shared pieces that both the plugin
640
+ * definition (`channel.ts`) and the interactive setup wizard
641
+ * (`channel.wizard.ts`) need to read or mutate the `channels.agentchat.*`
642
+ * section of the OpenClaw config. Keeping them in a leaf file (no imports
643
+ * from other channel-* modules) breaks the channel.ts ↔ channel.wizard.ts
644
+ * import cycle — without it, the wizard literal's `channel:` field resolves
645
+ * to the temporal-dead-zone value of `AGENTCHAT_CHANNEL_ID` at module-init
646
+ * time, which bundlers emit as `undefined`.
647
+ *
648
+ * Invariants:
649
+ * - Flat form (`channels.agentchat.{apiKey,...}`) is the default-account
650
+ * layout when no `accounts` key is present. Once a named account is
651
+ * written, flat form is never used again for the default account.
652
+ * - The `enabled` flag is section-level (not per-account) and is kept out
653
+ * of the Zod-parsed account shape because the schema is `.strict()`.
654
+ */
655
+
656
+ declare const AGENTCHAT_CHANNEL_ID: "agentchat";
657
+ declare const AGENTCHAT_DEFAULT_ACCOUNT_ID = "default";
658
+
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 };