@telnyx/agent-harness 0.1.0-beta.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.
@@ -0,0 +1,12 @@
1
+ /** Private Agent harness foundation and turn engine. Never publish this working package. */
2
+ export * from "./ports.js";
3
+ export * from "./runtime-adapter.js";
4
+ export * from "./harness.js";
5
+ export { HARNESS_RUN_STATUSES, HarnessApprovalPause, HarnessInjectedCrash, createHarnessRunLedger, ensureHarnessDurabilitySchema, type HarnessCheckpoint, type HarnessRun, type HarnessRunAcceptance, type HarnessRunLedger, type HarnessRunLedgerOptions, type HarnessRunListOptions, type HarnessRunStatus, } from "./durable.js";
6
+ export { HARNESS_APPROVAL_STATUSES, HarnessApprovalError, HarnessAuthorizationError, type HarnessApproval, type HarnessApprovalLedger, type HarnessApprovalStatus, } from "./approvals.js";
7
+ export * from "./steps.js";
8
+ export * from "./lifecycle.js";
9
+ export * from "./channel.js";
10
+ export * from "./scheduling.js";
11
+ export * from "./workspace.js";
12
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ /** Private Agent harness foundation and turn engine. Never publish this working package. */
2
+ export * from "./ports.js";
3
+ export * from "./runtime-adapter.js";
4
+ // node-adapter is deliberately NOT re-exported: it pulls in the Node-only
5
+ // SQLite storage, whose module-level createRequire(import.meta.url) throws
6
+ // when the deploy pipeline stages a customer bundle as CommonJS (import.meta
7
+ // is empty there). Deployed actors get their storage from the runtime; the
8
+ // Node adapter is a local/test concern — consumers import it from the
9
+ // "@telnyx/agent-harness/node" subpath (internal code from
10
+ // "./node-adapter.js"). The clean-consumer CI check enforces both directions.
11
+ export * from "./harness.js";
12
+ export { HARNESS_RUN_STATUSES, HarnessApprovalPause, HarnessInjectedCrash, createHarnessRunLedger, ensureHarnessDurabilitySchema, } from "./durable.js";
13
+ export { HARNESS_APPROVAL_STATUSES, HarnessApprovalError, HarnessAuthorizationError, } from "./approvals.js";
14
+ export * from "./steps.js";
15
+ export * from "./lifecycle.js";
16
+ export * from "./channel.js";
17
+ export * from "./scheduling.js";
18
+ export * from "./workspace.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ /** Stable error raised when a lifecycle middleware attempts to advance twice. */
2
+ export declare class HarnessMiddlewareError extends Error {
3
+ readonly code: "HARNESS_MIDDLEWARE_NEXT";
4
+ constructor();
5
+ }
6
+ export type HarnessMiddleware<Context, Result> = (context: Readonly<Context>, next: () => Promise<Result>) => Promise<Result> | Result;
7
+ /** Executes one immutable lifecycle snapshot in registered onion order. */
8
+ export declare function runMiddleware<Context, Result>(context: Readonly<Context>, middleware: readonly HarnessMiddleware<Context, Result>[], core: () => Promise<Result>): Promise<Result>;
9
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1,25 @@
1
+ /** Stable error raised when a lifecycle middleware attempts to advance twice. */
2
+ export class HarnessMiddlewareError extends Error {
3
+ code = "HARNESS_MIDDLEWARE_NEXT";
4
+ constructor() {
5
+ super("Harness middleware may call next() at most once");
6
+ this.name = "HarnessMiddlewareError";
7
+ }
8
+ }
9
+ /** Executes one immutable lifecycle snapshot in registered onion order. */
10
+ export async function runMiddleware(context, middleware, core) {
11
+ const dispatch = async (index) => {
12
+ const current = middleware[index];
13
+ if (current === undefined)
14
+ return core();
15
+ let advanced = false;
16
+ return current(context, async () => {
17
+ if (advanced)
18
+ throw new HarnessMiddlewareError();
19
+ advanced = true;
20
+ return dispatch(index + 1);
21
+ });
22
+ };
23
+ return dispatch(0);
24
+ }
25
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,71 @@
1
+ import { type StoredEvent, type StoredMessage, type TaskDispatch, type TaskRecord } from "@telnyx/edge-runtime/internal";
2
+ import { type AgentHarnessEventPort, type HarnessAuthorizationPort, type AgentHarnessMessagePort, type AgentHarnessPorts, type AgentHarnessSqlPort, type AgentHarnessStatePort, type AgentHarnessTaskPort } from "./ports.js";
3
+ interface NodeBacking<State extends Record<string, unknown>> {
4
+ messageSeq: number;
5
+ messages: StoredMessage[];
6
+ eventSeq: number;
7
+ events: StoredEvent[];
8
+ state: State | undefined;
9
+ tasks: Map<string, TaskRecord>;
10
+ nextTaskId: number;
11
+ sql: AgentHarnessSqlPort & {
12
+ close(): void;
13
+ };
14
+ closed: boolean;
15
+ }
16
+ /** Options for the deterministic plain-Node adapter. */
17
+ export interface NodeAgentHarnessPortsOptions<State extends Record<string, unknown>> {
18
+ id: string;
19
+ now: () => number;
20
+ initialState: () => State;
21
+ databasePath: string;
22
+ environment?: Readonly<Record<string, unknown>>;
23
+ /** Deterministic authorization adapter for tests; production hosts provide an attested gateway provider. */
24
+ authorization?: HarnessAuthorizationPort;
25
+ /**
26
+ * Optional Agent-compatible hook fired after a state merge or replacement is
27
+ * committed. A rejection propagates without rolling the committed state back.
28
+ */
29
+ onStateChanged?: (next: State, prev: State) => void | Promise<void>;
30
+ }
31
+ /**
32
+ * Deterministic plain-Node implementation of AgentHarnessPorts v2.
33
+ *
34
+ * KV-like data is in memory and survives `reopen()` only; SQL is file-backed
35
+ * through Node's experimental `node:sqlite` API and requires Node 22.13 or
36
+ * newer without runtime flags. This is a contract-test host, not a production
37
+ * durability claim.
38
+ */
39
+ export declare class NodeAgentHarnessPorts<State extends Record<string, unknown> = Record<string, unknown>> implements AgentHarnessPorts<State> {
40
+ private readonly options;
41
+ private readonly backing;
42
+ readonly version: 2;
43
+ readonly identity: Readonly<{
44
+ id: string;
45
+ }>;
46
+ readonly activation: Readonly<{}>;
47
+ readonly clock: Readonly<{
48
+ now(): number;
49
+ }>;
50
+ readonly authorization: HarnessAuthorizationPort | undefined;
51
+ readonly environment: Readonly<Record<string, unknown>>;
52
+ readonly messages: AgentHarnessMessagePort;
53
+ readonly state: AgentHarnessStatePort<State>;
54
+ readonly events: AgentHarnessEventPort;
55
+ readonly tasks: AgentHarnessTaskPort;
56
+ readonly sql: AgentHarnessSqlPort;
57
+ constructor(options: NodeAgentHarnessPortsOptions<State>, backing?: NodeBacking<State>);
58
+ /** Reconstruct the adapter while retaining its in-process durable backing. */
59
+ reopen(): NodeAgentHarnessPorts<State>;
60
+ /**
61
+ * Pump due tasks for deterministic Node tests. This is a host control, not an
62
+ * AgentHarnessPorts method or a durable run-status API.
63
+ */
64
+ runDue(dispatch: TaskDispatch): Promise<number>;
65
+ /** Close the fixture-owned SQLite database. Idempotent. */
66
+ close(): void;
67
+ }
68
+ /** Construct a deterministic plain-Node ports adapter. */
69
+ export declare function createNodeAgentHarnessPorts<State extends Record<string, unknown>>(options: NodeAgentHarnessPortsOptions<State>): NodeAgentHarnessPorts<State>;
70
+ export {};
71
+ //# sourceMappingURL=node-adapter.d.ts.map