@animalabs/agent-framework 0.24.0 → 0.25.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/src/agent.d.ts +5 -0
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +27 -8
- package/dist/src/agent.js.map +1 -1
- package/dist/src/clock-rows.d.ts +115 -0
- package/dist/src/clock-rows.d.ts.map +1 -0
- package/dist/src/clock-rows.js +222 -0
- package/dist/src/clock-rows.js.map +1 -0
- package/dist/src/framework.d.ts +98 -6
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +514 -80
- package/dist/src/framework.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +9 -0
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +49 -6
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/protocol-family.js +1 -1
- package/dist/src/mcpl/references.d.ts +4 -1
- package/dist/src/mcpl/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +5 -2
- package/dist/src/mcpl/references.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +9 -1
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +118 -28
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +6 -2
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/text-as-stored.d.ts +31 -0
- package/dist/src/text-as-stored.d.ts.map +1 -0
- package/dist/src/text-as-stored.js +70 -0
- package/dist/src/text-as-stored.js.map +1 -0
- package/dist/src/timezone.d.ts +4 -2
- package/dist/src/timezone.d.ts.map +1 -1
- package/dist/src/timezone.js +4 -2
- package/dist/src/timezone.js.map +1 -1
- package/dist/src/tool-image-ledger.d.ts +46 -7
- package/dist/src/tool-image-ledger.d.ts.map +1 -1
- package/dist/src/tool-image-ledger.js +60 -7
- package/dist/src/tool-image-ledger.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +9 -1
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +10 -8
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +12 -10
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +17 -6
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +35 -10
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/tune-out/coordinator.js +3 -3
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/types/agent.d.ts +27 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +13 -3
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +7 -4
- package/dist/src/types/framework.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agent.ts +27 -8
- package/src/clock-rows.ts +302 -0
- package/src/framework.ts +538 -85
- package/src/index.ts +2 -0
- package/src/mcpl/channel-registry.ts +54 -8
- package/src/mcpl/protocol-family.ts +1 -1
- package/src/mcpl/references.ts +5 -2
- package/src/modules/workspace/index.ts +121 -29
- package/src/modules/workspace/types.ts +6 -2
- package/src/text-as-stored.ts +73 -0
- package/src/timezone.ts +4 -2
- package/src/tool-image-ledger.ts +62 -8
- package/src/tool-presentation.ts +8 -1
- package/src/tool-result-guard.ts +12 -10
- package/src/tool-result-history.ts +35 -9
- package/src/tune-out/coordinator.ts +3 -3
- package/src/types/agent.ts +28 -0
- package/src/types/events.ts +13 -3
- package/src/types/framework.ts +7 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRo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CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,gBAAgB,CAAC;IACvB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,SAAS,EAAE,SAAS,CAAC;IACrB,kBAAkB;IAClB,UAAU,EAAE,YAAY,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,iBAAiB,CAAC;IACxB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,cAAc,CAAC;IACrB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iCAAiC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/types/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,IAAI,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GACpB,oBAAoB,GACpB,aAAa,GACb,eAAe,GACf,eAAe,GACf,qBAAqB,GACrB,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,eAAe,GACf,wBAAwB,GACxB,aAAa,GACb,wBAAwB,GACxB,WAAW,CAAC;AAEhB;;GA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AAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -107,9 +107,10 @@ export interface FrameworkConfig {
|
|
|
107
107
|
*/
|
|
108
108
|
subconscious?: import('../tune-out/tools.js').SubconsciousConfig;
|
|
109
109
|
/**
|
|
110
|
-
* IANA zone
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* IANA zone of the agent's wall clock: it renders wall-clock times for the
|
|
111
|
+
* agent, and it sets where clock rows' boundaries fall (AgentConfig.clock,
|
|
112
|
+
* counted from local midnight here). Stored/protocol timestamps remain
|
|
113
|
+
* epoch/UTC. Defaults to AGENT_TIMEZONE, then the process zone.
|
|
113
114
|
*/
|
|
114
115
|
timeZone?: string;
|
|
115
116
|
/** Path to Chronicle store */
|
|
@@ -217,7 +218,9 @@ export interface FrameworkConfig {
|
|
|
217
218
|
* takes precedence over this for that agent; the EFFECTIVE cap for every
|
|
218
219
|
* source is min(desired, strategy bound) — desired values above the
|
|
219
220
|
* strategy-derived bound (maxMessageTokens * 4) are hard-clamped to it,
|
|
220
|
-
* with the clamp reported via agent_settings get.
|
|
221
|
+
* with the clamp reported via agent_settings get. For an ordinary resident
|
|
222
|
+
* the bound is the smallest among the agents that read the shared slot,
|
|
223
|
+
* reported as clamped by `reader-bound` when another reader's sets it.
|
|
221
224
|
*/
|
|
222
225
|
toolResultInlineMaxChars?: number;
|
|
223
226
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework.d.ts","sourceRoot":"","sources":["../../../src/types/framework.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;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;IACrC,kCAAkC;IAClC,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,2CAA2C;IAC3C,eAAe,EAAE,OAAO,CAAC;CAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animalabs/agent-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Multi-agent framework with pluggable modules, persistent state, and concurrent tool execution",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@animalabs/chronicle": "^0.4.0",
|
|
52
|
-
"@animalabs/context-manager": "^0.
|
|
53
|
-
"@animalabs/membrane": "^0.6.
|
|
52
|
+
"@animalabs/context-manager": "^0.19.0",
|
|
53
|
+
"@animalabs/membrane": "^0.6.1",
|
|
54
54
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
55
55
|
"chokidar": "^4.0.3",
|
|
56
56
|
"discord.js": "^14.25.1",
|
package/src/agent.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import type { CacheWireReceipt, KvUnifiedRequestHooks } from './kv-unified-wire.js';
|
|
5
5
|
import { ToolResultGuard } from './tool-result-guard.js';
|
|
6
6
|
import { withoutTokenEstimates } from './thinking-token-stamp.js';
|
|
7
|
+
import { injectionsAsStored } from './text-as-stored.js';
|
|
7
8
|
import { assertBooleanSetting, holdsSettings } from './config-checks.js';
|
|
8
9
|
import {
|
|
9
10
|
CONTINUE_ROW,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
type StoredRowLike,
|
|
20
21
|
} from './silent-heartbeat.js';
|
|
21
22
|
import { randomUUID } from 'node:crypto';
|
|
23
|
+
import { resolveClockConfig, type ResolvedClockConfig } from './clock-rows.js';
|
|
22
24
|
import {
|
|
23
25
|
nonErrorResultText,
|
|
24
26
|
truncateForHistory,
|
|
@@ -167,6 +169,10 @@ export class Agent {
|
|
|
167
169
|
readonly proseRouting: 'locus' | 'explicit' | 'hybrid' | 'disabled';
|
|
168
170
|
/** Exact whole-response known-tool wrapper containment (default off). */
|
|
169
171
|
readonly toolWrapperProseGuard: boolean;
|
|
172
|
+
/** Clock rows' interval and precision (see AgentConfig.clock); undefined
|
|
173
|
+
* when the agent writes none of its own (a resident still reads those
|
|
174
|
+
* another resident writes into the shared slot). */
|
|
175
|
+
readonly clock: ResolvedClockConfig | undefined;
|
|
170
176
|
/** Prompt-cache TTL forwarded to the provider (see AgentConfig.cacheTtl). */
|
|
171
177
|
readonly cacheTtl: NonNullable<AgentConfig['cacheTtl']>;
|
|
172
178
|
/** Emit prompt-cache markers on requests (see AgentConfig.promptCaching). */
|
|
@@ -296,6 +302,7 @@ export class Agent {
|
|
|
296
302
|
this.toolResultGuard = new ToolResultGuard(config.name, contextManager, config.toolResultGuard === true);
|
|
297
303
|
this.proseRouting = config.proseRouting ?? 'locus';
|
|
298
304
|
this.toolWrapperProseGuard = config.toolWrapperProseGuard === true;
|
|
305
|
+
this.clock = resolveClockConfig(config.name, config.clock);
|
|
299
306
|
this.cacheTtl = config.cacheTtl ?? '1h';
|
|
300
307
|
this.promptCaching = config.promptCaching !== false;
|
|
301
308
|
this.prefillUserMessage = config.prefillUserMessage;
|
|
@@ -1151,6 +1158,8 @@ export class Agent {
|
|
|
1151
1158
|
if (this._state.status === 'inferring') {
|
|
1152
1159
|
throw new Error(`Agent ${this.name} is already inferring`);
|
|
1153
1160
|
}
|
|
1161
|
+
// Unstored, so they leave for the request here (text-as-stored.ts).
|
|
1162
|
+
injections = injectionsAsStored(injections);
|
|
1154
1163
|
|
|
1155
1164
|
if (this._state.status === 'waiting_for_tools') {
|
|
1156
1165
|
throw new Error(`Agent ${this.name} is waiting for tool results`);
|
|
@@ -1326,6 +1335,9 @@ export class Agent {
|
|
|
1326
1335
|
compressionTools: ToolDefinition[] = availableTools,
|
|
1327
1336
|
options: ActivationRequestOptions = {},
|
|
1328
1337
|
): Promise<{ request: NormalizedRequest; continuePrompt?: RequestOnlyPrompt }> {
|
|
1338
|
+
// Unstored, so they leave for the request here (text-as-stored.ts), the
|
|
1339
|
+
// layout hash below included.
|
|
1340
|
+
injections = injectionsAsStored(injections);
|
|
1329
1341
|
// Compression may revisit hidden tools in recorded history. Keep its full
|
|
1330
1342
|
// definition set separate from the resident's advertised tools: the
|
|
1331
1343
|
// autobiographical strategy must declare the same tools on its
|
|
@@ -1915,14 +1927,21 @@ export class Agent {
|
|
|
1915
1927
|
// via buildStoredToolResultContent, with workspace spill). No workspace
|
|
1916
1928
|
// is reachable from here, so the house default cap applies as plain
|
|
1917
1929
|
// truncation — bounded beats unbounded, for errors too.
|
|
1918
|
-
const content = results.map((r) =>
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1930
|
+
const content = results.map((r) => {
|
|
1931
|
+
// This API's results are unchecked (nonErrorResultText), so each field
|
|
1932
|
+
// is read once, and only an error that is a string is made well formed;
|
|
1933
|
+
// any other error value is passed on as it was before.
|
|
1934
|
+
const isError = r.result.isError;
|
|
1935
|
+
const error: unknown = isError ? r.result.error ?? 'Unknown error' : undefined;
|
|
1936
|
+
return {
|
|
1937
|
+
type: 'tool_result' as const,
|
|
1938
|
+
toolUseId: r.id,
|
|
1939
|
+
content: isError
|
|
1940
|
+
? truncateForHistory(typeof error === 'string' ? error.toWellFormed() : error as string, DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS)
|
|
1941
|
+
: nonErrorResultText(r.result, DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS),
|
|
1942
|
+
isError,
|
|
1943
|
+
};
|
|
1944
|
+
});
|
|
1926
1945
|
|
|
1927
1946
|
return [{
|
|
1928
1947
|
participant: 'user',
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clock rows: a time marker an agent's window takes when an interval
|
|
3
|
+
* boundary has passed since the last one it holds.
|
|
4
|
+
*
|
|
5
|
+
* The model is a tick event at every boundary of the agent's local wall
|
|
6
|
+
* clock (every 10 minutes, say, from local midnight). The ticks aren't
|
|
7
|
+
* written as they fire. One is written when the window next takes something
|
|
8
|
+
* (an incoming event, a tool round's results, the start of a turn), and only
|
|
9
|
+
* the latest of the ticks that fired meanwhile: nothing was written between
|
|
10
|
+
* them, and a clock wakes no one, so the window reads exactly as it would
|
|
11
|
+
* had every tick been written and the earlier ones coalesced away.
|
|
12
|
+
*
|
|
13
|
+
* A clock never lies about order. One that lands where its tick would have
|
|
14
|
+
* been (the row before it is no newer than the boundary) reads the
|
|
15
|
+
* boundary's time, which is in the past by the time it is written. One that
|
|
16
|
+
* can't (the boundary passed while the agent was mid-reply or a tool ran:
|
|
17
|
+
* a tool's results must follow its call directly, so nothing can be written
|
|
18
|
+
* between them) reads the time it is written instead.
|
|
19
|
+
*
|
|
20
|
+
* Everything the next clock needs is read back from the window: the last
|
|
21
|
+
* clock row's time, wherever it is, and the newest row's. A window that
|
|
22
|
+
* holds no clock row takes one the next time it would take a clock (an
|
|
23
|
+
* incoming event, a turn's start, a tool boundary), so a window that has
|
|
24
|
+
* just had a clock turned on, or a fork seeded with copies of its
|
|
25
|
+
* template's rows (which carry none of their metadata), reads the time
|
|
26
|
+
* then. A restart, a rollback or a second resident sharing the window
|
|
27
|
+
* leaves nothing stale to reconcile.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import type { ContentBlock } from '@animalabs/membrane';
|
|
31
|
+
import { resolveTimeZone } from './timezone.js';
|
|
32
|
+
|
|
33
|
+
/** `AgentConfig.clock`: when the agent's window takes clock rows. */
|
|
34
|
+
export interface ClockConfig {
|
|
35
|
+
/** Minutes between boundaries. Give this or `intervalSeconds`. */
|
|
36
|
+
intervalMinutes?: number;
|
|
37
|
+
/** Seconds between boundaries, for clocks finer than a minute. */
|
|
38
|
+
intervalSeconds?: number;
|
|
39
|
+
/**
|
|
40
|
+
* How a clock reads: `'minutes'` (`10:50`) or `'seconds'` (`10:50:30`).
|
|
41
|
+
* Defaults to minutes for an interval of whole minutes, else seconds.
|
|
42
|
+
*/
|
|
43
|
+
precision?: 'minutes' | 'seconds';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ResolvedClockConfig {
|
|
47
|
+
intervalSeconds: number;
|
|
48
|
+
precision: 'minutes' | 'seconds';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `metadata.kind` of a clock row. */
|
|
52
|
+
export const CLOCK_ROW_KIND = 'clock';
|
|
53
|
+
|
|
54
|
+
/** `metadata.clock` of a clock row. */
|
|
55
|
+
export interface ClockStamp {
|
|
56
|
+
/** The instant the row reads, epoch ms. */
|
|
57
|
+
at: number;
|
|
58
|
+
/** Whether that instant is the boundary itself (else, when it was written). */
|
|
59
|
+
onBoundary: boolean;
|
|
60
|
+
/** The IANA zone it reads in. */
|
|
61
|
+
zone: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const DAY_SECONDS = 86_400;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Validate `AgentConfig.clock`. Undefined when the agent has no clock; throws
|
|
68
|
+
* on a setting that can't be read as one, naming the agent.
|
|
69
|
+
*/
|
|
70
|
+
export function resolveClockConfig(agentName: string, config: ClockConfig | undefined): ResolvedClockConfig | undefined {
|
|
71
|
+
if (config === undefined) return undefined;
|
|
72
|
+
const at = `Agent "${agentName}" clock`;
|
|
73
|
+
if (config === null || typeof config !== 'object' || Array.isArray(config)) {
|
|
74
|
+
throw new Error(`${at} must be an object such as { intervalMinutes: 10 }, or left out for no clock rows of its own`);
|
|
75
|
+
}
|
|
76
|
+
const { intervalMinutes, intervalSeconds, precision } = config;
|
|
77
|
+
if ((intervalMinutes === undefined) === (intervalSeconds === undefined)) {
|
|
78
|
+
throw new Error(`${at} takes exactly one of intervalMinutes and intervalSeconds`);
|
|
79
|
+
}
|
|
80
|
+
const given = intervalMinutes !== undefined ? intervalMinutes : intervalSeconds;
|
|
81
|
+
if (typeof given !== 'number' || !Number.isInteger(given) || given <= 0) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`${at}.${intervalMinutes !== undefined ? 'intervalMinutes' : 'intervalSeconds'} must be a positive whole number`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const seconds = intervalMinutes !== undefined ? given * 60 : given;
|
|
87
|
+
if (seconds > DAY_SECONDS) {
|
|
88
|
+
throw new Error(`${at} interval is at most a day (1440 minutes); boundaries count from local midnight`);
|
|
89
|
+
}
|
|
90
|
+
if (precision !== undefined && precision !== 'minutes' && precision !== 'seconds') {
|
|
91
|
+
throw new Error(`${at}.precision must be 'minutes' or 'seconds'`);
|
|
92
|
+
}
|
|
93
|
+
const resolved = precision ?? (seconds % 60 === 0 ? 'minutes' : 'seconds');
|
|
94
|
+
if (resolved === 'minutes' && seconds % 60 !== 0) {
|
|
95
|
+
throw new Error(`${at}: an interval of ${seconds} seconds isn't whole minutes, so its clocks need precision 'seconds'`);
|
|
96
|
+
}
|
|
97
|
+
return { intervalSeconds: seconds, precision: resolved };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Wall-clock arithmetic in a zone
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
interface WallFields {
|
|
105
|
+
year: number;
|
|
106
|
+
month: number;
|
|
107
|
+
day: number;
|
|
108
|
+
hour: number;
|
|
109
|
+
minute: number;
|
|
110
|
+
second: number;
|
|
111
|
+
/** Offset from UTC at this instant, in minutes. */
|
|
112
|
+
offsetMinutes: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const formatters = new Map<string, Intl.DateTimeFormat>();
|
|
116
|
+
|
|
117
|
+
function formatterFor(zone: string): Intl.DateTimeFormat {
|
|
118
|
+
let formatter = formatters.get(zone);
|
|
119
|
+
if (!formatter) {
|
|
120
|
+
formatter = new Intl.DateTimeFormat('en-CA', {
|
|
121
|
+
timeZone: zone,
|
|
122
|
+
year: 'numeric',
|
|
123
|
+
month: '2-digit',
|
|
124
|
+
day: '2-digit',
|
|
125
|
+
hour: '2-digit',
|
|
126
|
+
minute: '2-digit',
|
|
127
|
+
second: '2-digit',
|
|
128
|
+
hourCycle: 'h23',
|
|
129
|
+
});
|
|
130
|
+
formatters.set(zone, formatter);
|
|
131
|
+
}
|
|
132
|
+
return formatter;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function wallFields(at: number, zone: string): WallFields {
|
|
136
|
+
const parts = formatterFor(zone).formatToParts(new Date(at));
|
|
137
|
+
const get = (type: Intl.DateTimeFormatPartTypes): number =>
|
|
138
|
+
Number(parts.find((part) => part.type === type)?.value ?? NaN);
|
|
139
|
+
const fields = {
|
|
140
|
+
year: get('year'),
|
|
141
|
+
month: get('month'),
|
|
142
|
+
day: get('day'),
|
|
143
|
+
hour: get('hour'),
|
|
144
|
+
minute: get('minute'),
|
|
145
|
+
second: get('second'),
|
|
146
|
+
};
|
|
147
|
+
const shownAsUtc = Date.UTC(fields.year, fields.month - 1, fields.day, fields.hour, fields.minute, fields.second);
|
|
148
|
+
const offsetMinutes = Math.round((shownAsUtc - Math.floor(at / 1000) * 1000) / 60_000);
|
|
149
|
+
return { ...fields, offsetMinutes };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The latest boundary at or before `now`: an instant at which the zone's
|
|
154
|
+
* wall clock read a whole multiple of the interval since local midnight. A
|
|
155
|
+
* boundary whose wall time a DST change skips doesn't occur; one it repeats
|
|
156
|
+
* occurs twice.
|
|
157
|
+
*
|
|
158
|
+
* While the zone's offset stays the same, its wall clock runs with real
|
|
159
|
+
* time, so the latest boundary is `now` less how far the wall clock has run
|
|
160
|
+
* past its last multiple of the interval. Where that instant has another
|
|
161
|
+
* offset, the offset changed in between and no boundary falls between the
|
|
162
|
+
* change and `now`: the walk goes on from just before the change. The change
|
|
163
|
+
* is found by searching between the two instants, whatever their offsets
|
|
164
|
+
* are. The same offset at both is taken to mean no change between them: in
|
|
165
|
+
* the tz data, no zone changes its offset twice within a day, the longest
|
|
166
|
+
* interval, from 2024 through 2040. Throws if the walk passes 24 changes,
|
|
167
|
+
* which no real zone reaches, rather than return an instant that isn't a
|
|
168
|
+
* boundary.
|
|
169
|
+
*/
|
|
170
|
+
export function latestBoundary(now: number, intervalSeconds: number, zone: string): number {
|
|
171
|
+
let at = now;
|
|
172
|
+
// A pass that doesn't return steps back past an offset change, and a day
|
|
173
|
+
// of a real zone holds at most two of them; running out of passes is a
|
|
174
|
+
// defect, and it throws rather than return an instant that isn't a boundary.
|
|
175
|
+
for (let pass = 0; pass < 24; pass++) {
|
|
176
|
+
const f = wallFields(at, zone);
|
|
177
|
+
const secondOfDay = f.hour * 3600 + f.minute * 60 + f.second;
|
|
178
|
+
const subSecond = at - Math.floor(at / 1000) * 1000;
|
|
179
|
+
const candidate = at - (secondOfDay % intervalSeconds) * 1000 - subSecond;
|
|
180
|
+
if (wallFields(candidate, zone).offsetMinutes === f.offsetMinutes) return candidate;
|
|
181
|
+
at = offsetTakenAt(candidate, at, f.offsetMinutes, zone) - 1;
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`no clock boundary found within 24 offset changes of ${new Date(now).toISOString()} in ${zone}`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The instant in (`from`, `to`] at which the zone took `offset`, given that
|
|
188
|
+
* `to` reads at that offset and `from` doesn't, to the millisecond.
|
|
189
|
+
*/
|
|
190
|
+
function offsetTakenAt(from: number, to: number, offset: number, zone: string): number {
|
|
191
|
+
let before = from;
|
|
192
|
+
let after = to;
|
|
193
|
+
while (after - before > 1) {
|
|
194
|
+
const mid = Math.floor((before + after) / 2);
|
|
195
|
+
if (wallFields(mid, zone).offsetMinutes === offset) after = mid;
|
|
196
|
+
else before = mid;
|
|
197
|
+
}
|
|
198
|
+
return after;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// What a clock reads
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
|
|
205
|
+
const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
206
|
+
|
|
207
|
+
const pad = (n: number): string => String(n).padStart(2, '0');
|
|
208
|
+
|
|
209
|
+
function localDate(at: number, zone: string): string {
|
|
210
|
+
const f = wallFields(at, zone);
|
|
211
|
+
return `${f.year}-${pad(f.month)}-${pad(f.day)}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function isUtcZone(zone: string): boolean {
|
|
215
|
+
return /^(Etc\/)?(UTC|UCT|Zulu|Universal|GMT|Greenwich)$/.test(zone) || zone === 'Etc/GMT0' || zone === 'GMT0';
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* A clock row's text: `Clock: 10:50 Europe/Berlin (UTC+02:00)`, with the
|
|
220
|
+
* weekday and date ahead of the time when `withDate`
|
|
221
|
+
* (`Clock: Thursday 2026-10-22, 00:00 Europe/Berlin (UTC+02:00)`).
|
|
222
|
+
*/
|
|
223
|
+
export function formatClockText(
|
|
224
|
+
at: number,
|
|
225
|
+
zone: string,
|
|
226
|
+
precision: 'minutes' | 'seconds',
|
|
227
|
+
withDate: boolean,
|
|
228
|
+
): string {
|
|
229
|
+
const f = wallFields(at, zone);
|
|
230
|
+
const time = precision === 'seconds'
|
|
231
|
+
? `${pad(f.hour)}:${pad(f.minute)}:${pad(f.second)}`
|
|
232
|
+
: `${pad(f.hour)}:${pad(f.minute)}`;
|
|
233
|
+
const weekday = WEEKDAYS[new Date(Date.UTC(f.year, f.month - 1, f.day)).getUTCDay()];
|
|
234
|
+
const date = withDate ? `${weekday} ${f.year}-${pad(f.month)}-${pad(f.day)}, ` : '';
|
|
235
|
+
const sign = f.offsetMinutes < 0 ? '-' : '+';
|
|
236
|
+
const offset = Math.abs(f.offsetMinutes);
|
|
237
|
+
const where = isUtcZone(zone) && f.offsetMinutes === 0
|
|
238
|
+
? 'UTC'
|
|
239
|
+
: `${zone} (UTC${sign}${pad(Math.floor(offset / 60))}:${pad(offset % 60)})`;
|
|
240
|
+
return `Clock: ${date}${time} ${where}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A clock row to store. */
|
|
244
|
+
export interface PlannedClock {
|
|
245
|
+
content: ContentBlock[];
|
|
246
|
+
stamp: ClockStamp;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The clock row the window takes next, or null when no boundary has passed
|
|
251
|
+
* since the last clock it holds. The framework asks before an incoming
|
|
252
|
+
* event, at a turn's start and at a tool boundary (storeDueClock).
|
|
253
|
+
*
|
|
254
|
+
* - `newestRowAt`: the newest row's time, which the clock goes after.
|
|
255
|
+
* - `lastClockAt`: the time the window's last clock row reads, when it holds
|
|
256
|
+
* one. Without one, no boundary counts as told: the window takes a clock
|
|
257
|
+
* now, and it carries the date.
|
|
258
|
+
*/
|
|
259
|
+
export function planClock(args: {
|
|
260
|
+
now: number;
|
|
261
|
+
newestRowAt: number | undefined;
|
|
262
|
+
lastClockAt: number | undefined;
|
|
263
|
+
config: ResolvedClockConfig;
|
|
264
|
+
zone: string;
|
|
265
|
+
}): PlannedClock | null {
|
|
266
|
+
const { now, newestRowAt, lastClockAt, config } = args;
|
|
267
|
+
const zone = resolveTimeZone(args.zone);
|
|
268
|
+
const boundary = latestBoundary(now, config.intervalSeconds, zone);
|
|
269
|
+
const told = lastClockAt !== undefined ? latestBoundary(lastClockAt, config.intervalSeconds, zone) : -Infinity;
|
|
270
|
+
if (boundary <= told) return null;
|
|
271
|
+
// The boundary's own time only where its tick would have been: no row
|
|
272
|
+
// after the boundary comes before the clock. Otherwise the time it is
|
|
273
|
+
// written, and never earlier than the row it follows.
|
|
274
|
+
const onBoundary = newestRowAt === undefined || newestRowAt <= boundary;
|
|
275
|
+
const at = onBoundary ? boundary : Math.max(now, newestRowAt);
|
|
276
|
+
const withDate = lastClockAt === undefined || localDate(lastClockAt, zone) !== localDate(at, zone);
|
|
277
|
+
return {
|
|
278
|
+
content: [{ type: 'text', text: formatClockText(at, zone, config.precision, withDate) }],
|
|
279
|
+
stamp: { at, onBoundary, zone },
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The clock stamp a stored row's metadata carries, if it is a clock row. */
|
|
284
|
+
export function clockStampOf(metadata: unknown): ClockStamp | undefined {
|
|
285
|
+
const m = metadata as { kind?: unknown; clock?: { at?: unknown } } | undefined;
|
|
286
|
+
if (m?.kind !== CLOCK_ROW_KIND || typeof m.clock?.at !== 'number') return undefined;
|
|
287
|
+
return m.clock as ClockStamp;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Whether a row can have a clock written before it: not the agent's own
|
|
291
|
+
* (an assistant turn), no tool blocks (a tool's results follow its call
|
|
292
|
+
* directly), and not itself a clock. */
|
|
293
|
+
export function takesClockBefore(
|
|
294
|
+
participant: string,
|
|
295
|
+
content: readonly ContentBlock[],
|
|
296
|
+
metadata: unknown,
|
|
297
|
+
agentName: string,
|
|
298
|
+
): boolean {
|
|
299
|
+
return participant !== agentName
|
|
300
|
+
&& !content.some((b) => b.type === 'tool_use' || b.type === 'tool_result')
|
|
301
|
+
&& clockStampOf(metadata) === undefined;
|
|
302
|
+
}
|