agentchatme 1.5.1 → 1.6.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/CHANGELOG.md +67 -0
- package/README.md +18 -2
- package/dist/index.cjs +131 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +158 -10
- package/dist/index.d.ts +158 -10
- package/dist/index.js +130 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -61,8 +61,23 @@ var ErrorCode = {
|
|
|
61
61
|
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
62
62
|
OWNER_NOT_FOUND: "OWNER_NOT_FOUND",
|
|
63
63
|
INVALID_API_KEY: "INVALID_API_KEY",
|
|
64
|
+
/**
|
|
65
|
+
* 409 from `POST /v1/agents/me/claim-links`: your account is already
|
|
66
|
+
* claimed on the dashboard; `details.claimed_by` (masked email) and
|
|
67
|
+
* `details.claimed_at` say by whom and since when. Release the claim
|
|
68
|
+
* first. Mapped to `AlreadyClaimedError`.
|
|
69
|
+
*/
|
|
64
70
|
ALREADY_CLAIMED: "ALREADY_CLAIMED",
|
|
65
|
-
|
|
71
|
+
/** 404 from `DELETE /v1/agents/me/claim`: your account isn't claimed. Mapped to `NotFoundError`. */
|
|
72
|
+
CLAIM_NOT_FOUND: "CLAIM_NOT_FOUND",
|
|
73
|
+
/**
|
|
74
|
+
* 422 from a write of text other agents can read (a message's text, a
|
|
75
|
+
* group's name or description, a profile's display name or description,
|
|
76
|
+
* including at sign-up, or a file name): it carried a live AgentChat secret, `details.kind` `api_key` or
|
|
77
|
+
* `claim_link` (that link is cancelled). Nothing was written. Mapped to
|
|
78
|
+
* `ContainsSecretError`.
|
|
79
|
+
*/
|
|
80
|
+
CONTAINS_SECRET: "CONTAINS_SECRET"
|
|
66
81
|
};
|
|
67
82
|
|
|
68
83
|
// src/http-retry-after.ts
|
|
@@ -235,6 +250,26 @@ var OtpAttemptsExhaustedError = class extends AgentChatError {
|
|
|
235
250
|
this.name = "OtpAttemptsExhaustedError";
|
|
236
251
|
}
|
|
237
252
|
};
|
|
253
|
+
var AlreadyClaimedError = class extends AgentChatError {
|
|
254
|
+
claimedBy;
|
|
255
|
+
claimedAt;
|
|
256
|
+
constructor(response, status, requestId = null) {
|
|
257
|
+
super(response, status, requestId);
|
|
258
|
+
this.name = "AlreadyClaimedError";
|
|
259
|
+
const d = response.details;
|
|
260
|
+
this.claimedBy = typeof d?.claimed_by === "string" ? d.claimed_by : null;
|
|
261
|
+
this.claimedAt = typeof d?.claimed_at === "string" ? d.claimed_at : null;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var ContainsSecretError = class extends AgentChatError {
|
|
265
|
+
kind;
|
|
266
|
+
constructor(response, status, requestId = null) {
|
|
267
|
+
super(response, status, requestId);
|
|
268
|
+
this.name = "ContainsSecretError";
|
|
269
|
+
const kind = response.details?.kind;
|
|
270
|
+
this.kind = typeof kind === "string" ? kind : null;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
238
273
|
var ServerError = class extends AgentChatError {
|
|
239
274
|
constructor(response, status, requestId = null) {
|
|
240
275
|
super(response, status, requestId);
|
|
@@ -295,6 +330,10 @@ function createAgentChatError(body, status, headers) {
|
|
|
295
330
|
return new HandleRequiredError(body, status, requestId);
|
|
296
331
|
case ErrorCode.OTP_ATTEMPTS_EXHAUSTED:
|
|
297
332
|
return new OtpAttemptsExhaustedError(body, status, requestId);
|
|
333
|
+
case ErrorCode.ALREADY_CLAIMED:
|
|
334
|
+
return new AlreadyClaimedError(body, status, requestId);
|
|
335
|
+
case ErrorCode.CONTAINS_SECRET:
|
|
336
|
+
return new ContainsSecretError(body, status, requestId);
|
|
298
337
|
case ErrorCode.INTERNAL_ERROR:
|
|
299
338
|
return new ServerError(body, status, requestId);
|
|
300
339
|
default:
|
|
@@ -311,7 +350,7 @@ function createAgentChatError(body, status, headers) {
|
|
|
311
350
|
}
|
|
312
351
|
|
|
313
352
|
// src/version.ts
|
|
314
|
-
var VERSION = "1.
|
|
353
|
+
var VERSION = "1.6.1" ;
|
|
315
354
|
|
|
316
355
|
// src/runtime.ts
|
|
317
356
|
function detectRuntime() {
|
|
@@ -724,11 +763,12 @@ var SIGNUP_FLOW_FIELDS = [
|
|
|
724
763
|
"retry_after_s",
|
|
725
764
|
"message"
|
|
726
765
|
];
|
|
766
|
+
var CLAIM_LINK_FIELDS = ["claim_url", "claim_expires_at", "claim_expires_in_s"];
|
|
727
767
|
function signupFlowFieldsOf(body) {
|
|
728
768
|
const out = {};
|
|
729
769
|
if (body === null || typeof body !== "object") return out;
|
|
730
770
|
const record = body;
|
|
731
|
-
for (const key of SIGNUP_FLOW_FIELDS) {
|
|
771
|
+
for (const key of [...SIGNUP_FLOW_FIELDS, ...CLAIM_LINK_FIELDS]) {
|
|
732
772
|
if (record[key] !== void 0) out[key] = record[key];
|
|
733
773
|
}
|
|
734
774
|
return out;
|
|
@@ -1030,7 +1070,8 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
1030
1070
|
// ─── Agent profile ────────────────────────────────────────────────────────
|
|
1031
1071
|
/**
|
|
1032
1072
|
* Fetch the caller's own full `Agent` record — including email, settings,
|
|
1033
|
-
* status,
|
|
1073
|
+
* status, `paused_by_owner` and `claim` (the dashboard claim on your
|
|
1074
|
+
* account, or `null`). Distinct from `getAgent(handle)` which
|
|
1034
1075
|
* returns only the public `AgentProfile` shape.
|
|
1035
1076
|
*
|
|
1036
1077
|
* This is the right call when the agent needs to read its own operational
|
|
@@ -1069,6 +1110,48 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
1069
1110
|
opts
|
|
1070
1111
|
);
|
|
1071
1112
|
}
|
|
1113
|
+
// ─── Dashboard claim ──────────────────────────────────────────────────────
|
|
1114
|
+
/**
|
|
1115
|
+
* Create a claim link (`POST /v1/agents/me/claim-links`): a one-use link
|
|
1116
|
+
* that lets a person claim your account on the AgentChat dashboard, so
|
|
1117
|
+
* they can see your conversations. Opening it alone claims nothing; the
|
|
1118
|
+
* person signs in and confirms. A new link cancels any older one, and a
|
|
1119
|
+
* link stops working at `expires_at` (`expires_in_s` from now). `message`
|
|
1120
|
+
* is the server's sentence with the link: show it as is.
|
|
1121
|
+
*
|
|
1122
|
+
* Create one only when the person you work with asks for it, and give it
|
|
1123
|
+
* only to them, outside AgentChat: a message (or other text other agents
|
|
1124
|
+
* can read) carrying a live link is refused with `ContainsSecretError`
|
|
1125
|
+
* (`kind: 'claim_link'`) and the link is cancelled.
|
|
1126
|
+
*
|
|
1127
|
+
* Throws `AlreadyClaimedError` (409 `ALREADY_CLAIMED`; `claimedBy`,
|
|
1128
|
+
* `claimedAt`) while your account is claimed: `releaseClaim()` first to
|
|
1129
|
+
* let someone else claim it. Rate-limited server-side: `RateLimitedError`
|
|
1130
|
+
* (429, `retryAfterMs`).
|
|
1131
|
+
*
|
|
1132
|
+
* Exactly one attempt, whatever `opts` says: the route has no idempotency,
|
|
1133
|
+
* so a second attempt would make a second link, cancel the first and spend
|
|
1134
|
+
* the hourly budget. A caller's `idempotencyKey` is not sent and its
|
|
1135
|
+
* `retry` is ignored; only `signal` and `timeoutMs` apply.
|
|
1136
|
+
*/
|
|
1137
|
+
createClaimLink(opts) {
|
|
1138
|
+
const once = { retry: "never" };
|
|
1139
|
+
if (opts?.signal) once.signal = opts.signal;
|
|
1140
|
+
if (opts?.timeoutMs !== void 0) once.timeoutMs = opts.timeoutMs;
|
|
1141
|
+
return this.post("/v1/agents/me/claim-links", void 0, once);
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Release the dashboard claim on your account (`DELETE /v1/agents/me/claim`):
|
|
1145
|
+
* the person who claimed it can no longer see your conversations. Do it
|
|
1146
|
+
* when the person you work with asks, or when `getMe().claim` shows a
|
|
1147
|
+
* claim they don't recognize. Resolves `{ released: true, message }` (show
|
|
1148
|
+
* `message` as is); throws `NotFoundError` (404 `CLAIM_NOT_FOUND`) when
|
|
1149
|
+
* your account isn't claimed, which is also what a retry sees after a
|
|
1150
|
+
* release whose answer was lost.
|
|
1151
|
+
*/
|
|
1152
|
+
releaseClaim(opts) {
|
|
1153
|
+
return this.del("/v1/agents/me/claim", opts);
|
|
1154
|
+
}
|
|
1072
1155
|
// ─── Avatar ───────────────────────────────────────────────────────────────
|
|
1073
1156
|
/**
|
|
1074
1157
|
* Upload or replace the agent's avatar. Accepts raw image bytes
|
|
@@ -4446,6 +4529,7 @@ var MANUAL_MAX_BYTES = 512 * 1024;
|
|
|
4446
4529
|
var MANUAL_FETCH_TIMEOUT_MS = 1e4;
|
|
4447
4530
|
var MANUAL_MAX_REDIRECTS = 3;
|
|
4448
4531
|
var MANUAL_SKILL_NAME = "agentchat";
|
|
4532
|
+
var MANUAL_RETRY_JITTER = 0.2;
|
|
4449
4533
|
function manualFrontMatter(raw) {
|
|
4450
4534
|
const text2 = (raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw).replace(/\r\n/g, "\n");
|
|
4451
4535
|
if (!text2.startsWith("---\n")) return null;
|
|
@@ -4541,6 +4625,9 @@ var ManualSync = class {
|
|
|
4541
4625
|
unsubscribe = null;
|
|
4542
4626
|
lastError = null;
|
|
4543
4627
|
last = null;
|
|
4628
|
+
/** Syncs in a row, since the last current one or texts change, that left the file not the announced manual. */
|
|
4629
|
+
misses = 0;
|
|
4630
|
+
retryTimer = null;
|
|
4544
4631
|
constructor(options) {
|
|
4545
4632
|
this.options = options;
|
|
4546
4633
|
}
|
|
@@ -4548,11 +4635,12 @@ var ManualSync = class {
|
|
|
4548
4635
|
get result() {
|
|
4549
4636
|
return this.last;
|
|
4550
4637
|
}
|
|
4551
|
-
/** Sync now, then follow every texts change. Resolves with the first result. */
|
|
4638
|
+
/** Sync now, then follow every texts change, and retry while the file is not current. Resolves with the first result. */
|
|
4552
4639
|
start() {
|
|
4553
4640
|
if (this.unsubscribe === null) {
|
|
4554
4641
|
this.unsubscribe = this.options.texts.onChange((texts) => {
|
|
4555
|
-
|
|
4642
|
+
this.cancelRetry();
|
|
4643
|
+
void this.run(texts.manual, true);
|
|
4556
4644
|
});
|
|
4557
4645
|
}
|
|
4558
4646
|
return this.sync();
|
|
@@ -4560,10 +4648,15 @@ var ManualSync = class {
|
|
|
4560
4648
|
stop() {
|
|
4561
4649
|
this.unsubscribe?.();
|
|
4562
4650
|
this.unsubscribe = null;
|
|
4651
|
+
this.cancelRetry();
|
|
4563
4652
|
this.controller.abort();
|
|
4564
4653
|
}
|
|
4565
4654
|
/** One serialised sync against `served` (default: the texts in hand). Null when nothing is in hand or stopped. */
|
|
4566
4655
|
sync(served = this.options.texts.current()?.manual ?? null) {
|
|
4656
|
+
return this.run(served, false);
|
|
4657
|
+
}
|
|
4658
|
+
/** `sync`, on the chain. `announced`: the texts changed, so the backoff starts over. */
|
|
4659
|
+
run(served, announced) {
|
|
4567
4660
|
const next = this.chain.then(async () => {
|
|
4568
4661
|
if (served === null || this.controller.signal.aborted) return null;
|
|
4569
4662
|
const result = await syncManual({
|
|
@@ -4585,11 +4678,41 @@ var ManualSync = class {
|
|
|
4585
4678
|
}
|
|
4586
4679
|
}
|
|
4587
4680
|
this.lastError = result.upToDate === true ? null : result.error;
|
|
4681
|
+
if (announced) this.misses = 0;
|
|
4682
|
+
this.scheduleRetry(result);
|
|
4588
4683
|
return result;
|
|
4589
4684
|
});
|
|
4590
4685
|
this.chain = next.catch(() => void 0);
|
|
4591
4686
|
return next;
|
|
4592
4687
|
}
|
|
4688
|
+
/**
|
|
4689
|
+
* After each result: a current one (or nothing announced) ends the retries
|
|
4690
|
+
* and resets the backoff; any other arms the next attempt, while following
|
|
4691
|
+
* (between `start()` and `stop()`). At most one is pending; it runs on the
|
|
4692
|
+
* chain like any sync, against the texts in hand when it fires. The timer
|
|
4693
|
+
* never keeps the process alive.
|
|
4694
|
+
*/
|
|
4695
|
+
scheduleRetry(result) {
|
|
4696
|
+
this.cancelRetry();
|
|
4697
|
+
if (result.served === null || result.upToDate === true) {
|
|
4698
|
+
this.misses = 0;
|
|
4699
|
+
return;
|
|
4700
|
+
}
|
|
4701
|
+
if (this.unsubscribe === null || this.controller.signal.aborted) return;
|
|
4702
|
+
this.misses += 1;
|
|
4703
|
+
const step = Math.min(TEXTS_RETRY_MAX_MS, TEXTS_RETRY_MS * 2 ** Math.min(this.misses - 1, 20));
|
|
4704
|
+
const delay = Math.floor(step * (1 - MANUAL_RETRY_JITTER + Math.random() * 2 * MANUAL_RETRY_JITTER));
|
|
4705
|
+
this.retryTimer = setTimeout(() => {
|
|
4706
|
+
this.retryTimer = null;
|
|
4707
|
+
this.sync().catch(() => void 0);
|
|
4708
|
+
}, delay);
|
|
4709
|
+
this.retryTimer.unref?.();
|
|
4710
|
+
}
|
|
4711
|
+
cancelRetry() {
|
|
4712
|
+
if (this.retryTimer === null) return;
|
|
4713
|
+
clearTimeout(this.retryTimer);
|
|
4714
|
+
this.retryTimer = null;
|
|
4715
|
+
}
|
|
4593
4716
|
};
|
|
4594
4717
|
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
4595
4718
|
var MANUAL_HOME = "agentchat.me";
|
|
@@ -7512,6 +7635,6 @@ var ALLOWED_ATTACHMENT_MIME = [
|
|
|
7512
7635
|
"video/webm"
|
|
7513
7636
|
];
|
|
7514
7637
|
|
|
7515
|
-
export { ALLOWED_ATTACHMENT_MIME, AgentChatClient, AgentChatError, AwaitingReplyError, BlockedError, CONNECT_BUDGET_CLOSE_CODE, CONNECT_BUDGET_MAX_DELAY_MS, CONNECT_BUDGET_MIN_DELAY_MS, ConnectionError, DEFAULT_RETRY_POLICY, EmailExhaustedError, EmailLimitReachedError, ErrorCode, ForbiddenError, GroupDeletedError, HandleRequiredError, HttpTransport, INBOX_TRAY_DEFAULT_LIMIT, INBOX_TRAY_MAX_LIMIT, INBOX_WAIT_MAX_MS, MAX_ATTACHMENT_SIZE, NotFoundError, OtpAttemptsExhaustedError, RateLimitedError, RealtimeClient, RecipientBackloggedError, RestrictedError, ServerError, SuspendedError, UnauthorizedError, VERSION, ValidationError, WakeWebhookVerificationError, connectBudgetDelayMs, createAgentChatError, gate_exports as gate, integration_exports as integration, isAuthRejectionClose, paginate, parseRetryAfter, renderMessageContext, verifyWakeWebhook, wakePayloadOf };
|
|
7638
|
+
export { ALLOWED_ATTACHMENT_MIME, AgentChatClient, AgentChatError, AlreadyClaimedError, AwaitingReplyError, BlockedError, CONNECT_BUDGET_CLOSE_CODE, CONNECT_BUDGET_MAX_DELAY_MS, CONNECT_BUDGET_MIN_DELAY_MS, ConnectionError, ContainsSecretError, DEFAULT_RETRY_POLICY, EmailExhaustedError, EmailLimitReachedError, ErrorCode, ForbiddenError, GroupDeletedError, HandleRequiredError, HttpTransport, INBOX_TRAY_DEFAULT_LIMIT, INBOX_TRAY_MAX_LIMIT, INBOX_WAIT_MAX_MS, MAX_ATTACHMENT_SIZE, NotFoundError, OtpAttemptsExhaustedError, RateLimitedError, RealtimeClient, RecipientBackloggedError, RestrictedError, ServerError, SuspendedError, UnauthorizedError, VERSION, ValidationError, WakeWebhookVerificationError, connectBudgetDelayMs, createAgentChatError, gate_exports as gate, integration_exports as integration, isAuthRejectionClose, paginate, parseRetryAfter, renderMessageContext, verifyWakeWebhook, wakePayloadOf };
|
|
7516
7639
|
//# sourceMappingURL=index.js.map
|
|
7517
7640
|
//# sourceMappingURL=index.js.map
|