@you-agent-factory/client 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +78 -17
- package/dist/contracts.d.ts +51 -0
- package/dist/contracts.js +9 -0
- package/dist/event-ordering.d.ts +15 -0
- package/dist/event-ordering.js +33 -0
- package/dist/generated/factory-event.schema.json +5490 -0
- package/dist/generated/factory.schema.json +2606 -0
- package/dist/generated/openapi.d.ts +7587 -0
- package/dist/generated/openapi.js +1020 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/recording.d.ts +34 -0
- package/dist/recording.js +236 -0
- package/dist/replay.d.ts +21 -0
- package/dist/replay.js +82 -0
- package/dist/schema-validation.d.ts +9 -0
- package/dist/schema-validation.js +113 -0
- package/dist/visualization-layout-contracts.d.ts +63 -0
- package/dist/visualization-layout-contracts.js +1 -0
- package/dist/visualization-layout-data.d.ts +9 -0
- package/dist/visualization-layout-data.js +105 -0
- package/dist/visualization-layout-error.d.ts +5 -0
- package/dist/visualization-layout-error.js +10 -0
- package/dist/visualization-layout-fields.d.ts +7 -0
- package/dist/visualization-layout-fields.js +26 -0
- package/dist/visualization-layout-geometry.d.ts +5 -0
- package/dist/visualization-layout-geometry.js +74 -0
- package/dist/visualization-layout-media.d.ts +11 -0
- package/dist/visualization-layout-media.js +110 -0
- package/dist/visualization-layout-safety.d.ts +15 -0
- package/dist/visualization-layout-safety.js +142 -0
- package/dist/visualization-layout-topology.d.ts +11 -0
- package/dist/visualization-layout-topology.js +90 -0
- package/dist/visualization-layout.d.ts +12 -0
- package/dist/visualization-layout.js +299 -0
- package/examples/customer-support.factory-recording.v1.json +64 -0
- package/examples/customer-support.factory-visualization-layout.v1.json +47 -0
- package/package.json +37 -18
- package/recordings/factory-recording.json +0 -36
- package/src/contracts.ts +0 -13
- package/src/generated/factory-recording.schema.json +0 -5521
- package/src/generated/openapi.ts +0 -8134
- package/src/index.js +0 -5
- package/src/index.ts +0 -17
- package/src/recording-parser.d.ts +0 -37
- package/src/recording-parser.js +0 -230
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,19 +1,80 @@
|
|
|
1
1
|
# `@you-agent-factory/client`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
Transport-neutral Factory contracts and recording utilities for TypeScript
|
|
4
|
+
consumers. The package has no React, browser, dashboard, or network dependency.
|
|
5
|
+
See the [public package family guide](https://github.com/portpowered/you-agent-factory/blob/main/ui/packages/README.md)
|
|
6
|
+
for its contract-layer role, dependency direction, supported integration paths,
|
|
7
|
+
and hosted-execution boundary.
|
|
8
|
+
|
|
9
|
+
## Stable contracts
|
|
10
|
+
|
|
11
|
+
The root entry point exports the generated `components`, `paths`, and
|
|
12
|
+
`operations` type namespaces together with stable `FactoryEvent`,
|
|
13
|
+
`FactoryEventType`, and `FactoryDefinition` aliases. `FACTORY_EVENT_TYPES`
|
|
14
|
+
provides the runtime event constants from the same generated contract.
|
|
15
|
+
|
|
16
|
+
## Factory recordings
|
|
17
|
+
|
|
18
|
+
`parseFactoryRecording` validates unknown input and returns a trusted
|
|
19
|
+
`FactoryRecording`; invalid input throws `FactoryRecordingValidationError` with
|
|
20
|
+
machine-readable issue codes and input paths. Use `safeParseFactoryRecording`
|
|
21
|
+
for a discriminated result that never throws for invalid customer input. Both
|
|
22
|
+
recording and replay parsing enforce the generated canonical Factory and
|
|
23
|
+
discriminated Factory-event JSON Schemas, including formats, numeric limits,
|
|
24
|
+
required payload fields, and additional-property rules.
|
|
25
|
+
|
|
26
|
+
The packaged
|
|
27
|
+
[`customer-support.factory-recording.v1.json`](examples/customer-support.factory-recording.v1.json)
|
|
28
|
+
is a backend-free example of the public `factory-recording/v1` contract. It
|
|
29
|
+
includes both a top-level Factory definition and a canonical topology event.
|
|
30
|
+
|
|
31
|
+
## Replay helpers
|
|
32
|
+
|
|
33
|
+
Replay consumers can use `orderFactoryEvents` for deterministic tick-first
|
|
34
|
+
ordering, `createFactoryEventCursor` for reconnect positions, and
|
|
35
|
+
`parseFactoryEventReplayText` (or its non-throwing safe-parser counterpart) to
|
|
36
|
+
validate and order canonical JSON `data` frames from captured SSE text. These
|
|
37
|
+
helpers are pure and do not open or retain a live transport.
|
|
38
|
+
|
|
39
|
+
## Factory visualization layout sidecars
|
|
40
|
+
|
|
41
|
+
`parseFactoryVisualizationLayout` validates optional, presentation-only
|
|
42
|
+
metadata beside a read-only `FactoryDefinition`; the sidecar is never added to
|
|
43
|
+
the canonical Factory. Version 1 carries positioned note and embedded-raster
|
|
44
|
+
image annotations plus text or image empty states keyed by canonical topology
|
|
45
|
+
node ID. Empty-state references are checked against the canonical topology
|
|
46
|
+
projected from the supplied Factory, and blank, unknown, or duplicate node IDs
|
|
47
|
+
are rejected. `safeParseFactoryVisualizationLayout` returns stable issue codes
|
|
48
|
+
and input paths instead of throwing. The contract contains data only: no
|
|
49
|
+
callback, URL, link, HTML, Markdown, topology connection, route, event,
|
|
50
|
+
persistence, or runtime-effect field is supported.
|
|
51
|
+
|
|
52
|
+
Embedded sources accept only PNG, JPEG, or WebP signatures encoded as strict
|
|
53
|
+
canonical padded base64. Alternative text is required, each decoded image is
|
|
54
|
+
limited to 2 MiB, and all image occurrences in one sidecar share an 8 MiB
|
|
55
|
+
decoded-byte budget.
|
|
56
|
+
|
|
57
|
+
The packaged
|
|
58
|
+
[`customer-support.factory-visualization-layout.v1.json`](examples/customer-support.factory-visualization-layout.v1.json)
|
|
59
|
+
demonstrates each version-1 variant independently from the canonical Factory.
|
|
60
|
+
|
|
61
|
+
## Contract generation
|
|
62
|
+
|
|
63
|
+
Run `bun run generate` from this directory after the checked-in dashboard
|
|
64
|
+
OpenAPI TypeScript artifact changes. Run `bun run check:generated` to verify
|
|
65
|
+
freshness without writing files. Both commands treat the generated OpenAPI
|
|
66
|
+
TypeScript artifact and published Factory/Factory-event schemas as read-only
|
|
67
|
+
inputs and write, when requested, only to
|
|
68
|
+
`ui/packages/client/src/generated`.
|
|
69
|
+
|
|
70
|
+
## Distribution verification
|
|
71
|
+
|
|
72
|
+
Run `bun run build` to emit the ESM runtime and declarations in `dist`. Run
|
|
73
|
+
`bun run check:pack` to build a registry-format tarball and verify its exact
|
|
74
|
+
inventory, export targets, and declared runtime dependency boundary. Run
|
|
75
|
+
`bun run check:installed-consumer` to install that tarball in a clean temporary
|
|
76
|
+
project, typecheck the public contracts, and execute the recording, ordering,
|
|
77
|
+
cursor, and replay helpers against the packaged customer example using only its
|
|
78
|
+
declared runtime dependencies. `bun run
|
|
79
|
+
verify` runs these checks after generation freshness, package typecheck, and
|
|
80
|
+
focused tests.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type components, type operations, type paths } from "./generated/openapi.js";
|
|
2
|
+
export type { components, operations, paths };
|
|
3
|
+
type FactorySchemas = components["schemas"];
|
|
4
|
+
/** The canonical versioned event envelope exposed by the public client. */
|
|
5
|
+
export type FactoryEvent = FactorySchemas["FactoryEvent"];
|
|
6
|
+
/** The supported canonical Factory event type vocabulary. */
|
|
7
|
+
export type FactoryEventType = FactorySchemas["FactoryEventType"];
|
|
8
|
+
/** The customer-authored Factory topology definition. */
|
|
9
|
+
export type FactoryDefinition = FactorySchemas["Factory"];
|
|
10
|
+
/**
|
|
11
|
+
* Runtime Factory event constants generated from the canonical OpenAPI input.
|
|
12
|
+
* The object retains the generated keys and literal values without duplicating
|
|
13
|
+
* the event vocabulary in handwritten source.
|
|
14
|
+
*/
|
|
15
|
+
export declare const FACTORY_EVENT_TYPES: {
|
|
16
|
+
readonly FactoryEventTypeRunRequest: "RUN_REQUEST";
|
|
17
|
+
readonly FactoryEventTypeInitialStructureRequest: "INITIAL_STRUCTURE_REQUEST";
|
|
18
|
+
readonly FactoryEventTypeFactoryChange: "FACTORY_CHANGE";
|
|
19
|
+
readonly FactoryEventTypeWorkRequest: "WORK_REQUEST";
|
|
20
|
+
readonly FactoryEventTypeRelationshipChangeRequest: "RELATIONSHIP_CHANGE_REQUEST";
|
|
21
|
+
readonly FactoryEventTypeDispatchRequest: "DISPATCH_REQUEST";
|
|
22
|
+
readonly FactoryEventTypeModelRequest: "MODEL_REQUEST";
|
|
23
|
+
readonly FactoryEventTypeModelResponse: "MODEL_RESPONSE";
|
|
24
|
+
readonly FactoryEventTypeInferenceRequest: "INFERENCE_REQUEST";
|
|
25
|
+
readonly FactoryEventTypeInferenceResponse: "INFERENCE_RESPONSE";
|
|
26
|
+
readonly FactoryEventTypeScriptRequest: "SCRIPT_REQUEST";
|
|
27
|
+
readonly FactoryEventTypeScriptResponse: "SCRIPT_RESPONSE";
|
|
28
|
+
readonly FactoryEventTypeAgentRunResponse: "AGENT_RUN_RESPONSE";
|
|
29
|
+
readonly FactoryEventTypeDispatchResponse: "DISPATCH_RESPONSE";
|
|
30
|
+
readonly FactoryEventTypeWorkStateChange: "WORK_STATE_CHANGE";
|
|
31
|
+
readonly FactoryEventTypeFactoryStateResponse: "FACTORY_STATE_RESPONSE";
|
|
32
|
+
readonly FactoryEventTypeRunResponse: "RUN_RESPONSE";
|
|
33
|
+
readonly FactoryEventTypeSessionStarted: "SESSION_STARTED";
|
|
34
|
+
readonly FactoryEventTypeSessionPaused: "SESSION_PAUSED";
|
|
35
|
+
readonly FactoryEventTypeSessionResumed: "SESSION_RESUMED";
|
|
36
|
+
readonly FactoryEventTypeSessionResultUpdated: "SESSION_RESULT_UPDATED";
|
|
37
|
+
readonly FactoryEventTypeSessionCompleted: "SESSION_COMPLETED";
|
|
38
|
+
readonly FactoryEventTypeSessionLifecycleControl: "SESSION_LIFECYCLE_CONTROL";
|
|
39
|
+
readonly FactoryEventTypeOrchestratorPhaseChanged: "ORCHESTRATOR_PHASE_CHANGED";
|
|
40
|
+
readonly FactoryEventTypeOrchestratorCheckpointWritten: "ORCHESTRATOR_CHECKPOINT_WRITTEN";
|
|
41
|
+
readonly FactoryEventTypeDispatchQueued: "DISPATCH_QUEUED";
|
|
42
|
+
readonly FactoryEventTypeDispatchInterrupted: "DISPATCH_INTERRUPTED";
|
|
43
|
+
readonly FactoryEventTypeDispatchReconciled: "DISPATCH_RECONCILED";
|
|
44
|
+
readonly FactoryEventTypeJavaScriptCheckpointRef: "JAVASCRIPT_CHECKPOINT_REF";
|
|
45
|
+
readonly FactoryEventTypeJavaScriptPhaseChange: "JAVASCRIPT_PHASE_CHANGE";
|
|
46
|
+
readonly FactoryEventTypeArtifactCreated: "ARTIFACT_CREATED";
|
|
47
|
+
};
|
|
48
|
+
/** Runtime versions accepted by the canonical Factory event envelope. */
|
|
49
|
+
export declare const FACTORY_EVENT_SCHEMA_VERSIONS: {
|
|
50
|
+
readonly agent_factory_event_v1: "agent-factory.event.v1";
|
|
51
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FactoryEventSchemaVersion as GENERATED_FACTORY_EVENT_SCHEMA_VERSIONS, FactoryEventType as GENERATED_FACTORY_EVENT_TYPES, } from "./generated/openapi.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime Factory event constants generated from the canonical OpenAPI input.
|
|
4
|
+
* The object retains the generated keys and literal values without duplicating
|
|
5
|
+
* the event vocabulary in handwritten source.
|
|
6
|
+
*/
|
|
7
|
+
export const FACTORY_EVENT_TYPES = GENERATED_FACTORY_EVENT_TYPES;
|
|
8
|
+
/** Runtime versions accepted by the canonical Factory event envelope. */
|
|
9
|
+
export const FACTORY_EVENT_SCHEMA_VERSIONS = GENERATED_FACTORY_EVENT_SCHEMA_VERSIONS;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FactoryEvent } from "./contracts.js";
|
|
2
|
+
/** The reconnect position acknowledged by a downstream replay consumer. */
|
|
3
|
+
export interface FactoryEventCursor {
|
|
4
|
+
afterEventId: string;
|
|
5
|
+
afterSequence: number;
|
|
6
|
+
tick: number;
|
|
7
|
+
}
|
|
8
|
+
/** Return the session-scoped sequence when available, otherwise the event-log sequence. */
|
|
9
|
+
export declare function getFactoryEventEffectiveSequence(event: FactoryEvent): number;
|
|
10
|
+
/** Compare canonical Factory events by replay position. */
|
|
11
|
+
export declare function compareFactoryEvents(left: FactoryEvent, right: FactoryEvent): number;
|
|
12
|
+
/** Return a canonically ordered copy without mutating caller-owned events or arrays. */
|
|
13
|
+
export declare function orderFactoryEvents(events: readonly FactoryEvent[]): FactoryEvent[];
|
|
14
|
+
/** Build the reconnect cursor acknowledged at an accepted Factory event. */
|
|
15
|
+
export declare function createFactoryEventCursor(event: FactoryEvent): FactoryEventCursor;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Return the session-scoped sequence when available, otherwise the event-log sequence. */
|
|
2
|
+
export function getFactoryEventEffectiveSequence(event) {
|
|
3
|
+
return event.context.sessionSequence ?? event.context.sequence;
|
|
4
|
+
}
|
|
5
|
+
/** Compare canonical Factory events by replay position. */
|
|
6
|
+
export function compareFactoryEvents(left, right) {
|
|
7
|
+
const tickDifference = left.context.tick - right.context.tick;
|
|
8
|
+
if (tickDifference !== 0)
|
|
9
|
+
return tickDifference;
|
|
10
|
+
const sequenceDifference = getFactoryEventEffectiveSequence(left) -
|
|
11
|
+
getFactoryEventEffectiveSequence(right);
|
|
12
|
+
if (sequenceDifference !== 0)
|
|
13
|
+
return sequenceDifference;
|
|
14
|
+
const eventLogSequenceDifference = left.context.sequence - right.context.sequence;
|
|
15
|
+
if (eventLogSequenceDifference !== 0)
|
|
16
|
+
return eventLogSequenceDifference;
|
|
17
|
+
const timeDifference = left.context.eventTime.localeCompare(right.context.eventTime);
|
|
18
|
+
return timeDifference !== 0
|
|
19
|
+
? timeDifference
|
|
20
|
+
: left.id.localeCompare(right.id);
|
|
21
|
+
}
|
|
22
|
+
/** Return a canonically ordered copy without mutating caller-owned events or arrays. */
|
|
23
|
+
export function orderFactoryEvents(events) {
|
|
24
|
+
return [...events].sort(compareFactoryEvents);
|
|
25
|
+
}
|
|
26
|
+
/** Build the reconnect cursor acknowledged at an accepted Factory event. */
|
|
27
|
+
export function createFactoryEventCursor(event) {
|
|
28
|
+
return {
|
|
29
|
+
afterEventId: event.id,
|
|
30
|
+
afterSequence: getFactoryEventEffectiveSequence(event),
|
|
31
|
+
tick: event.context.tick,
|
|
32
|
+
};
|
|
33
|
+
}
|