@dungle-scrubs/tether-protocol 0.1.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,244 @@
1
+ import { z } from "zod";
2
+ import type { ParticipantRecord, SessionEvent, SessionEventType, TaskRecord } from "./records.js";
3
+ import { approvalDecisionSchema } from "./rest-schemas.js";
4
+ /** Payload schema for task-created events. */
5
+ export declare const taskCreatedPayloadSchema: z.ZodObject<{
6
+ task: z.ZodObject<{
7
+ cancelledAt: z.ZodNullable<z.ZodString>;
8
+ claimExpiredAt: z.ZodNullable<z.ZodString>;
9
+ claimExpiredBy: z.ZodNullable<z.ZodString>;
10
+ claimExpiresAt: z.ZodNullable<z.ZodString>;
11
+ claimedAt: z.ZodNullable<z.ZodString>;
12
+ claimedBy: z.ZodNullable<z.ZodString>;
13
+ completedAt: z.ZodNullable<z.ZodString>;
14
+ createdAt: z.ZodString;
15
+ failedAt: z.ZodNullable<z.ZodString>;
16
+ failure: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
17
+ input: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
18
+ kind: z.ZodString;
19
+ objective: z.ZodString;
20
+ releasedAt: z.ZodNullable<z.ZodString>;
21
+ releasedBy: z.ZodNullable<z.ZodString>;
22
+ result: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
23
+ sessionId: z.ZodString;
24
+ taskId: z.ZodString;
25
+ }, z.core.$strip>;
26
+ }, z.core.$strip>;
27
+ /** Payload schema for task-claim-expired events. */
28
+ export declare const taskClaimExpiredPayloadSchema: z.ZodObject<{
29
+ previousClaimedBy: z.ZodString;
30
+ task: z.ZodObject<{
31
+ cancelledAt: z.ZodNullable<z.ZodString>;
32
+ claimExpiredAt: z.ZodNullable<z.ZodString>;
33
+ claimExpiredBy: z.ZodNullable<z.ZodString>;
34
+ claimExpiresAt: z.ZodNullable<z.ZodString>;
35
+ claimedAt: z.ZodNullable<z.ZodString>;
36
+ claimedBy: z.ZodNullable<z.ZodString>;
37
+ completedAt: z.ZodNullable<z.ZodString>;
38
+ createdAt: z.ZodString;
39
+ failedAt: z.ZodNullable<z.ZodString>;
40
+ failure: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
+ input: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ kind: z.ZodString;
43
+ objective: z.ZodString;
44
+ releasedAt: z.ZodNullable<z.ZodString>;
45
+ releasedBy: z.ZodNullable<z.ZodString>;
46
+ result: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
47
+ sessionId: z.ZodString;
48
+ taskId: z.ZodString;
49
+ }, z.core.$strip>;
50
+ }, z.core.$strip>;
51
+ /** Payload schema for task participant lifecycle events that include a task. */
52
+ export declare const taskParticipantPayloadSchema: z.ZodObject<{
53
+ participantId: z.ZodString;
54
+ task: z.ZodObject<{
55
+ cancelledAt: z.ZodNullable<z.ZodString>;
56
+ claimExpiredAt: z.ZodNullable<z.ZodString>;
57
+ claimExpiredBy: z.ZodNullable<z.ZodString>;
58
+ claimExpiresAt: z.ZodNullable<z.ZodString>;
59
+ claimedAt: z.ZodNullable<z.ZodString>;
60
+ claimedBy: z.ZodNullable<z.ZodString>;
61
+ completedAt: z.ZodNullable<z.ZodString>;
62
+ createdAt: z.ZodString;
63
+ failedAt: z.ZodNullable<z.ZodString>;
64
+ failure: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
65
+ input: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
66
+ kind: z.ZodString;
67
+ objective: z.ZodString;
68
+ releasedAt: z.ZodNullable<z.ZodString>;
69
+ releasedBy: z.ZodNullable<z.ZodString>;
70
+ result: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
71
+ sessionId: z.ZodString;
72
+ taskId: z.ZodString;
73
+ }, z.core.$strip>;
74
+ }, z.core.$strip>;
75
+ /** Payload schema for task cancellation events. */
76
+ export declare const taskCancelledPayloadSchema: z.ZodObject<{
77
+ participantId: z.ZodString;
78
+ reason: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
79
+ task: z.ZodObject<{
80
+ cancelledAt: z.ZodNullable<z.ZodString>;
81
+ claimExpiredAt: z.ZodNullable<z.ZodString>;
82
+ claimExpiredBy: z.ZodNullable<z.ZodString>;
83
+ claimExpiresAt: z.ZodNullable<z.ZodString>;
84
+ claimedAt: z.ZodNullable<z.ZodString>;
85
+ claimedBy: z.ZodNullable<z.ZodString>;
86
+ completedAt: z.ZodNullable<z.ZodString>;
87
+ createdAt: z.ZodString;
88
+ failedAt: z.ZodNullable<z.ZodString>;
89
+ failure: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
+ input: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
91
+ kind: z.ZodString;
92
+ objective: z.ZodString;
93
+ releasedAt: z.ZodNullable<z.ZodString>;
94
+ releasedBy: z.ZodNullable<z.ZodString>;
95
+ result: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
96
+ sessionId: z.ZodString;
97
+ taskId: z.ZodString;
98
+ }, z.core.$strip>;
99
+ }, z.core.$strip>;
100
+ /** Event payload schema for task approval decisions. */
101
+ export declare const taskApprovalRecordedPayloadSchema: z.ZodObject<{
102
+ decision: z.ZodUnion<readonly [z.ZodLiteral<"approved">, z.ZodLiteral<"rejected">]>;
103
+ participantId: z.ZodString;
104
+ reason: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
105
+ task: z.ZodObject<{
106
+ cancelledAt: z.ZodNullable<z.ZodString>;
107
+ claimExpiredAt: z.ZodNullable<z.ZodString>;
108
+ claimExpiredBy: z.ZodNullable<z.ZodString>;
109
+ claimExpiresAt: z.ZodNullable<z.ZodString>;
110
+ claimedAt: z.ZodNullable<z.ZodString>;
111
+ claimedBy: z.ZodNullable<z.ZodString>;
112
+ completedAt: z.ZodNullable<z.ZodString>;
113
+ createdAt: z.ZodString;
114
+ failedAt: z.ZodNullable<z.ZodString>;
115
+ failure: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
116
+ input: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
117
+ kind: z.ZodString;
118
+ objective: z.ZodString;
119
+ releasedAt: z.ZodNullable<z.ZodString>;
120
+ releasedBy: z.ZodNullable<z.ZodString>;
121
+ result: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
122
+ sessionId: z.ZodString;
123
+ taskId: z.ZodString;
124
+ }, z.core.$strip>;
125
+ }, z.core.$strip>;
126
+ /** Runtime validator for public session events. */
127
+ export declare const sessionEventSchema: z.ZodObject<{
128
+ createdAt: z.ZodString;
129
+ eventId: z.ZodString;
130
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
131
+ producerId: z.ZodString;
132
+ seq: z.ZodNumber;
133
+ sessionId: z.ZodString;
134
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<(string & {}) | "agent.output" | "approval.recorded" | "control.cancel" | "participant.heartbeat" | "participant.joined" | "participant.updated" | "session.created" | "task.claim_expired" | "task.claimed" | "task.completed" | "task.created" | "task.failed" | "task.progress" | "task.released" | "user.message", string>>;
135
+ }, z.core.$strip>;
136
+ /** Input for appending a canonical session event. */
137
+ export interface AppendSessionEventInput {
138
+ readonly eventId: string;
139
+ readonly payload: Record<string, unknown>;
140
+ readonly producerId: string;
141
+ readonly sessionId: string;
142
+ readonly type: SessionEventType;
143
+ }
144
+ type BuildParticipantEventInput = {
145
+ readonly participant: ParticipantRecord;
146
+ readonly sessionId: string;
147
+ readonly status: "joined" | "refreshed";
148
+ } | {
149
+ readonly participant: ParticipantRecord;
150
+ readonly previousParticipant: ParticipantRecord;
151
+ readonly sessionId: string;
152
+ readonly status: "updated";
153
+ };
154
+ interface BuildTaskParticipantEventInput {
155
+ readonly participantId: string;
156
+ readonly sessionId: string;
157
+ readonly task: TaskRecord;
158
+ }
159
+ interface BuildTaskCancelledEventInput extends BuildTaskParticipantEventInput {
160
+ readonly reason: Record<string, unknown>;
161
+ }
162
+ interface BuildTaskApprovalRecordedEventInput extends BuildTaskParticipantEventInput {
163
+ readonly decision: z.infer<typeof approvalDecisionSchema>;
164
+ readonly reason: Record<string, unknown>;
165
+ }
166
+ interface BuildTaskCreatedEventInput {
167
+ readonly sessionId: string;
168
+ readonly task: TaskRecord;
169
+ }
170
+ interface BuildTaskClaimExpiredEventInput {
171
+ readonly previousClaimedBy: string;
172
+ readonly sessionId: string;
173
+ readonly task: TaskRecord;
174
+ }
175
+ interface BuildPublishedEventInput {
176
+ readonly eventId?: string;
177
+ readonly payload: Record<string, unknown>;
178
+ readonly producerId: string;
179
+ readonly sessionId: string;
180
+ readonly type: string;
181
+ }
182
+ interface BuildTaskOutputEventInput {
183
+ readonly output: string;
184
+ readonly participantId: string;
185
+ readonly sessionId: string;
186
+ readonly taskId: string;
187
+ }
188
+ interface BuildTaskProgressEventInput {
189
+ readonly participantId: string;
190
+ readonly sessionId: string;
191
+ readonly taskId: string;
192
+ }
193
+ /** Creates a unique event id in Tether's public event-id namespace. */
194
+ export declare function newEventId(): string;
195
+ /** Creates a participant id scoped by runtime kind for generated REST participants. */
196
+ export declare function newParticipantId(runtimeKind: string): string;
197
+ /** Creates a unique runtime instance id. */
198
+ export declare function newParticipantInstanceId(): string;
199
+ /** Creates a unique session id. */
200
+ export declare function newSessionId(): string;
201
+ /** Creates a unique task id. */
202
+ export declare function newTaskId(): string;
203
+ /** Parses an event replay cursor, falling back to the beginning of the stream. */
204
+ export declare function parseAfterSeq(value: string | null | undefined): number;
205
+ /** Parses a positive safe integer without coercing partial decimal strings. */
206
+ export declare function parsePositiveSafeInteger(value: string | number | bigint | null | undefined): number | null;
207
+ /** Builds the durable event for a newly-created session. */
208
+ export declare function buildSessionCreatedEventInput(sessionId: string): AppendSessionEventInput;
209
+ /** Builds a caller-published session event while applying Tether id defaults. */
210
+ export declare function buildPublishedEventInput(input: BuildPublishedEventInput): AppendSessionEventInput;
211
+ /** Builds participant join/update events. */
212
+ export declare function buildParticipantRegistrationEventInput(input: BuildParticipantEventInput): AppendSessionEventInput | null;
213
+ /** Builds the visible heartbeat event emitted after presence state refreshes. */
214
+ export declare function buildParticipantHeartbeatEventInput(input: {
215
+ readonly participant: ParticipantRecord;
216
+ readonly sessionId: string;
217
+ }): AppendSessionEventInput;
218
+ /** Builds the canonical event for a newly-created task. */
219
+ export declare function buildTaskCreatedEventInput(input: BuildTaskCreatedEventInput): AppendSessionEventInput;
220
+ /** Builds the canonical event for a user or bridge approval decision. */
221
+ export declare function buildTaskApprovalRecordedEventInput(input: BuildTaskApprovalRecordedEventInput): AppendSessionEventInput;
222
+ /** Builds the canonical event for a successful task claim. */
223
+ export declare function buildTaskClaimedEventInput(input: BuildTaskParticipantEventInput): AppendSessionEventInput;
224
+ /** Builds the canonical event for an expired task claim. */
225
+ export declare function buildTaskClaimExpiredEventInput(input: BuildTaskClaimExpiredEventInput): AppendSessionEventInput;
226
+ /** Builds the canonical event for a cancelled task. */
227
+ export declare function buildTaskCancelledEventInput(input: BuildTaskCancelledEventInput): AppendSessionEventInput;
228
+ /** Builds the canonical event for a completed task. */
229
+ export declare function buildTaskCompletedEventInput(input: BuildTaskParticipantEventInput): AppendSessionEventInput;
230
+ /** Builds the canonical event for a failed task. */
231
+ export declare function buildTaskFailedEventInput(input: BuildTaskParticipantEventInput): AppendSessionEventInput;
232
+ /** Builds the canonical event for a released task claim. */
233
+ export declare function buildTaskReleasedEventInput(input: BuildTaskParticipantEventInput): AppendSessionEventInput;
234
+ /** Builds the standard progress event published by simple participant workers. */
235
+ export declare function buildTaskProgressEventInput(input: BuildTaskProgressEventInput): AppendSessionEventInput;
236
+ /** Builds the standard output event published by simple participant workers. */
237
+ export declare function buildTaskOutputEventInput(input: BuildTaskOutputEventInput): AppendSessionEventInput;
238
+ /** Extracts a task from a task-created event payload. */
239
+ export declare function taskFromCreatedEvent(event: SessionEvent): TaskRecord | null;
240
+ /** Extracts a task that has become claimable from the public event stream. */
241
+ export declare function taskFromClaimableEvent(event: SessionEvent): TaskRecord | null;
242
+ /** Extracts the cancelled task id from a task cancellation event payload. */
243
+ export declare function taskIdFromCancelledEvent(event: SessionEvent): string | null;
244
+ export {};
@@ -0,0 +1,259 @@
1
+ import { z } from "zod";
2
+ import { sessionEventType, systemProducerId, taskRecordSchema } from "./records.js";
3
+ import { approvalDecisionSchema } from "./rest-schemas.js";
4
+ const sessionEventTypeSchema = z
5
+ .string()
6
+ .min(1)
7
+ .transform((value) => value);
8
+ /** Payload schema for task-created events. */
9
+ export const taskCreatedPayloadSchema = z.object({
10
+ task: taskRecordSchema,
11
+ });
12
+ /** Payload schema for task-claim-expired events. */
13
+ export const taskClaimExpiredPayloadSchema = z.object({
14
+ previousClaimedBy: z.string().min(1),
15
+ task: taskRecordSchema,
16
+ });
17
+ /** Payload schema for task participant lifecycle events that include a task. */
18
+ export const taskParticipantPayloadSchema = z.object({
19
+ participantId: z.string().min(1),
20
+ task: taskRecordSchema,
21
+ });
22
+ /** Payload schema for task cancellation events. */
23
+ export const taskCancelledPayloadSchema = z.object({
24
+ participantId: z.string().min(1),
25
+ reason: z.record(z.string(), z.unknown()).default({}),
26
+ task: taskRecordSchema,
27
+ });
28
+ /** Event payload schema for task approval decisions. */
29
+ export const taskApprovalRecordedPayloadSchema = z.object({
30
+ decision: approvalDecisionSchema,
31
+ participantId: z.string().min(1),
32
+ reason: z.record(z.string(), z.unknown()).default({}),
33
+ task: taskRecordSchema,
34
+ });
35
+ /** Runtime validator for public session events. */
36
+ export const sessionEventSchema = z.object({
37
+ createdAt: z.string(),
38
+ eventId: z.string().min(1),
39
+ payload: z.record(z.string(), z.unknown()),
40
+ producerId: z.string().min(1),
41
+ seq: z.number(),
42
+ sessionId: z.string().min(1),
43
+ type: sessionEventTypeSchema,
44
+ });
45
+ /** Creates a unique event id in Tether's public event-id namespace. */
46
+ export function newEventId() {
47
+ return `evt_${newProtocolId()}`;
48
+ }
49
+ /** Creates a participant id scoped by runtime kind for generated REST participants. */
50
+ export function newParticipantId(runtimeKind) {
51
+ return `part_${runtimeKind}_${newProtocolId()}`;
52
+ }
53
+ /** Creates a unique runtime instance id. */
54
+ export function newParticipantInstanceId() {
55
+ return `inst_${newProtocolId()}`;
56
+ }
57
+ /** Creates a unique session id. */
58
+ export function newSessionId() {
59
+ return `sess_${newProtocolId()}`;
60
+ }
61
+ /** Creates a unique task id. */
62
+ export function newTaskId() {
63
+ return `task_${newProtocolId()}`;
64
+ }
65
+ /** Parses an event replay cursor, falling back to the beginning of the stream. */
66
+ export function parseAfterSeq(value) {
67
+ return parsePositiveSafeInteger(value) ?? 0;
68
+ }
69
+ /** Parses a positive safe integer without coercing partial decimal strings. */
70
+ export function parsePositiveSafeInteger(value) {
71
+ if (!value) {
72
+ return null;
73
+ }
74
+ const parsed = Number(value);
75
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
76
+ }
77
+ /** Builds the durable event for a newly-created session. */
78
+ export function buildSessionCreatedEventInput(sessionId) {
79
+ return {
80
+ eventId: newEventId(),
81
+ payload: {},
82
+ producerId: systemProducerId,
83
+ sessionId,
84
+ type: sessionEventType.sessionCreated,
85
+ };
86
+ }
87
+ /** Builds a caller-published session event while applying Tether id defaults. */
88
+ export function buildPublishedEventInput(input) {
89
+ return {
90
+ eventId: input.eventId ?? newEventId(),
91
+ payload: input.payload,
92
+ producerId: input.producerId,
93
+ sessionId: input.sessionId,
94
+ type: input.type,
95
+ };
96
+ }
97
+ /** Builds participant join/update events. */
98
+ export function buildParticipantRegistrationEventInput(input) {
99
+ if (input.status === "refreshed") {
100
+ return null;
101
+ }
102
+ return {
103
+ eventId: newEventId(),
104
+ payload: input.status === "updated"
105
+ ? {
106
+ participant: input.participant,
107
+ previousParticipant: input.previousParticipant,
108
+ }
109
+ : { participant: input.participant },
110
+ producerId: systemProducerId,
111
+ sessionId: input.sessionId,
112
+ type: input.status === "joined"
113
+ ? sessionEventType.participantJoined
114
+ : sessionEventType.participantUpdated,
115
+ };
116
+ }
117
+ /** Builds the visible heartbeat event emitted after presence state refreshes. */
118
+ export function buildParticipantHeartbeatEventInput(input) {
119
+ return {
120
+ eventId: newEventId(),
121
+ payload: { participant: input.participant },
122
+ producerId: systemProducerId,
123
+ sessionId: input.sessionId,
124
+ type: sessionEventType.participantHeartbeat,
125
+ };
126
+ }
127
+ /** Builds the canonical event for a newly-created task. */
128
+ export function buildTaskCreatedEventInput(input) {
129
+ return {
130
+ eventId: newEventId(),
131
+ payload: { task: input.task },
132
+ producerId: systemProducerId,
133
+ sessionId: input.sessionId,
134
+ type: sessionEventType.taskCreated,
135
+ };
136
+ }
137
+ /** Builds the canonical event for a user or bridge approval decision. */
138
+ export function buildTaskApprovalRecordedEventInput(input) {
139
+ return {
140
+ eventId: newEventId(),
141
+ payload: {
142
+ decision: input.decision,
143
+ participantId: input.participantId,
144
+ reason: input.reason,
145
+ task: input.task,
146
+ },
147
+ producerId: systemProducerId,
148
+ sessionId: input.sessionId,
149
+ type: sessionEventType.approvalRecorded,
150
+ };
151
+ }
152
+ /** Builds the canonical event for a successful task claim. */
153
+ export function buildTaskClaimedEventInput(input) {
154
+ return buildTaskParticipantEventInput(input, sessionEventType.taskClaimed);
155
+ }
156
+ /** Builds the canonical event for an expired task claim. */
157
+ export function buildTaskClaimExpiredEventInput(input) {
158
+ return {
159
+ eventId: newEventId(),
160
+ payload: { previousClaimedBy: input.previousClaimedBy, task: input.task },
161
+ producerId: systemProducerId,
162
+ sessionId: input.sessionId,
163
+ type: sessionEventType.taskClaimExpired,
164
+ };
165
+ }
166
+ /** Builds the canonical event for a cancelled task. */
167
+ export function buildTaskCancelledEventInput(input) {
168
+ return {
169
+ eventId: newEventId(),
170
+ payload: {
171
+ participantId: input.participantId,
172
+ reason: input.reason,
173
+ task: input.task,
174
+ },
175
+ producerId: systemProducerId,
176
+ sessionId: input.sessionId,
177
+ type: sessionEventType.controlCancel,
178
+ };
179
+ }
180
+ /** Builds the canonical event for a completed task. */
181
+ export function buildTaskCompletedEventInput(input) {
182
+ return buildTaskParticipantEventInput(input, sessionEventType.taskCompleted);
183
+ }
184
+ /** Builds the canonical event for a failed task. */
185
+ export function buildTaskFailedEventInput(input) {
186
+ return buildTaskParticipantEventInput(input, sessionEventType.taskFailed);
187
+ }
188
+ /** Builds the canonical event for a released task claim. */
189
+ export function buildTaskReleasedEventInput(input) {
190
+ return buildTaskParticipantEventInput(input, sessionEventType.taskReleased);
191
+ }
192
+ /** Builds the standard progress event published by simple participant workers. */
193
+ export function buildTaskProgressEventInput(input) {
194
+ return {
195
+ eventId: newEventId(),
196
+ payload: { taskId: input.taskId },
197
+ producerId: input.participantId,
198
+ sessionId: input.sessionId,
199
+ type: sessionEventType.taskProgress,
200
+ };
201
+ }
202
+ /** Builds the standard output event published by simple participant workers. */
203
+ export function buildTaskOutputEventInput(input) {
204
+ return {
205
+ eventId: newEventId(),
206
+ payload: { output: input.output, taskId: input.taskId },
207
+ producerId: input.participantId,
208
+ sessionId: input.sessionId,
209
+ type: sessionEventType.agentOutput,
210
+ };
211
+ }
212
+ /** Extracts a task from a task-created event payload. */
213
+ export function taskFromCreatedEvent(event) {
214
+ if (event.type !== sessionEventType.taskCreated) {
215
+ return null;
216
+ }
217
+ const parsed = taskCreatedPayloadSchema.safeParse(event.payload);
218
+ return parsed.success ? parsed.data.task : null;
219
+ }
220
+ /** Extracts a task that has become claimable from the public event stream. */
221
+ export function taskFromClaimableEvent(event) {
222
+ if (event.type === sessionEventType.taskCreated) {
223
+ return taskFromCreatedEvent(event);
224
+ }
225
+ if (event.type === sessionEventType.taskClaimExpired) {
226
+ const parsed = taskClaimExpiredPayloadSchema.safeParse(event.payload);
227
+ return parsed.success ? parsed.data.task : null;
228
+ }
229
+ if (event.type !== sessionEventType.taskReleased) {
230
+ return null;
231
+ }
232
+ const parsed = taskParticipantPayloadSchema.safeParse(event.payload);
233
+ return parsed.success ? parsed.data.task : null;
234
+ }
235
+ /** Extracts the cancelled task id from a task cancellation event payload. */
236
+ export function taskIdFromCancelledEvent(event) {
237
+ if (event.type !== sessionEventType.controlCancel) {
238
+ return null;
239
+ }
240
+ const parsed = taskCancelledPayloadSchema.safeParse(event.payload);
241
+ return parsed.success ? parsed.data.task.taskId : null;
242
+ }
243
+ function buildTaskParticipantEventInput(input, type) {
244
+ return {
245
+ eventId: newEventId(),
246
+ payload: { participantId: input.participantId, task: input.task },
247
+ producerId: systemProducerId,
248
+ sessionId: input.sessionId,
249
+ type,
250
+ };
251
+ }
252
+ function newProtocolId() {
253
+ const randomUuid = readGlobalRandomUuid();
254
+ return randomUuid ?? `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 12)}`;
255
+ }
256
+ function readGlobalRandomUuid() {
257
+ const candidate = globalThis;
258
+ return candidate.crypto?.randomUUID?.() ?? null;
259
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./event-builders.js";
2
+ export * from "./records.js";
3
+ export * from "./rest-schemas.js";
4
+ export * from "./task-contracts.js";
5
+ export * from "./task-payload-display.js";
6
+ export * from "./websocket.js";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./event-builders.js";
2
+ export * from "./records.js";
3
+ export * from "./rest-schemas.js";
4
+ export * from "./task-contracts.js";
5
+ export * from "./task-payload-display.js";
6
+ export * from "./websocket.js";