@agents24/client 0.2.31 → 0.2.33
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/README.md +37 -3
- package/dist/adapters/browser.js +3 -3
- package/dist/adapters/cloudflare.js +2 -2
- package/dist/adapters/node/dpop-key.d.ts +31 -0
- package/dist/adapters/node/files.d.ts +27 -0
- package/dist/adapters/node/persistence.d.ts +57 -0
- package/dist/adapters/node/session-controller.d.ts +63 -0
- package/dist/adapters/node.d.ts +8 -2
- package/dist/adapters/node.js +584 -3
- package/dist/adapters/node.js.map +1 -1
- package/dist/adapters/worker.js +2 -2
- package/dist/bff.js +1 -1
- package/dist/{chunk-3WC6DOBA.js → chunk-CBKEVJV6.js} +11 -3
- package/dist/chunk-CBKEVJV6.js.map +1 -0
- package/dist/{chunk-2PRRXQGA.js → chunk-D3ILKDVB.js} +64 -35
- package/dist/chunk-D3ILKDVB.js.map +1 -0
- package/dist/{chunk-LPCITIHI.js → chunk-JAIXMKE7.js} +22 -2
- package/dist/chunk-JAIXMKE7.js.map +1 -0
- package/dist/customer-types.d.ts +59 -0
- package/dist/dpop.d.ts +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/sessions.d.ts +7 -0
- package/dist/types.d.ts +20 -1
- package/package.json +1 -1
- package/dist/chunk-2PRRXQGA.js.map +0 -1
- package/dist/chunk-3WC6DOBA.js.map +0 -1
- package/dist/chunk-LPCITIHI.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# `@agents24/client`
|
|
2
2
|
|
|
3
|
-
Last Updated: 2026-12-
|
|
3
|
+
Last Updated: 2026-12-03
|
|
4
4
|
|
|
5
5
|
Framework-neutral end-user runtime client for one deployment-scoped Agents24 Agent. It supports public client sessions, authenticated streaming, durable reconnect, threads, attachments, HITL, and MCP without accepting organization API keys.
|
|
6
6
|
|
|
7
|
-
The root package uses structural capabilities and resolves without DOM or Node declarations. Runtime adapter subpaths provide verified global-capability bindings. The canonical wire validators and SSE parser are exported from `@agents24/client/protocol`.
|
|
7
|
+
The root package uses structural capabilities and resolves without DOM or Node declarations. Runtime adapter subpaths provide verified global-capability bindings; only `@agents24/client/node` imports Node built-ins. The canonical wire validators and SSE parser are exported from `@agents24/client/protocol`.
|
|
8
8
|
|
|
9
|
-
Persistent refresh grants require DPoP plus durable credential and refresh-fence storage. In browsers, `createBrowserSessionPersistence(...)` provides the complete IndexedDB-backed persistence set, including fenced cross-tab refresh coordination. `createFencedRefreshCoordinator` remains available for
|
|
9
|
+
Persistent refresh grants require DPoP plus durable credential and refresh-fence storage. In browsers, `createBrowserSessionPersistence(...)` provides the complete IndexedDB-backed persistence set, including fenced cross-tab refresh coordination. In Node processes, `createNodeSessionPersistence(...)` from `@agents24/client/node` provides the same set with cross-process coordination. `createFencedRefreshCoordinator` remains available for other runtimes with an atomic compare-and-swap store. Access tokens remain memory-only.
|
|
10
10
|
|
|
11
11
|
Allowlisted host headers can be carried through `chat.stream` and durable `runs.attach`; authentication, DPoP, Origin, cache, content-type, and idempotency headers remain client-owned and cannot be overridden.
|
|
12
12
|
|
|
@@ -58,6 +58,39 @@ await client.hitl.resume({
|
|
|
58
58
|
|
|
59
59
|
For a single-choice question, send exactly one listed option or `custom_text` for Other, not both. Multi-select questions may combine them. Reattach to the same run after a successful or idempotent resolution.
|
|
60
60
|
|
|
61
|
+
## Node and desktop processes
|
|
62
|
+
|
|
63
|
+
A desktop app's Node process (for example a bridge inside a native app) keeps the device's DPoP key and refresh grant out of renderer JavaScript. The application's backend mints each session through backend exchange (`session-tokens` with `persistent: true`, the device's `dpop_public_jwk`, and its `native_profile_id`).
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { createNodeSessionController, createNodeSessionPersistence } from "@agents24/client/node";
|
|
67
|
+
|
|
68
|
+
const persistence = createNodeSessionPersistence({
|
|
69
|
+
directory: join(app.getPath("userData"), "agents24"),
|
|
70
|
+
namespace: `${baseUrl}:${deploymentId}`,
|
|
71
|
+
// Optional: keep the key and grant in the OS secure store.
|
|
72
|
+
secretStore: { get, set, delete: remove },
|
|
73
|
+
});
|
|
74
|
+
const session = createNodeSessionController({
|
|
75
|
+
baseUrl,
|
|
76
|
+
deploymentId,
|
|
77
|
+
persistence,
|
|
78
|
+
// Ask your backend for a session; return its session-tokens response body.
|
|
79
|
+
async mintSession({ dpopPublicJwk, createDpopProof }) {
|
|
80
|
+
return myBackend.mintAgents24Session({ dpopPublicJwk, createDpopProof });
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
await session.start();
|
|
84
|
+
await session.client.chat.stream({ input: "Hello" }, onEvent);
|
|
85
|
+
await session.signOut();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- **Key.** `createNodeDpopKeyProvider` signs ES256 proofs with a non-extractable WebCrypto key from `node:crypto`. With persistence, the serialized key is read only to import it.
|
|
89
|
+
- **Storage.** Without `secretStore`, the key and refresh grant are owner-only (0600) files in a private (0700) directory, replaced atomically. Symlinked or foreign-owned entries are refused. A `secretStore` (`get`/`set`/`delete` of opaque strings) lets the host use the macOS Keychain or Windows Credential Manager through its own native bridge, and the package needs no native modules. File modes do not protect files on Windows, so use a secret store there. The directory always holds the refresh fence and lock files, which contain no credentials.
|
|
90
|
+
- **Refresh.** Processes that share a directory and namespace rotate the grant one at a time behind a fenced lease. A waiter reloads the persisted grant once it holds the fence, and each replacement is saved before it is used. A refresh proof with no nonce gets the server's `DPoP-Nonce` challenge, and the controller retries once with the nonce. Nonces are single-use and short-lived, so they are not persisted.
|
|
91
|
+
- **Minting.** `start()` restores and rotates the stored session. When there is no stored session, or the server says it ended (`SESSION_REVOKED`, `SESSION_EXPIRED`), the controller calls `mintSession`. The same happens when the stored record is unreadable or bound to another key: the record is discarded and `onRecovery` reports it. Your backend calls `session-tokens` and receives a `DPoP-Nonce` challenge. `createDpopProof({ url, nonce })` signs the device proof for the retry, and only for this deployment's `session-tokens` URL. The minted session must be a persistent DPoP session.
|
|
92
|
+
- **Sign-out.** `signOut()` revokes the session and always deletes the local grant. Until `start()` runs again, requests fail with `SIGNED_OUT` and nothing mints a new session. `persistence.forgetDevice()` also deletes the device key.
|
|
93
|
+
|
|
61
94
|
## Same-origin BFF
|
|
62
95
|
|
|
63
96
|
`@agents24/client/bff` exposes `createBffAgentClient({ basePath })`, an `AgentClient` implementation for a customer-owned same-origin BFF. It covers the complete chat lifecycle, uses same-origin credentials, reconnects with the last durable cursor, and reuses caller idempotency keys for mutations. It accepts only an absolute path such as `/api/agents24`. Pair it with `createAgents24BffHandler` from `@agents24/node/bff`; use `npm create agents24-app@latest` for the complete React/Vite setup.
|
|
@@ -75,6 +108,7 @@ routing.
|
|
|
75
108
|
| Runtime | Status |
|
|
76
109
|
| --- | --- |
|
|
77
110
|
| Browser/Vite, dedicated workers, Node 22/24 | GA candidates; promotion requires the final cross-browser and CI matrix |
|
|
111
|
+
| Node desktop sessions (`./node`) | Pre-beta; file store and cross-process refresh are covered by package tests. OS secure-store adapters are host-supplied and not verified here |
|
|
78
112
|
| Cloudflare Workers | Pre-beta; packed local workerd conformance passes, but the deployed Worker smoke is not yet authorized or verified |
|
|
79
113
|
| Bun 1.3 and Deno 2 | Pre-beta; packed local portable matrix passes, dedicated CI must be green for promotion |
|
|
80
114
|
| Service Workers | Experimental; packed termination/restart with durable cursor reattach passes, full operation coverage is pending |
|
package/dist/adapters/browser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createBrowserVisibility } from '../chunk-CQOFY3IL.js';
|
|
2
2
|
export { createBrowserVisibility } from '../chunk-CQOFY3IL.js';
|
|
3
|
-
import { createFencedRefreshCoordinator, createWebCryptoDpopKeyProvider, createAnonymousSessionProvider, createHostedOidcSessionProvider, createPkcePair } from '../chunk-
|
|
4
|
-
import { createAgents24Client } from '../chunk-
|
|
5
|
-
import '../chunk-
|
|
3
|
+
import { createFencedRefreshCoordinator, createWebCryptoDpopKeyProvider, createAnonymousSessionProvider, createHostedOidcSessionProvider, createPkcePair } from '../chunk-D3ILKDVB.js';
|
|
4
|
+
import { createAgents24Client } from '../chunk-CBKEVJV6.js';
|
|
5
|
+
import '../chunk-JAIXMKE7.js';
|
|
6
6
|
import '../chunk-OD5SQZ4O.js';
|
|
7
7
|
|
|
8
8
|
// src/adapters/browser.ts
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Clock, DpopKeyProvider, IdProvider } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Durable home of one device's DPoP private key. Implementations serialize
|
|
4
|
+
* provisioning across processes so every process signs with the same key.
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeDpopKeyStorage {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the persisted serialized key, or atomically persists and returns
|
|
9
|
+
* `generate()` when none exists or the stored one fails `isUsable`.
|
|
10
|
+
*/
|
|
11
|
+
loadOrCreate(input: {
|
|
12
|
+
generate(): Promise<string>;
|
|
13
|
+
isUsable(serialized: string): boolean;
|
|
14
|
+
}): Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface NodeDpopKeyProviderOptions {
|
|
17
|
+
/** Omit for a key that lives only as long as this process. */
|
|
18
|
+
storage?: NodeDpopKeyStorage;
|
|
19
|
+
clock?: Clock;
|
|
20
|
+
ids?: IdProvider;
|
|
21
|
+
}
|
|
22
|
+
export interface NodeDpopKeyProvider extends DpopKeyProvider {
|
|
23
|
+
/** Drops the in-memory key; the next use loads the persisted one again. */
|
|
24
|
+
reload(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* ES256 DPoP key provider for Node processes. The private key is held as a
|
|
28
|
+
* non-extractable WebCrypto key; with `storage`, its serialized form is read
|
|
29
|
+
* only while importing and lives in the host-chosen secure store.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createNodeDpopKeyProvider(options?: NodeDpopKeyProviderOptions): NodeDpopKeyProvider;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates (or tightens) a directory only the current user can enter. Symlinked
|
|
3
|
+
* or foreign-owned directories are refused instead of followed.
|
|
4
|
+
*/
|
|
5
|
+
export declare function ensurePrivateDirectory(directory: string): Promise<void>;
|
|
6
|
+
/** Reads a private file without following symlinks; `null` when it does not exist. */
|
|
7
|
+
export declare function readPrivateFile(path: string): Promise<string | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Durable replace: the new content is fully written and flushed under a unique
|
|
10
|
+
* 0600 temporary name, then renamed over the target. Readers observe either
|
|
11
|
+
* the previous or the next content, never a partial write.
|
|
12
|
+
*/
|
|
13
|
+
export declare function writePrivateFileAtomic(path: string, content: string): Promise<void>;
|
|
14
|
+
export declare function removeFile(path: string): Promise<void>;
|
|
15
|
+
export interface FileMutexOptions {
|
|
16
|
+
/** A lock untouched for this long belongs to a crashed holder. Holds last milliseconds. */
|
|
17
|
+
staleMs: number;
|
|
18
|
+
/** Give up waiting for a live holder after this long. */
|
|
19
|
+
timeoutMs: number;
|
|
20
|
+
}
|
|
21
|
+
export type AssertMutexHeld = () => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Cross-process mutual exclusion through an O_EXCL lock file. It guards only
|
|
24
|
+
* short read-modify-write sections; the refresh fence built on top of it owns
|
|
25
|
+
* the long-running refresh lease.
|
|
26
|
+
*/
|
|
27
|
+
export declare function withFileMutex<T>(path: string, options: FileMutexOptions, operation: (assertHeld: AssertMutexHeld) => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ClientSessionStorage, SessionRefreshCoordinator } from "../../types.js";
|
|
2
|
+
import type { NodeDpopKeyProvider } from "./dpop-key.js";
|
|
3
|
+
/**
|
|
4
|
+
* Host-supplied secret storage, e.g. the macOS Keychain or Windows Credential
|
|
5
|
+
* Manager reached through the host's own native bridge. Values are opaque
|
|
6
|
+
* strings; `get` returns `null` for an absent entry.
|
|
7
|
+
*/
|
|
8
|
+
export interface NodeSecretStore {
|
|
9
|
+
get(name: string): Promise<string | null>;
|
|
10
|
+
set(name: string, value: string): Promise<void>;
|
|
11
|
+
delete(name: string): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface NodeStoreRecoveryEvent {
|
|
14
|
+
record: "dpop_key" | "session";
|
|
15
|
+
reason: "unreadable" | "key_mismatch";
|
|
16
|
+
}
|
|
17
|
+
export interface NodeSessionPersistenceOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Private application-data directory (created 0700). It always holds the
|
|
20
|
+
* cross-process locks and refresh fence, which contain no credentials, and
|
|
21
|
+
* holds the key and session too unless `secretStore` is supplied.
|
|
22
|
+
*/
|
|
23
|
+
directory: string;
|
|
24
|
+
/** Distinguishes environments and deployments, e.g. `${baseUrl}:${deploymentId}`. */
|
|
25
|
+
namespace: string;
|
|
26
|
+
/** Keeps the DPoP key and refresh grant in OS secure storage instead of 0600 files. */
|
|
27
|
+
secretStore?: NodeSecretStore;
|
|
28
|
+
/** Reports a stored record that could not be used and was replaced. */
|
|
29
|
+
onRecovery?: (event: NodeStoreRecoveryEvent) => void;
|
|
30
|
+
/** Lock files older than this belong to a crashed process. Default 10 s. */
|
|
31
|
+
lockStaleMs?: number;
|
|
32
|
+
/** Maximum wait for a live lock holder. Default 30 s. */
|
|
33
|
+
lockTimeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface NodeSessionPersistence {
|
|
36
|
+
dpopKeyProvider: NodeDpopKeyProvider;
|
|
37
|
+
sessionStorage: ClientSessionStorage;
|
|
38
|
+
refreshCoordinator: SessionRefreshCoordinator;
|
|
39
|
+
/** Deletes this device's key, session and refresh fence. */
|
|
40
|
+
forgetDevice(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface FileSecretStoreOptions {
|
|
43
|
+
directory: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Secret store backed by owner-only (0600) files in a private (0700)
|
|
47
|
+
* directory, replaced atomically. Prefer an OS secure store where the host has
|
|
48
|
+
* one; on Windows, file modes do not restrict access, so the directory's ACL
|
|
49
|
+
* must.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createFileSecretStore(options: FileSecretStoreOptions): NodeSecretStore;
|
|
52
|
+
/**
|
|
53
|
+
* Persistent key, refresh grant and cross-process refresh fence for a Node
|
|
54
|
+
* process (desktop bridge, CLI, daemon). Two processes sharing a directory and
|
|
55
|
+
* namespace never present the same rotated grant twice.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createNodeSessionPersistence(options: NodeSessionPersistenceOptions): NodeSessionPersistence;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AbortSignalLike, Agents24ClientOptions, Clock, FetchLike, IdProvider, PublicJwk, SessionAgentClient, TelemetrySink } from "../../types.js";
|
|
2
|
+
import type { NodeSessionPersistence } from "./persistence.js";
|
|
3
|
+
/** What the host's backend needs to mint a persistent DPoP session for this device. */
|
|
4
|
+
export interface NodeSessionMintRequest {
|
|
5
|
+
/** Send as `dpop_public_jwk`, with `persistent: true`, to `session-tokens`. */
|
|
6
|
+
dpopPublicJwk: PublicJwk;
|
|
7
|
+
/**
|
|
8
|
+
* Signs this device's DPoP proof for the backend's `session-tokens` request
|
|
9
|
+
* after Agents24 answers it with a `DPoP-Nonce` challenge.
|
|
10
|
+
*/
|
|
11
|
+
createDpopProof(input: {
|
|
12
|
+
url: string;
|
|
13
|
+
nonce: string;
|
|
14
|
+
}): Promise<string>;
|
|
15
|
+
signal?: AbortSignalLike | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface NodeSessionControllerOptions {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
deploymentId: string;
|
|
20
|
+
persistence: NodeSessionPersistence;
|
|
21
|
+
/**
|
|
22
|
+
* Asks the application's backend for a new session and returns the
|
|
23
|
+
* `session-tokens` response body unchanged. Called when no stored session
|
|
24
|
+
* exists or the stored one can no longer be refreshed.
|
|
25
|
+
*/
|
|
26
|
+
mintSession(request: NodeSessionMintRequest): Promise<unknown>;
|
|
27
|
+
fetch?: FetchLike;
|
|
28
|
+
clock?: Clock;
|
|
29
|
+
ids?: IdProvider;
|
|
30
|
+
telemetry?: TelemetrySink;
|
|
31
|
+
client?: Omit<Agents24ClientOptions, "baseUrl" | "deploymentId" | "sessionProvider" | "fetch" | "clock" | "ids" | "telemetry">;
|
|
32
|
+
}
|
|
33
|
+
export type NodeSessionState = "idle" | "starting" | "active" | "signed_out" | "error";
|
|
34
|
+
export interface NodeSessionSnapshot {
|
|
35
|
+
state: NodeSessionState;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
error?: {
|
|
38
|
+
code: string;
|
|
39
|
+
message: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface NodeSessionController {
|
|
43
|
+
client: SessionAgentClient;
|
|
44
|
+
getSnapshot(): NodeSessionSnapshot;
|
|
45
|
+
subscribe(listener: () => void): () => void;
|
|
46
|
+
/** Restores the stored session (rotating its grant) or mints one through the host. */
|
|
47
|
+
start(): Promise<NodeSessionSnapshot>;
|
|
48
|
+
/**
|
|
49
|
+
* Revokes the session server-side and always removes the local session.
|
|
50
|
+
* Resolves `revoked: false` when no live session remained to revoke; rejects
|
|
51
|
+
* when the server could not confirm revocation.
|
|
52
|
+
*/
|
|
53
|
+
signOut(): Promise<{
|
|
54
|
+
revoked: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Session lifecycle for a Node process acting for one device: restore on
|
|
59
|
+
* start, fenced cross-process refresh with DPoP nonce challenges, replacement
|
|
60
|
+
* credentials persisted before use, explicit sign-out, and host minting when
|
|
61
|
+
* refresh is impossible.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createNodeSessionController(options: NodeSessionControllerOptions): NodeSessionController;
|
package/dist/adapters/node.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Agents24ClientOptions, SessionAgentClient } from "../types.js";
|
|
2
2
|
export declare const runtimeAdapter: "node";
|
|
3
|
-
export declare function createNodeAgentClient(options: Agents24ClientOptions):
|
|
3
|
+
export declare function createNodeAgentClient(options: Agents24ClientOptions): SessionAgentClient;
|
|
4
|
+
export { createNodeDpopKeyProvider } from "./node/dpop-key.js";
|
|
5
|
+
export type { NodeDpopKeyProvider, NodeDpopKeyProviderOptions, NodeDpopKeyStorage } from "./node/dpop-key.js";
|
|
6
|
+
export { createFileSecretStore, createNodeSessionPersistence } from "./node/persistence.js";
|
|
7
|
+
export type { FileSecretStoreOptions, NodeSecretStore, NodeSessionPersistence, NodeSessionPersistenceOptions, NodeStoreRecoveryEvent, } from "./node/persistence.js";
|
|
8
|
+
export { createNodeSessionController } from "./node/session-controller.js";
|
|
9
|
+
export type { NodeSessionController, NodeSessionControllerOptions, NodeSessionMintRequest, NodeSessionSnapshot, NodeSessionState, } from "./node/session-controller.js";
|