@anthropic-ai/sdk 0.119.0 → 0.120.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 +13 -0
- package/helpers/beta/environments.d.mts +5 -4
- package/helpers/beta/environments.d.mts.map +1 -1
- package/helpers/beta/environments.d.ts +5 -4
- package/helpers/beta/environments.d.ts.map +1 -1
- package/helpers/beta/environments.js +5 -4
- package/helpers/beta/environments.js.map +1 -1
- package/helpers/beta/environments.mjs +5 -4
- package/helpers/beta/environments.mjs.map +1 -1
- package/internal/file-store.d.mts +136 -0
- package/internal/file-store.d.mts.map +1 -0
- package/internal/file-store.d.ts +136 -0
- package/internal/file-store.d.ts.map +1 -0
- package/internal/file-store.js +531 -0
- package/internal/file-store.js.map +1 -0
- package/internal/file-store.mjs +523 -0
- package/internal/file-store.mjs.map +1 -0
- package/lib/environments/poller.d.mts +6 -0
- package/lib/environments/poller.d.mts.map +1 -1
- package/lib/environments/poller.d.ts +6 -0
- package/lib/environments/poller.d.ts.map +1 -1
- package/lib/environments/poller.js +46 -1
- package/lib/environments/poller.js.map +1 -1
- package/lib/environments/poller.mjs +46 -1
- package/lib/environments/poller.mjs.map +1 -1
- package/lib/environments/worker.d.mts +89 -12
- package/lib/environments/worker.d.mts.map +1 -1
- package/lib/environments/worker.d.ts +89 -12
- package/lib/environments/worker.d.ts.map +1 -1
- package/lib/environments/worker.js +336 -67
- package/lib/environments/worker.js.map +1 -1
- package/lib/environments/worker.mjs +336 -68
- package/lib/environments/worker.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +322 -27
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +322 -27
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/agents/index.d.mts +1 -1
- package/resources/beta/agents/index.d.mts.map +1 -1
- package/resources/beta/agents/index.d.ts +1 -1
- package/resources/beta/agents/index.d.ts.map +1 -1
- package/resources/beta/agents/index.js.map +1 -1
- package/resources/beta/agents/index.mjs.map +1 -1
- package/resources/beta/beta.d.mts +2 -2
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/environments/work.d.mts +5 -1
- package/resources/beta/environments/work.d.mts.map +1 -1
- package/resources/beta/environments/work.d.ts +5 -1
- package/resources/beta/environments/work.d.ts.map +1 -1
- package/resources/beta/environments/work.js +0 -17
- package/resources/beta/environments/work.js.map +1 -1
- package/resources/beta/environments/work.mjs +0 -17
- package/resources/beta/environments/work.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +1 -1
- package/resources/beta/messages/messages.d.ts +1 -1
- package/resources/messages/messages.d.mts +1 -1
- package/resources/messages/messages.d.ts +1 -1
- package/src/helpers/beta/environments.ts +5 -4
- package/src/internal/file-store.ts +550 -0
- package/src/lib/environments/poller.ts +47 -1
- package/src/lib/environments/worker.ts +419 -79
- package/src/resources/beta/agents/agents.ts +435 -30
- package/src/resources/beta/agents/index.ts +17 -0
- package/src/resources/beta/beta.ts +34 -0
- package/src/resources/beta/environments/work.ts +7 -0
- package/src/resources/beta/index.ts +17 -0
- package/src/resources/beta/messages/messages.ts +1 -1
- package/src/resources/messages/messages.ts +1 -1
- package/src/tools/agent-toolset/fs-util.ts +40 -24
- package/src/tools/agent-toolset/memories.ts +1017 -0
- package/src/tools/agent-toolset/node.browser.ts +68 -0
- package/src/tools/agent-toolset/node.ts +139 -53
- package/src/tools/agent-toolset/skills.ts +29 -9
- package/src/tools/agent-toolset/sync-interval.ts +30 -0
- package/src/version.ts +1 -1
- package/tools/agent-toolset/fs-util.d.mts +23 -10
- package/tools/agent-toolset/fs-util.d.mts.map +1 -1
- package/tools/agent-toolset/fs-util.d.ts +23 -10
- package/tools/agent-toolset/fs-util.d.ts.map +1 -1
- package/tools/agent-toolset/fs-util.js +40 -25
- package/tools/agent-toolset/fs-util.js.map +1 -1
- package/tools/agent-toolset/fs-util.mjs +38 -25
- package/tools/agent-toolset/fs-util.mjs.map +1 -1
- package/tools/agent-toolset/memories.d.mts +173 -0
- package/tools/agent-toolset/memories.d.mts.map +1 -0
- package/tools/agent-toolset/memories.d.ts +173 -0
- package/tools/agent-toolset/memories.d.ts.map +1 -0
- package/tools/agent-toolset/memories.js +902 -0
- package/tools/agent-toolset/memories.js.map +1 -0
- package/tools/agent-toolset/memories.mjs +895 -0
- package/tools/agent-toolset/memories.mjs.map +1 -0
- package/tools/agent-toolset/node.browser.d.mts +31 -0
- package/tools/agent-toolset/node.browser.d.mts.map +1 -1
- package/tools/agent-toolset/node.browser.d.ts +31 -0
- package/tools/agent-toolset/node.browser.d.ts.map +1 -1
- package/tools/agent-toolset/node.browser.js +59 -1
- package/tools/agent-toolset/node.browser.js.map +1 -1
- package/tools/agent-toolset/node.browser.mjs +54 -0
- package/tools/agent-toolset/node.browser.mjs.map +1 -1
- package/tools/agent-toolset/node.d.mts +54 -22
- package/tools/agent-toolset/node.d.mts.map +1 -1
- package/tools/agent-toolset/node.d.ts +54 -22
- package/tools/agent-toolset/node.d.ts.map +1 -1
- package/tools/agent-toolset/node.js +83 -44
- package/tools/agent-toolset/node.js.map +1 -1
- package/tools/agent-toolset/node.mjs +77 -44
- package/tools/agent-toolset/node.mjs.map +1 -1
- package/tools/agent-toolset/skills.d.mts +16 -7
- package/tools/agent-toolset/skills.d.mts.map +1 -1
- package/tools/agent-toolset/skills.d.ts +16 -7
- package/tools/agent-toolset/skills.d.ts.map +1 -1
- package/tools/agent-toolset/skills.js +27 -9
- package/tools/agent-toolset/skills.js.map +1 -1
- package/tools/agent-toolset/skills.mjs +27 -9
- package/tools/agent-toolset/skills.mjs.map +1 -1
- package/tools/agent-toolset/sync-interval.d.mts +19 -0
- package/tools/agent-toolset/sync-interval.d.mts.map +1 -0
- package/tools/agent-toolset/sync-interval.d.ts +19 -0
- package/tools/agent-toolset/sync-interval.d.ts.map +1 -0
- package/tools/agent-toolset/sync-interval.js +29 -0
- package/tools/agent-toolset/sync-interval.js.map +1 -0
- package/tools/agent-toolset/sync-interval.mjs +25 -0
- package/tools/agent-toolset/sync-interval.mjs.map +1 -0
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _WorkPoller_runnerClient, _WorkPoller_consumed, _WorkPoller_controller, _WorkPoller_detachExternal, _WorkPoller_autoStop, _WorkPoller_drain, _WorkPoller_blockMs, _WorkPoller_reclaimOlderThanMs, _WorkPoller_requestOpts;
|
|
2
|
+
var _WorkPoller_runnerClient, _WorkPoller_consumed, _WorkPoller_controller, _WorkPoller_detachExternal, _WorkPoller_autoStop, _WorkPoller_drain, _WorkPoller_blockMs, _WorkPoller_reclaimOlderThanMs, _WorkPoller_requestOpts, _IdleLog_log, _IdleLog_environmentId, _IdleLog_idleSince, _IdleLog_lastReport;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.WorkPoller = exports.POLL_BLOCK_MS = exports.jitter = exports.isStatus = exports.isFatal4xx = exports.is4xx = void 0;
|
|
5
5
|
exports.backoff = backoff;
|
|
@@ -21,11 +21,18 @@ Object.defineProperty(exports, "jitter", { enumerable: true, get: function () {
|
|
|
21
21
|
exports.POLL_BLOCK_MS = 999;
|
|
22
22
|
const POLL_BACKOFF_BASE_MS = 1000;
|
|
23
23
|
const POLL_BACKOFF_CAP_MS = 60000;
|
|
24
|
+
const IDLE_REPORT_INTERVAL_MS = 300000;
|
|
24
25
|
/**
|
|
25
26
|
* Async-iterable that long-polls a self-hosted environment for work, ack's
|
|
26
27
|
* each item, yields the {@link BetaSelfHostedWork} item, and posts `stop` after
|
|
27
28
|
* the consumer's loop body returns (or when the consumer `break`s).
|
|
28
29
|
*
|
|
30
|
+
* A yielded item may carry a per-item `secret` payload (populated only by the
|
|
31
|
+
* poll response); the poller passes it through untouched — consumers such as
|
|
32
|
+
* {@link EnvironmentWorker} extract the sessions token it carries and prefer
|
|
33
|
+
* that over the environment key for the item's downstream calls. Treat it as
|
|
34
|
+
* opaque and never log it.
|
|
35
|
+
*
|
|
29
36
|
* @example
|
|
30
37
|
* ```ts
|
|
31
38
|
* for await (const work of client.beta.environments.work.poller({
|
|
@@ -87,6 +94,7 @@ class WorkPoller {
|
|
|
87
94
|
component: 'work-poller',
|
|
88
95
|
environment_id: this.environmentId,
|
|
89
96
|
});
|
|
97
|
+
const idle = new IdleLog(log, this.environmentId);
|
|
90
98
|
try {
|
|
91
99
|
let attempt = 0;
|
|
92
100
|
while (!tslib_1.__classPrivateFieldGet(this, _WorkPoller_controller, "f").signal.aborted) {
|
|
@@ -122,9 +130,11 @@ class WorkPoller {
|
|
|
122
130
|
// Queue empty: either return now (drain) or wait and poll again.
|
|
123
131
|
if (tslib_1.__classPrivateFieldGet(this, _WorkPoller_drain, "f"))
|
|
124
132
|
return;
|
|
133
|
+
idle.onEmptyPoll();
|
|
125
134
|
await (0, sleep_1.sleep)((0, backoff_1.jitter)(1000, 3000), tslib_1.__classPrivateFieldGet(this, _WorkPoller_controller, "f").signal);
|
|
126
135
|
continue;
|
|
127
136
|
}
|
|
137
|
+
idle.onClaim();
|
|
128
138
|
log.info('claimed work', {
|
|
129
139
|
component: 'work-poller',
|
|
130
140
|
environment_id: this.environmentId,
|
|
@@ -169,6 +179,41 @@ exports.WorkPoller = WorkPoller;
|
|
|
169
179
|
function backoff(attempt) {
|
|
170
180
|
return (0, backoff_1.backoff)(attempt, POLL_BACKOFF_BASE_MS, POLL_BACKOFF_CAP_MS);
|
|
171
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Keeps an idle poll loop visible in the logs without an INFO line per poll:
|
|
184
|
+
* the first empty poll after start-up or after a claim logs at INFO and later
|
|
185
|
+
* ones at DEBUG, with an INFO reminder every `IDLE_REPORT_INTERVAL_MS` while
|
|
186
|
+
* the loop stays idle.
|
|
187
|
+
*/
|
|
188
|
+
class IdleLog {
|
|
189
|
+
constructor(log, environmentId) {
|
|
190
|
+
_IdleLog_log.set(this, void 0);
|
|
191
|
+
_IdleLog_environmentId.set(this, void 0);
|
|
192
|
+
_IdleLog_idleSince.set(this, void 0);
|
|
193
|
+
_IdleLog_lastReport.set(this, 0);
|
|
194
|
+
tslib_1.__classPrivateFieldSet(this, _IdleLog_log, log, "f");
|
|
195
|
+
tslib_1.__classPrivateFieldSet(this, _IdleLog_environmentId, environmentId, "f");
|
|
196
|
+
}
|
|
197
|
+
onEmptyPoll() {
|
|
198
|
+
const now = Date.now();
|
|
199
|
+
const fields = { component: 'work-poller', environment_id: tslib_1.__classPrivateFieldGet(this, _IdleLog_environmentId, "f") };
|
|
200
|
+
if (tslib_1.__classPrivateFieldGet(this, _IdleLog_idleSince, "f") === undefined) {
|
|
201
|
+
tslib_1.__classPrivateFieldSet(this, _IdleLog_idleSince, tslib_1.__classPrivateFieldSet(this, _IdleLog_lastReport, now, "f"), "f");
|
|
202
|
+
tslib_1.__classPrivateFieldGet(this, _IdleLog_log, "f").info('idle; polling for work', fields);
|
|
203
|
+
}
|
|
204
|
+
else if (now - tslib_1.__classPrivateFieldGet(this, _IdleLog_lastReport, "f") >= IDLE_REPORT_INTERVAL_MS) {
|
|
205
|
+
tslib_1.__classPrivateFieldSet(this, _IdleLog_lastReport, now, "f");
|
|
206
|
+
tslib_1.__classPrivateFieldGet(this, _IdleLog_log, "f").info(`still polling; idle for ${Math.round((now - tslib_1.__classPrivateFieldGet(this, _IdleLog_idleSince, "f")) / 1000)}s`, fields);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
tslib_1.__classPrivateFieldGet(this, _IdleLog_log, "f").debug('poll returned no work', fields);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
onClaim() {
|
|
213
|
+
tslib_1.__classPrivateFieldSet(this, _IdleLog_idleSince, undefined, "f");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
_IdleLog_log = new WeakMap(), _IdleLog_environmentId = new WeakMap(), _IdleLog_idleSince = new WeakMap(), _IdleLog_lastReport = new WeakMap();
|
|
172
217
|
function defaultWorkerId() {
|
|
173
218
|
// The API documents the worker id as a *unique* identifier for Redis consumer
|
|
174
219
|
// groups, so the fallback must be unique even when several pollers share a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../src/lib/environments/poller.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../src/lib/environments/poller.ts"],"names":[],"mappings":";;;;AA0PA,0BAEC;;AA5PD,+CAAkD;AAGlD,qDAAkE;AAClE,yDAAmD;AACnD,uDAAkD;AAClD,yDAAuD;AACvD,uDAAsD;AAEtD,6DAMsC;AACtC,uDAAuD;AAEvD,2DAAmF;AAA1E,gGAAA,KAAK,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,iGAAA,MAAM,OAAA;AAE5C,4EAA4E;AAC/D,QAAA,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,mBAAmB,GAAG,KAAM,CAAC;AACnC,MAAM,uBAAuB,GAAG,MAAO,CAAC;AAwDxC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,UAAU;IAoBrB,YAAY,IAAuB;QAdnC,yEAAyE;QACzE,wEAAwE;QACxE,uEAAuE;QACvE,0EAA0E;QACjE,2CAAy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,+BAAA,IAAI,uBAAe,GAAG,MAAA,CAAC;YACvB,+BAAA,IAAI,oBAAK,CAAC,IAAI,CAAC,2BAA2B,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,+BAAA,IAAI,0BAAW,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACnG,CAAC;aAAM,CAAC;YACN,+BAAA,IAAI,oBAAK,CAAC,KAAK,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO;QACL,+BAAA,IAAI,sBAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;CACF;;AAED,SAAS,eAAe;IACtB,8EAA8E;IAC9E,2EAA2E;IAC3E,+EAA+E;IAC/E,8BAA8B;IAC9B,MAAM,GAAG,GAAI,UAAyE,CAAC,OAAO,EAAE,GAAG,CAAC;IACpG,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAA,YAAK,GAAE,EAAE,CAAC,CAAC,CAAC,IAAA,YAAK,GAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _WorkPoller_runnerClient, _WorkPoller_consumed, _WorkPoller_controller, _WorkPoller_detachExternal, _WorkPoller_autoStop, _WorkPoller_drain, _WorkPoller_blockMs, _WorkPoller_reclaimOlderThanMs, _WorkPoller_requestOpts;
|
|
1
|
+
var _WorkPoller_runnerClient, _WorkPoller_consumed, _WorkPoller_controller, _WorkPoller_detachExternal, _WorkPoller_autoStop, _WorkPoller_drain, _WorkPoller_blockMs, _WorkPoller_reclaimOlderThanMs, _WorkPoller_requestOpts, _IdleLog_log, _IdleLog_environmentId, _IdleLog_idleSince, _IdleLog_lastReport;
|
|
2
2
|
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../../internal/tslib.mjs";
|
|
3
3
|
import { AnthropicError } from "../../core/error.mjs";
|
|
4
4
|
import { loggerFor } from "../../internal/utils/log.mjs";
|
|
@@ -13,11 +13,18 @@ export { is4xx, isFatal4xx, isStatus, jitter } from "../../internal/utils/backof
|
|
|
13
13
|
export const POLL_BLOCK_MS = 999;
|
|
14
14
|
const POLL_BACKOFF_BASE_MS = 1000;
|
|
15
15
|
const POLL_BACKOFF_CAP_MS = 60000;
|
|
16
|
+
const IDLE_REPORT_INTERVAL_MS = 300000;
|
|
16
17
|
/**
|
|
17
18
|
* Async-iterable that long-polls a self-hosted environment for work, ack's
|
|
18
19
|
* each item, yields the {@link BetaSelfHostedWork} item, and posts `stop` after
|
|
19
20
|
* the consumer's loop body returns (or when the consumer `break`s).
|
|
20
21
|
*
|
|
22
|
+
* A yielded item may carry a per-item `secret` payload (populated only by the
|
|
23
|
+
* poll response); the poller passes it through untouched — consumers such as
|
|
24
|
+
* {@link EnvironmentWorker} extract the sessions token it carries and prefer
|
|
25
|
+
* that over the environment key for the item's downstream calls. Treat it as
|
|
26
|
+
* opaque and never log it.
|
|
27
|
+
*
|
|
21
28
|
* @example
|
|
22
29
|
* ```ts
|
|
23
30
|
* for await (const work of client.beta.environments.work.poller({
|
|
@@ -79,6 +86,7 @@ export class WorkPoller {
|
|
|
79
86
|
component: 'work-poller',
|
|
80
87
|
environment_id: this.environmentId,
|
|
81
88
|
});
|
|
89
|
+
const idle = new IdleLog(log, this.environmentId);
|
|
82
90
|
try {
|
|
83
91
|
let attempt = 0;
|
|
84
92
|
while (!__classPrivateFieldGet(this, _WorkPoller_controller, "f").signal.aborted) {
|
|
@@ -114,9 +122,11 @@ export class WorkPoller {
|
|
|
114
122
|
// Queue empty: either return now (drain) or wait and poll again.
|
|
115
123
|
if (__classPrivateFieldGet(this, _WorkPoller_drain, "f"))
|
|
116
124
|
return;
|
|
125
|
+
idle.onEmptyPoll();
|
|
117
126
|
await sleep(jitter(1000, 3000), __classPrivateFieldGet(this, _WorkPoller_controller, "f").signal);
|
|
118
127
|
continue;
|
|
119
128
|
}
|
|
129
|
+
idle.onClaim();
|
|
120
130
|
log.info('claimed work', {
|
|
121
131
|
component: 'work-poller',
|
|
122
132
|
environment_id: this.environmentId,
|
|
@@ -160,6 +170,41 @@ export class WorkPoller {
|
|
|
160
170
|
export function backoff(attempt) {
|
|
161
171
|
return expBackoff(attempt, POLL_BACKOFF_BASE_MS, POLL_BACKOFF_CAP_MS);
|
|
162
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Keeps an idle poll loop visible in the logs without an INFO line per poll:
|
|
175
|
+
* the first empty poll after start-up or after a claim logs at INFO and later
|
|
176
|
+
* ones at DEBUG, with an INFO reminder every `IDLE_REPORT_INTERVAL_MS` while
|
|
177
|
+
* the loop stays idle.
|
|
178
|
+
*/
|
|
179
|
+
class IdleLog {
|
|
180
|
+
constructor(log, environmentId) {
|
|
181
|
+
_IdleLog_log.set(this, void 0);
|
|
182
|
+
_IdleLog_environmentId.set(this, void 0);
|
|
183
|
+
_IdleLog_idleSince.set(this, void 0);
|
|
184
|
+
_IdleLog_lastReport.set(this, 0);
|
|
185
|
+
__classPrivateFieldSet(this, _IdleLog_log, log, "f");
|
|
186
|
+
__classPrivateFieldSet(this, _IdleLog_environmentId, environmentId, "f");
|
|
187
|
+
}
|
|
188
|
+
onEmptyPoll() {
|
|
189
|
+
const now = Date.now();
|
|
190
|
+
const fields = { component: 'work-poller', environment_id: __classPrivateFieldGet(this, _IdleLog_environmentId, "f") };
|
|
191
|
+
if (__classPrivateFieldGet(this, _IdleLog_idleSince, "f") === undefined) {
|
|
192
|
+
__classPrivateFieldSet(this, _IdleLog_idleSince, __classPrivateFieldSet(this, _IdleLog_lastReport, now, "f"), "f");
|
|
193
|
+
__classPrivateFieldGet(this, _IdleLog_log, "f").info('idle; polling for work', fields);
|
|
194
|
+
}
|
|
195
|
+
else if (now - __classPrivateFieldGet(this, _IdleLog_lastReport, "f") >= IDLE_REPORT_INTERVAL_MS) {
|
|
196
|
+
__classPrivateFieldSet(this, _IdleLog_lastReport, now, "f");
|
|
197
|
+
__classPrivateFieldGet(this, _IdleLog_log, "f").info(`still polling; idle for ${Math.round((now - __classPrivateFieldGet(this, _IdleLog_idleSince, "f")) / 1000)}s`, fields);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
__classPrivateFieldGet(this, _IdleLog_log, "f").debug('poll returned no work', fields);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
onClaim() {
|
|
204
|
+
__classPrivateFieldSet(this, _IdleLog_idleSince, undefined, "f");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
_IdleLog_log = new WeakMap(), _IdleLog_environmentId = new WeakMap(), _IdleLog_idleSince = new WeakMap(), _IdleLog_lastReport = new WeakMap();
|
|
163
208
|
function defaultWorkerId() {
|
|
164
209
|
// The API documents the worker id as a *unique* identifier for Redis consumer
|
|
165
210
|
// groups, so the fallback must be unique even when several pollers share a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.mjs","sourceRoot":"","sources":["../../src/lib/environments/poller.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,cAAc,EAAE,6BAAyB;AAGlD,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"poller.mjs","sourceRoot":"","sources":["../../src/lib/environments/poller.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,cAAc,EAAE,6BAAyB;AAGlD,OAAO,EAAE,SAAS,EAAe,qCAAiC;AAClE,OAAO,EAAE,KAAK,EAAE,uCAAmC;AACnD,OAAO,EAAE,KAAK,EAAE,sCAAkC;AAClD,OAAO,EAAE,SAAS,EAAE,uCAAmC;AACvD,OAAO,EAAE,YAAY,EAAE,mCAA+B;AAEtD,OAAO,EACL,WAAW,EACX,OAAO,IAAI,UAAU,EACrB,UAAU,EACV,QAAQ,EACR,MAAM,GACP,yCAAqC;AACtC,OAAO,EAAE,mBAAmB,EAAE,6BAAyB;AAEvD,OAAO,EAAE,KAAK,EAAE,UAAU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AAI,0BAAW,KAAK,SAAS,EAAE,CAAC;YAClC,uBAAA,IAAI,sBAAc,uBAAA,IAAI,uBAAe,GAAG,MAAA,MAAA,CAAC;YACzC,uBAAA,IAAI,oBAAK,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;QACnD,CAAC;aAAM,IAAI,GAAG,GAAG,uBAAA,IAAI,2BAAY,IAAI,uBAAuB,EAAE,CAAC;YAC7D,uBAAA,IAAI,uBAAe,GAAG,MAAA,CAAC;YACvB,uBAAA,IAAI,oBAAK,CAAC,IAAI,CAAC,2BAA2B,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,uBAAA,IAAI,0BAAW,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACnG,CAAC;aAAM,CAAC;YACN,uBAAA,IAAI,oBAAK,CAAC,KAAK,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO;QACL,uBAAA,IAAI,sBAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;CACF;;AAED,SAAS,eAAe;IACtB,8EAA8E;IAC9E,2EAA2E;IAC3E,+EAA+E;IAC/E,8BAA8B;IAC9B,MAAM,GAAG,GAAI,UAAyE,CAAC,OAAO,EAAE,GAAG,CAAC;IACpG,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Anthropic } from "../../client.mjs";
|
|
2
2
|
import type { BetaRunnableTool } from "../tools/BetaRunnableTool.mjs";
|
|
3
3
|
import type { BetaToolRunnerRequestOptions } from "../tools/BetaToolRunner.mjs";
|
|
4
|
-
import type { AgentToolContext } from "../../tools/agent-toolset/node.mjs";
|
|
4
|
+
import type { AgentToolContext, MemoryDeleteMode } from "../../tools/agent-toolset/node.mjs";
|
|
5
5
|
/**
|
|
6
6
|
* Either a fixed tool array or a factory invoked once per claimed session with
|
|
7
7
|
* that session's {@link AgentToolContext} — use the factory form to bind
|
|
@@ -17,10 +17,11 @@ export interface EnvironmentWorkerOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
environmentId?: string;
|
|
19
19
|
/**
|
|
20
|
-
* The environment key — the
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* to `ANTHROPIC_ENVIRONMENT_KEY` in
|
|
20
|
+
* The environment key — the worker's standing credential: polling always
|
|
21
|
+
* uses it, and per-session calls fall back to it when a claimed item's
|
|
22
|
+
* `secret` doesn't yield a sessions token. Required by
|
|
23
|
+
* {@link EnvironmentWorker.run}; falls back to `ANTHROPIC_ENVIRONMENT_KEY` in
|
|
24
|
+
* {@link EnvironmentWorker.handleItem}.
|
|
24
25
|
*/
|
|
25
26
|
environmentKey?: string;
|
|
26
27
|
/**
|
|
@@ -35,12 +36,41 @@ export interface EnvironmentWorkerOptions {
|
|
|
35
36
|
tools?: EnvironmentWorkerTools;
|
|
36
37
|
/** Base directory for the per-session {@link AgentToolContext}. Defaults to `process.cwd()`. */
|
|
37
38
|
workdir?: string;
|
|
38
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated No longer accepted: the file tools are always confined to
|
|
41
|
+
* `workdir` plus `allowedRoots`, which is neither behavior this flag used to
|
|
42
|
+
* select, so passing either value throws. Remove it; list extra directories
|
|
43
|
+
* in {@link AgentToolContext.allowedRoots}. The property is removed in a
|
|
44
|
+
* future release.
|
|
45
|
+
*/
|
|
39
46
|
unrestrictedPaths?: boolean;
|
|
40
47
|
/** Forwarded to the per-session {@link AgentToolContext} (`maxFileBytes`). */
|
|
41
48
|
maxFileBytes?: number | null;
|
|
42
49
|
/** Forwarded to {@link SessionToolRunner} (`maxIdleMs`). */
|
|
43
50
|
maxIdleMs?: number;
|
|
51
|
+
/**
|
|
52
|
+
* How often (milliseconds) to sync the session's attached memory stores back
|
|
53
|
+
* while it runs — checked after each dispatched tool call, plus one final
|
|
54
|
+
* sync when the session ends cleanly. Defaults to
|
|
55
|
+
* `DEFAULT_MEMORY_SYNC_INTERVAL_MS` (15s); the constructor throws for
|
|
56
|
+
* values below `MIN_MEMORY_SYNC_INTERVAL_MS` (5s). Every teardown also runs
|
|
57
|
+
* a push-only flush of changed files; that flush and the final sync are
|
|
58
|
+
* each bounded by `MEMORY_FLUSH_TIMEOUT_MS`, and a warning is logged when
|
|
59
|
+
* either bound cuts work off. `null` disables memory download and sync
|
|
60
|
+
* entirely. Memory stores are only touched for work items whose `secret`
|
|
61
|
+
* carries a `sessions_token`; while sync is enabled, an item without one
|
|
62
|
+
* fails when its session has memory stores attached, because those stores
|
|
63
|
+
* cannot be mounted without the token. With `null` the same item runs,
|
|
64
|
+
* without memory, and nothing is logged — turning sync off is the
|
|
65
|
+
* operator's explicit choice.
|
|
66
|
+
*/
|
|
67
|
+
memorySyncIntervalMs?: number | null;
|
|
68
|
+
/**
|
|
69
|
+
* Whether local file deletions may delete on the server — see
|
|
70
|
+
* {@link MemoryDeleteMode}. Uploads and pulls are unaffected.
|
|
71
|
+
* Defaults to `"enabled"`.
|
|
72
|
+
*/
|
|
73
|
+
memorySyncDeletions?: MemoryDeleteMode;
|
|
44
74
|
/** Forwarded to the {@link WorkPoller}. */
|
|
45
75
|
workerId?: string;
|
|
46
76
|
/** External abort signal; aborting it ends the run. */
|
|
@@ -74,9 +104,30 @@ export interface HandleItemOptions {
|
|
|
74
104
|
* `ANTHROPIC_ENVIRONMENT_KEY`.
|
|
75
105
|
*/
|
|
76
106
|
environmentKey?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The work item's per-item `secret` payload from the poll response. Falls
|
|
109
|
+
* back to `ANTHROPIC_WORK_SECRET`. Unlike the others it is optional — when
|
|
110
|
+
* present, the sessions token extracted from it is preferred as the Bearer
|
|
111
|
+
* credential for this item's heartbeat / force-stop / skill-download /
|
|
112
|
+
* session calls; when absent (or undecodable) those calls use the
|
|
113
|
+
* environment key.
|
|
114
|
+
*/
|
|
115
|
+
workSecret?: string;
|
|
77
116
|
/** External abort signal; aborting it ends the run. Defaults to the constructor's signal. */
|
|
78
117
|
signal?: AbortSignal;
|
|
79
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Extract the per-item sessions token from a work item's `secret` payload.
|
|
121
|
+
*
|
|
122
|
+
* The `secret` the poll response populates is not itself a credential: it is a
|
|
123
|
+
* URL-safe base64 JSON payload matching {@link BetaWorkSecret} — the
|
|
124
|
+
* `sessions_token` (the bearer for this item's work lifecycle and
|
|
125
|
+
* session-level calls) plus fields this worker does not consume. Returns the
|
|
126
|
+
* sessions token, or `null` (meaning: fall back to the environment key) when
|
|
127
|
+
* the payload is missing, doesn't decode, or carries no token. Never log the
|
|
128
|
+
* payload or anything extracted from it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function sessionsTokenFromSecret(secret: string | null | undefined): string | null;
|
|
80
131
|
/**
|
|
81
132
|
* The self-hosted environment runner, composed from the control-plane
|
|
82
133
|
* {@link WorkPoller} and the per-session {@link SessionToolRunner}.
|
|
@@ -85,9 +136,17 @@ export interface HandleItemOptions {
|
|
|
85
136
|
* {@link AgentToolContext}, downloads the session agent's skills
|
|
86
137
|
* (`setupSkills`), then runs a {@link SessionToolRunner} for the session
|
|
87
138
|
* while heartbeating the work-item lease on the same event loop; on exit it
|
|
88
|
-
* force-stops the work item
|
|
89
|
-
*
|
|
90
|
-
*
|
|
139
|
+
* force-stops the work item (unless the lease was lost, in which case the item
|
|
140
|
+
* is left to whoever holds it now), cleans up the downloaded skills, and loops
|
|
141
|
+
* to the next one. The lease heartbeat reports `state === "stopping"` / a lost
|
|
142
|
+
* lease back into the run by aborting the session runner.
|
|
143
|
+
*
|
|
144
|
+
* The `environmentKey` is the worker's standing credential. When a claimed
|
|
145
|
+
* work item carries a per-item `secret` (a short-lived payload the poll
|
|
146
|
+
* response may populate), the sessions token extracted from it is preferred
|
|
147
|
+
* over the environment key for that item's heartbeat / force-stop /
|
|
148
|
+
* skill-download / session calls; polling itself always uses the environment
|
|
149
|
+
* key, and items without a usable secret fall back to it entirely.
|
|
91
150
|
*
|
|
92
151
|
* Use {@link EnvironmentWorker.handleItem} if you already hold a claimed work
|
|
93
152
|
* item (e.g. a `worker poll --on-work` script handed one to a fresh process) and
|
|
@@ -115,12 +174,19 @@ export declare class EnvironmentWorker {
|
|
|
115
174
|
readonly environmentKey: string | undefined;
|
|
116
175
|
readonly tools: EnvironmentWorkerTools | undefined;
|
|
117
176
|
readonly workdir: string;
|
|
177
|
+
/** @deprecated Never set; see {@link EnvironmentWorkerOptions.unrestrictedPaths}. */
|
|
118
178
|
readonly unrestrictedPaths: boolean | undefined;
|
|
119
179
|
readonly maxFileBytes: number | null | undefined;
|
|
120
180
|
readonly maxIdleMs: number | undefined;
|
|
181
|
+
readonly memorySyncIntervalMs: number | null | undefined;
|
|
182
|
+
readonly memorySyncDeletions: MemoryDeleteMode;
|
|
121
183
|
readonly workerId: string | undefined;
|
|
122
184
|
readonly requestOptions: BetaToolRunnerRequestOptions | undefined;
|
|
123
|
-
constructor(opts: EnvironmentWorkerOptions);
|
|
185
|
+
constructor(opts: Omit<EnvironmentWorkerOptions, 'unrestrictedPaths'>);
|
|
186
|
+
/** @deprecated `unrestrictedPaths` is no longer accepted — see {@link EnvironmentWorkerOptions.unrestrictedPaths}. */
|
|
187
|
+
constructor(opts: Omit<EnvironmentWorkerOptions, 'unrestrictedPaths'> & {
|
|
188
|
+
unrestrictedPaths: boolean;
|
|
189
|
+
});
|
|
124
190
|
/**
|
|
125
191
|
* Poll the environment and service each claimed session until the supplied
|
|
126
192
|
* signal (or the one passed to the constructor) aborts. Throws if
|
|
@@ -133,7 +199,9 @@ export declare class EnvironmentWorker {
|
|
|
133
199
|
* download the session agent's skills (`setupSkills`), run a
|
|
134
200
|
* {@link SessionToolRunner} for the session while heartbeating the work-item
|
|
135
201
|
* lease, and force-stop the work item on exit (whether the runner finishes
|
|
136
|
-
* normally, throws, or the
|
|
202
|
+
* normally, throws, or the control plane signals shutdown). The one
|
|
203
|
+
* exception is a lost lease: the item then belongs to the queue or another
|
|
204
|
+
* worker and is left alone.
|
|
137
205
|
*
|
|
138
206
|
* Use this when something else does the claiming — e.g. a `worker poll
|
|
139
207
|
* --on-work` script that hands an already-claimed item to a fresh process. The
|
|
@@ -143,7 +211,16 @@ export declare class EnvironmentWorker {
|
|
|
143
211
|
* option, then the worker's own `environmentKey`, then
|
|
144
212
|
* `ANTHROPIC_ENVIRONMENT_KEY`. With no arguments inside that command it just
|
|
145
213
|
* works. Throws a clear error naming the first of the four required values
|
|
146
|
-
* still missing after resolution.
|
|
214
|
+
* still missing after resolution. Throws `SessionMemoryError` when the
|
|
215
|
+
* session has memory stores attached but they cannot be mounted — the work
|
|
216
|
+
* item carried no sessions token (unless `memorySyncIntervalMs` turned
|
|
217
|
+
* memory off), or a store failed to download.
|
|
218
|
+
*
|
|
219
|
+
* `workSecret` is the work item's per-item `secret` payload from the poll
|
|
220
|
+
* response, falling back to `ANTHROPIC_WORK_SECRET`; unlike the others it is
|
|
221
|
+
* optional — when present, the sessions token extracted from it is preferred
|
|
222
|
+
* as the Bearer credential for this item's heartbeat / force-stop / session
|
|
223
|
+
* calls; when absent (or undecodable) those calls use the environment key.
|
|
147
224
|
*/
|
|
148
225
|
handleItem(opts?: HandleItemOptions): Promise<void>;
|
|
149
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.mts","sourceRoot":"","sources":["../../src/lib/environments/worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;
|
|
1
|
+
{"version":3,"file":"worker.d.mts","sourceRoot":"","sources":["../../src/lib/environments/worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAqB;AAW9C,OAAO,KAAK,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AAA;KAAE;IA6BtG;;;;OAIG;IACG,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,UAAU,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAoP1D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Anthropic } from "../../client.js";
|
|
2
2
|
import type { BetaRunnableTool } from "../tools/BetaRunnableTool.js";
|
|
3
3
|
import type { BetaToolRunnerRequestOptions } from "../tools/BetaToolRunner.js";
|
|
4
|
-
import type { AgentToolContext } from "../../tools/agent-toolset/node.js";
|
|
4
|
+
import type { AgentToolContext, MemoryDeleteMode } from "../../tools/agent-toolset/node.js";
|
|
5
5
|
/**
|
|
6
6
|
* Either a fixed tool array or a factory invoked once per claimed session with
|
|
7
7
|
* that session's {@link AgentToolContext} — use the factory form to bind
|
|
@@ -17,10 +17,11 @@ export interface EnvironmentWorkerOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
environmentId?: string;
|
|
19
19
|
/**
|
|
20
|
-
* The environment key — the
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* to `ANTHROPIC_ENVIRONMENT_KEY` in
|
|
20
|
+
* The environment key — the worker's standing credential: polling always
|
|
21
|
+
* uses it, and per-session calls fall back to it when a claimed item's
|
|
22
|
+
* `secret` doesn't yield a sessions token. Required by
|
|
23
|
+
* {@link EnvironmentWorker.run}; falls back to `ANTHROPIC_ENVIRONMENT_KEY` in
|
|
24
|
+
* {@link EnvironmentWorker.handleItem}.
|
|
24
25
|
*/
|
|
25
26
|
environmentKey?: string;
|
|
26
27
|
/**
|
|
@@ -35,12 +36,41 @@ export interface EnvironmentWorkerOptions {
|
|
|
35
36
|
tools?: EnvironmentWorkerTools;
|
|
36
37
|
/** Base directory for the per-session {@link AgentToolContext}. Defaults to `process.cwd()`. */
|
|
37
38
|
workdir?: string;
|
|
38
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated No longer accepted: the file tools are always confined to
|
|
41
|
+
* `workdir` plus `allowedRoots`, which is neither behavior this flag used to
|
|
42
|
+
* select, so passing either value throws. Remove it; list extra directories
|
|
43
|
+
* in {@link AgentToolContext.allowedRoots}. The property is removed in a
|
|
44
|
+
* future release.
|
|
45
|
+
*/
|
|
39
46
|
unrestrictedPaths?: boolean;
|
|
40
47
|
/** Forwarded to the per-session {@link AgentToolContext} (`maxFileBytes`). */
|
|
41
48
|
maxFileBytes?: number | null;
|
|
42
49
|
/** Forwarded to {@link SessionToolRunner} (`maxIdleMs`). */
|
|
43
50
|
maxIdleMs?: number;
|
|
51
|
+
/**
|
|
52
|
+
* How often (milliseconds) to sync the session's attached memory stores back
|
|
53
|
+
* while it runs — checked after each dispatched tool call, plus one final
|
|
54
|
+
* sync when the session ends cleanly. Defaults to
|
|
55
|
+
* `DEFAULT_MEMORY_SYNC_INTERVAL_MS` (15s); the constructor throws for
|
|
56
|
+
* values below `MIN_MEMORY_SYNC_INTERVAL_MS` (5s). Every teardown also runs
|
|
57
|
+
* a push-only flush of changed files; that flush and the final sync are
|
|
58
|
+
* each bounded by `MEMORY_FLUSH_TIMEOUT_MS`, and a warning is logged when
|
|
59
|
+
* either bound cuts work off. `null` disables memory download and sync
|
|
60
|
+
* entirely. Memory stores are only touched for work items whose `secret`
|
|
61
|
+
* carries a `sessions_token`; while sync is enabled, an item without one
|
|
62
|
+
* fails when its session has memory stores attached, because those stores
|
|
63
|
+
* cannot be mounted without the token. With `null` the same item runs,
|
|
64
|
+
* without memory, and nothing is logged — turning sync off is the
|
|
65
|
+
* operator's explicit choice.
|
|
66
|
+
*/
|
|
67
|
+
memorySyncIntervalMs?: number | null;
|
|
68
|
+
/**
|
|
69
|
+
* Whether local file deletions may delete on the server — see
|
|
70
|
+
* {@link MemoryDeleteMode}. Uploads and pulls are unaffected.
|
|
71
|
+
* Defaults to `"enabled"`.
|
|
72
|
+
*/
|
|
73
|
+
memorySyncDeletions?: MemoryDeleteMode;
|
|
44
74
|
/** Forwarded to the {@link WorkPoller}. */
|
|
45
75
|
workerId?: string;
|
|
46
76
|
/** External abort signal; aborting it ends the run. */
|
|
@@ -74,9 +104,30 @@ export interface HandleItemOptions {
|
|
|
74
104
|
* `ANTHROPIC_ENVIRONMENT_KEY`.
|
|
75
105
|
*/
|
|
76
106
|
environmentKey?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The work item's per-item `secret` payload from the poll response. Falls
|
|
109
|
+
* back to `ANTHROPIC_WORK_SECRET`. Unlike the others it is optional — when
|
|
110
|
+
* present, the sessions token extracted from it is preferred as the Bearer
|
|
111
|
+
* credential for this item's heartbeat / force-stop / skill-download /
|
|
112
|
+
* session calls; when absent (or undecodable) those calls use the
|
|
113
|
+
* environment key.
|
|
114
|
+
*/
|
|
115
|
+
workSecret?: string;
|
|
77
116
|
/** External abort signal; aborting it ends the run. Defaults to the constructor's signal. */
|
|
78
117
|
signal?: AbortSignal;
|
|
79
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Extract the per-item sessions token from a work item's `secret` payload.
|
|
121
|
+
*
|
|
122
|
+
* The `secret` the poll response populates is not itself a credential: it is a
|
|
123
|
+
* URL-safe base64 JSON payload matching {@link BetaWorkSecret} — the
|
|
124
|
+
* `sessions_token` (the bearer for this item's work lifecycle and
|
|
125
|
+
* session-level calls) plus fields this worker does not consume. Returns the
|
|
126
|
+
* sessions token, or `null` (meaning: fall back to the environment key) when
|
|
127
|
+
* the payload is missing, doesn't decode, or carries no token. Never log the
|
|
128
|
+
* payload or anything extracted from it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function sessionsTokenFromSecret(secret: string | null | undefined): string | null;
|
|
80
131
|
/**
|
|
81
132
|
* The self-hosted environment runner, composed from the control-plane
|
|
82
133
|
* {@link WorkPoller} and the per-session {@link SessionToolRunner}.
|
|
@@ -85,9 +136,17 @@ export interface HandleItemOptions {
|
|
|
85
136
|
* {@link AgentToolContext}, downloads the session agent's skills
|
|
86
137
|
* (`setupSkills`), then runs a {@link SessionToolRunner} for the session
|
|
87
138
|
* while heartbeating the work-item lease on the same event loop; on exit it
|
|
88
|
-
* force-stops the work item
|
|
89
|
-
*
|
|
90
|
-
*
|
|
139
|
+
* force-stops the work item (unless the lease was lost, in which case the item
|
|
140
|
+
* is left to whoever holds it now), cleans up the downloaded skills, and loops
|
|
141
|
+
* to the next one. The lease heartbeat reports `state === "stopping"` / a lost
|
|
142
|
+
* lease back into the run by aborting the session runner.
|
|
143
|
+
*
|
|
144
|
+
* The `environmentKey` is the worker's standing credential. When a claimed
|
|
145
|
+
* work item carries a per-item `secret` (a short-lived payload the poll
|
|
146
|
+
* response may populate), the sessions token extracted from it is preferred
|
|
147
|
+
* over the environment key for that item's heartbeat / force-stop /
|
|
148
|
+
* skill-download / session calls; polling itself always uses the environment
|
|
149
|
+
* key, and items without a usable secret fall back to it entirely.
|
|
91
150
|
*
|
|
92
151
|
* Use {@link EnvironmentWorker.handleItem} if you already hold a claimed work
|
|
93
152
|
* item (e.g. a `worker poll --on-work` script handed one to a fresh process) and
|
|
@@ -115,12 +174,19 @@ export declare class EnvironmentWorker {
|
|
|
115
174
|
readonly environmentKey: string | undefined;
|
|
116
175
|
readonly tools: EnvironmentWorkerTools | undefined;
|
|
117
176
|
readonly workdir: string;
|
|
177
|
+
/** @deprecated Never set; see {@link EnvironmentWorkerOptions.unrestrictedPaths}. */
|
|
118
178
|
readonly unrestrictedPaths: boolean | undefined;
|
|
119
179
|
readonly maxFileBytes: number | null | undefined;
|
|
120
180
|
readonly maxIdleMs: number | undefined;
|
|
181
|
+
readonly memorySyncIntervalMs: number | null | undefined;
|
|
182
|
+
readonly memorySyncDeletions: MemoryDeleteMode;
|
|
121
183
|
readonly workerId: string | undefined;
|
|
122
184
|
readonly requestOptions: BetaToolRunnerRequestOptions | undefined;
|
|
123
|
-
constructor(opts: EnvironmentWorkerOptions);
|
|
185
|
+
constructor(opts: Omit<EnvironmentWorkerOptions, 'unrestrictedPaths'>);
|
|
186
|
+
/** @deprecated `unrestrictedPaths` is no longer accepted — see {@link EnvironmentWorkerOptions.unrestrictedPaths}. */
|
|
187
|
+
constructor(opts: Omit<EnvironmentWorkerOptions, 'unrestrictedPaths'> & {
|
|
188
|
+
unrestrictedPaths: boolean;
|
|
189
|
+
});
|
|
124
190
|
/**
|
|
125
191
|
* Poll the environment and service each claimed session until the supplied
|
|
126
192
|
* signal (or the one passed to the constructor) aborts. Throws if
|
|
@@ -133,7 +199,9 @@ export declare class EnvironmentWorker {
|
|
|
133
199
|
* download the session agent's skills (`setupSkills`), run a
|
|
134
200
|
* {@link SessionToolRunner} for the session while heartbeating the work-item
|
|
135
201
|
* lease, and force-stop the work item on exit (whether the runner finishes
|
|
136
|
-
* normally, throws, or the
|
|
202
|
+
* normally, throws, or the control plane signals shutdown). The one
|
|
203
|
+
* exception is a lost lease: the item then belongs to the queue or another
|
|
204
|
+
* worker and is left alone.
|
|
137
205
|
*
|
|
138
206
|
* Use this when something else does the claiming — e.g. a `worker poll
|
|
139
207
|
* --on-work` script that hands an already-claimed item to a fresh process. The
|
|
@@ -143,7 +211,16 @@ export declare class EnvironmentWorker {
|
|
|
143
211
|
* option, then the worker's own `environmentKey`, then
|
|
144
212
|
* `ANTHROPIC_ENVIRONMENT_KEY`. With no arguments inside that command it just
|
|
145
213
|
* works. Throws a clear error naming the first of the four required values
|
|
146
|
-
* still missing after resolution.
|
|
214
|
+
* still missing after resolution. Throws `SessionMemoryError` when the
|
|
215
|
+
* session has memory stores attached but they cannot be mounted — the work
|
|
216
|
+
* item carried no sessions token (unless `memorySyncIntervalMs` turned
|
|
217
|
+
* memory off), or a store failed to download.
|
|
218
|
+
*
|
|
219
|
+
* `workSecret` is the work item's per-item `secret` payload from the poll
|
|
220
|
+
* response, falling back to `ANTHROPIC_WORK_SECRET`; unlike the others it is
|
|
221
|
+
* optional — when present, the sessions token extracted from it is preferred
|
|
222
|
+
* as the Bearer credential for this item's heartbeat / force-stop / session
|
|
223
|
+
* calls; when absent (or undecodable) those calls use the environment key.
|
|
147
224
|
*/
|
|
148
225
|
handleItem(opts?: HandleItemOptions): Promise<void>;
|
|
149
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/lib/environments/worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAqB;
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/lib/environments/worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAqB;AAW9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qCAAkC;AAClE,OAAO,KAAK,EAAE,4BAA4B,EAAE,mCAAgC;AAU5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAuB,0CAAuC;AAQ9G;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B,KAAK,CAAC,gBAAgB,CAAC,GACvB,CAAC,CAAC,GAAG,EAAE,gBAAgB,KAAK,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAEzD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,gGAAgG;IAChG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;OAeG;IACH,oBAAoB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