@clawrent/protocol 0.1.0 → 0.3.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/LICENSE +15 -0
- package/dist/envelope.d.ts +3 -0
- package/dist/envelope.d.ts.map +1 -1
- package/dist/envelope.js +1 -0
- package/dist/envelope.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ws-events.d.ts +202 -0
- package/dist/ws-events.d.ts.map +1 -0
- package/dist/ws-events.js +79 -0
- package/dist/ws-events.js.map +1 -0
- package/package.json +6 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ClawRent
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/dist/envelope.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare const ClawRentMessageSchema: z.ZodObject<{
|
|
|
25
25
|
}>;
|
|
26
26
|
type: z.ZodEnum<[string, ...string[]]>;
|
|
27
27
|
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
28
|
+
targetSlot: z.ZodOptional<z.ZodNumber>;
|
|
28
29
|
signature: z.ZodOptional<z.ZodString>;
|
|
29
30
|
}, "strip", z.ZodTypeAny, {
|
|
30
31
|
type: string;
|
|
@@ -36,6 +37,7 @@ export declare const ClawRentMessageSchema: z.ZodObject<{
|
|
|
36
37
|
agentId: string;
|
|
37
38
|
};
|
|
38
39
|
payload: Record<string, unknown>;
|
|
40
|
+
targetSlot?: number | undefined;
|
|
39
41
|
signature?: string | undefined;
|
|
40
42
|
}, {
|
|
41
43
|
type: string;
|
|
@@ -47,6 +49,7 @@ export declare const ClawRentMessageSchema: z.ZodObject<{
|
|
|
47
49
|
agentId: string;
|
|
48
50
|
};
|
|
49
51
|
payload: Record<string, unknown>;
|
|
52
|
+
targetSlot?: number | undefined;
|
|
50
53
|
signature?: string | undefined;
|
|
51
54
|
}>;
|
|
52
55
|
export type ClawRentMessage = z.infer<typeof ClawRentMessageSchema>;
|
package/dist/envelope.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,YAAY;;;;;;;;;EAGvB,CAAC;AAEH,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,YAAY;;;;;;;;;EAGvB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAShC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
package/dist/envelope.js
CHANGED
|
@@ -12,6 +12,7 @@ export const ClawRentMessageSchema = z.object({
|
|
|
12
12
|
sender: SenderSchema,
|
|
13
13
|
type: z.enum(allMessageTypes),
|
|
14
14
|
payload: z.record(z.unknown()),
|
|
15
|
+
targetSlot: z.number().int().min(0).optional(),
|
|
15
16
|
signature: z.string().optional(),
|
|
16
17
|
});
|
|
17
18
|
//# sourceMappingURL=envelope.js.map
|
package/dist/envelope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,eAAwC,CAAC;IACtD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,eAAwC,CAAC;IACtD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { MessageType } from './message-types.js';
|
|
2
2
|
export { ClawRentMessageSchema, type ClawRentMessage } from './envelope.js';
|
|
3
|
+
export { wsSessionMessageEventSchema, type WsSessionMessageEvent, wsSystemEventSchema, type WsSystemEvent, wsAgentControlEventSchema, type WsAgentControlEvent, } from './ws-events.js';
|
|
3
4
|
export { ExecInstructionSchema, type ExecInstruction } from './instructions/exec.js';
|
|
4
5
|
export { ReadFileInstructionSchema, type ReadFileInstruction } from './instructions/read-file.js';
|
|
5
6
|
export { WriteFileInstructionSchema, type WriteFileInstruction } from './instructions/write-file.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,0BAA0B,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,KAAK,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,E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,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,eAAe,EACpB,gBAAgB,EAChB,KAAK,UAAU,EACf,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,wBAAwB,EACxB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { MessageType } from './message-types.js';
|
|
2
2
|
export { ClawRentMessageSchema } from './envelope.js';
|
|
3
|
+
export { wsSessionMessageEventSchema, wsSystemEventSchema, wsAgentControlEventSchema, } from './ws-events.js';
|
|
3
4
|
export { ExecInstructionSchema } from './instructions/exec.js';
|
|
4
5
|
export { ReadFileInstructionSchema } from './instructions/read-file.js';
|
|
5
6
|
export { WriteFileInstructionSchema } from './instructions/write-file.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAwB,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAA4B,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,0BAA0B,EAA6B,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,wBAAwB,EAA2B,MAAM,4BAA4B,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAyB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AE,oBAAoB,EAAuB,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAwB,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,qBAAqB,EAErB,qBAAqB,EAErB,gBAAgB,EAEhB,wBAAwB,EAExB,yBAAyB,EAEzB,wBAAwB,GAEzB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* /ws/session peer message frame — the forwardPayload pushed by the platform
|
|
4
|
+
* when a consumer or provider sends a dialogue/instruction/result message.
|
|
5
|
+
* Mirrors apps/platform-api/src/ws/ws-handler.ts (forwardPayload, ~L403-416):
|
|
6
|
+
* { id, sessionId, timestamp, sender:{role,agentId,slotIndex?}, type, payload, _meta }
|
|
7
|
+
* `sender.agentId` is always present backend-side (agentId ?? userId).
|
|
8
|
+
*/
|
|
9
|
+
export declare const wsSessionMessageEventSchema: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
sessionId: z.ZodString;
|
|
12
|
+
timestamp: z.ZodNumber;
|
|
13
|
+
sender: z.ZodObject<{
|
|
14
|
+
role: z.ZodEnum<["provider", "consumer", "platform", "staff"]>;
|
|
15
|
+
agentId: z.ZodString;
|
|
16
|
+
slotIndex: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
role: "provider" | "consumer" | "platform" | "staff";
|
|
19
|
+
agentId: string;
|
|
20
|
+
slotIndex?: number | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
role: "provider" | "consumer" | "platform" | "staff";
|
|
23
|
+
agentId: string;
|
|
24
|
+
slotIndex?: number | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
type: z.ZodString;
|
|
27
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
28
|
+
_meta: z.ZodObject<{
|
|
29
|
+
sessionId: z.ZodString;
|
|
30
|
+
senderRole: z.ZodString;
|
|
31
|
+
slotIndex: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
timestamp: z.ZodString;
|
|
33
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
34
|
+
sessionId: z.ZodString;
|
|
35
|
+
senderRole: z.ZodString;
|
|
36
|
+
slotIndex: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
timestamp: z.ZodString;
|
|
38
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
39
|
+
sessionId: z.ZodString;
|
|
40
|
+
senderRole: z.ZodString;
|
|
41
|
+
slotIndex: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
timestamp: z.ZodString;
|
|
43
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
type: string;
|
|
46
|
+
id: string;
|
|
47
|
+
sessionId: string;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
sender: {
|
|
50
|
+
role: "provider" | "consumer" | "platform" | "staff";
|
|
51
|
+
agentId: string;
|
|
52
|
+
slotIndex?: number | undefined;
|
|
53
|
+
};
|
|
54
|
+
payload: Record<string, unknown>;
|
|
55
|
+
_meta: {
|
|
56
|
+
sessionId: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
senderRole: string;
|
|
59
|
+
slotIndex?: number | undefined;
|
|
60
|
+
} & {
|
|
61
|
+
[k: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
}, {
|
|
64
|
+
type: string;
|
|
65
|
+
id: string;
|
|
66
|
+
sessionId: string;
|
|
67
|
+
timestamp: number;
|
|
68
|
+
sender: {
|
|
69
|
+
role: "provider" | "consumer" | "platform" | "staff";
|
|
70
|
+
agentId: string;
|
|
71
|
+
slotIndex?: number | undefined;
|
|
72
|
+
};
|
|
73
|
+
payload: Record<string, unknown>;
|
|
74
|
+
_meta: {
|
|
75
|
+
sessionId: string;
|
|
76
|
+
timestamp: string;
|
|
77
|
+
senderRole: string;
|
|
78
|
+
slotIndex?: number | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
[k: string]: unknown;
|
|
81
|
+
};
|
|
82
|
+
}>;
|
|
83
|
+
export type WsSessionMessageEvent = z.infer<typeof wsSessionMessageEventSchema>;
|
|
84
|
+
/**
|
|
85
|
+
* /ws/session system.* events. Types confirmed in backend:
|
|
86
|
+
* peer_connected/peer_disconnected (ws-handler.ts), peer_offline (ws-handler.ts),
|
|
87
|
+
* blocked (ws-handler.ts security gateway), error (ws-agent-handler.ts / ws-handler.ts),
|
|
88
|
+
* session_ended (client-manager.ts closeSessionClients — carries `reason`).
|
|
89
|
+
*/
|
|
90
|
+
export declare const wsSystemEventSchema: z.ZodObject<{
|
|
91
|
+
type: z.ZodEnum<["system.peer_connected", "system.peer_disconnected", "system.peer_offline", "system.blocked", "system.error", "system.session_ended"]>;
|
|
92
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
93
|
+
payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
type: "system.peer_connected" | "system.peer_disconnected" | "system.peer_offline" | "system.blocked" | "system.error" | "system.session_ended";
|
|
96
|
+
sessionId?: string | undefined;
|
|
97
|
+
payload?: Record<string, unknown> | undefined;
|
|
98
|
+
}, {
|
|
99
|
+
type: "system.peer_connected" | "system.peer_disconnected" | "system.peer_offline" | "system.blocked" | "system.error" | "system.session_ended";
|
|
100
|
+
sessionId?: string | undefined;
|
|
101
|
+
payload?: Record<string, unknown> | undefined;
|
|
102
|
+
}>;
|
|
103
|
+
export type WsSystemEvent = z.infer<typeof wsSystemEventSchema>;
|
|
104
|
+
/**
|
|
105
|
+
* /ws/agent control channel events delivered via `sendToAgent(agentId, {type, payload})`.
|
|
106
|
+
* Discriminator is `type` (not `event`) and fields live under `payload` — confirmed at
|
|
107
|
+
* sessions.routes.ts:201-212 / 572-580 and orders.routes.ts:229-237.
|
|
108
|
+
*
|
|
109
|
+
* Note: backend does NOT push `session.ended` on /ws/agent. Session terminations arrive
|
|
110
|
+
* as `system.session_ended` on /ws/session (see wsSystemEventSchema).
|
|
111
|
+
*/
|
|
112
|
+
export declare const wsAgentControlEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
113
|
+
type: z.ZodLiteral<"session.new">;
|
|
114
|
+
payload: z.ZodObject<{
|
|
115
|
+
sessionId: z.ZodString;
|
|
116
|
+
sessionToken: z.ZodOptional<z.ZodString>;
|
|
117
|
+
status: z.ZodOptional<z.ZodString>;
|
|
118
|
+
consumerUserId: z.ZodOptional<z.ZodString>;
|
|
119
|
+
taskDescription: z.ZodOptional<z.ZodString>;
|
|
120
|
+
pricingSnapshot: z.ZodOptional<z.ZodUnknown>;
|
|
121
|
+
orderId: z.ZodOptional<z.ZodString>;
|
|
122
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
|
124
|
+
sessionId: string;
|
|
125
|
+
status?: string | undefined;
|
|
126
|
+
timestamp?: string | undefined;
|
|
127
|
+
sessionToken?: string | undefined;
|
|
128
|
+
consumerUserId?: string | undefined;
|
|
129
|
+
taskDescription?: string | undefined;
|
|
130
|
+
pricingSnapshot?: unknown;
|
|
131
|
+
orderId?: string | undefined;
|
|
132
|
+
}, {
|
|
133
|
+
sessionId: string;
|
|
134
|
+
status?: string | undefined;
|
|
135
|
+
timestamp?: string | undefined;
|
|
136
|
+
sessionToken?: string | undefined;
|
|
137
|
+
consumerUserId?: string | undefined;
|
|
138
|
+
taskDescription?: string | undefined;
|
|
139
|
+
pricingSnapshot?: unknown;
|
|
140
|
+
orderId?: string | undefined;
|
|
141
|
+
}>;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
type: "session.new";
|
|
144
|
+
payload: {
|
|
145
|
+
sessionId: string;
|
|
146
|
+
status?: string | undefined;
|
|
147
|
+
timestamp?: string | undefined;
|
|
148
|
+
sessionToken?: string | undefined;
|
|
149
|
+
consumerUserId?: string | undefined;
|
|
150
|
+
taskDescription?: string | undefined;
|
|
151
|
+
pricingSnapshot?: unknown;
|
|
152
|
+
orderId?: string | undefined;
|
|
153
|
+
};
|
|
154
|
+
}, {
|
|
155
|
+
type: "session.new";
|
|
156
|
+
payload: {
|
|
157
|
+
sessionId: string;
|
|
158
|
+
status?: string | undefined;
|
|
159
|
+
timestamp?: string | undefined;
|
|
160
|
+
sessionToken?: string | undefined;
|
|
161
|
+
consumerUserId?: string | undefined;
|
|
162
|
+
taskDescription?: string | undefined;
|
|
163
|
+
pricingSnapshot?: unknown;
|
|
164
|
+
orderId?: string | undefined;
|
|
165
|
+
};
|
|
166
|
+
}>, z.ZodObject<{
|
|
167
|
+
type: z.ZodLiteral<"session.approved">;
|
|
168
|
+
payload: z.ZodObject<{
|
|
169
|
+
sessionId: z.ZodString;
|
|
170
|
+
sessionToken: z.ZodOptional<z.ZodString>;
|
|
171
|
+
status: z.ZodOptional<z.ZodString>;
|
|
172
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
sessionId: string;
|
|
175
|
+
status?: string | undefined;
|
|
176
|
+
timestamp?: string | undefined;
|
|
177
|
+
sessionToken?: string | undefined;
|
|
178
|
+
}, {
|
|
179
|
+
sessionId: string;
|
|
180
|
+
status?: string | undefined;
|
|
181
|
+
timestamp?: string | undefined;
|
|
182
|
+
sessionToken?: string | undefined;
|
|
183
|
+
}>;
|
|
184
|
+
}, "strip", z.ZodTypeAny, {
|
|
185
|
+
type: "session.approved";
|
|
186
|
+
payload: {
|
|
187
|
+
sessionId: string;
|
|
188
|
+
status?: string | undefined;
|
|
189
|
+
timestamp?: string | undefined;
|
|
190
|
+
sessionToken?: string | undefined;
|
|
191
|
+
};
|
|
192
|
+
}, {
|
|
193
|
+
type: "session.approved";
|
|
194
|
+
payload: {
|
|
195
|
+
sessionId: string;
|
|
196
|
+
status?: string | undefined;
|
|
197
|
+
timestamp?: string | undefined;
|
|
198
|
+
sessionToken?: string | undefined;
|
|
199
|
+
};
|
|
200
|
+
}>]>;
|
|
201
|
+
export type WsAgentControlEvent = z.infer<typeof wsAgentControlEventSchema>;
|
|
202
|
+
//# sourceMappingURL=ws-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws-events.d.ts","sourceRoot":"","sources":["../src/ws-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBtC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAW9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuBpC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* /ws/session peer message frame — the forwardPayload pushed by the platform
|
|
4
|
+
* when a consumer or provider sends a dialogue/instruction/result message.
|
|
5
|
+
* Mirrors apps/platform-api/src/ws/ws-handler.ts (forwardPayload, ~L403-416):
|
|
6
|
+
* { id, sessionId, timestamp, sender:{role,agentId,slotIndex?}, type, payload, _meta }
|
|
7
|
+
* `sender.agentId` is always present backend-side (agentId ?? userId).
|
|
8
|
+
*/
|
|
9
|
+
export const wsSessionMessageEventSchema = z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
sessionId: z.string(),
|
|
12
|
+
timestamp: z.number(),
|
|
13
|
+
sender: z.object({
|
|
14
|
+
role: z.enum(['provider', 'consumer', 'platform', 'staff']),
|
|
15
|
+
agentId: z.string(),
|
|
16
|
+
slotIndex: z.number().int().min(0).optional(),
|
|
17
|
+
}),
|
|
18
|
+
type: z.string(),
|
|
19
|
+
payload: z.record(z.unknown()),
|
|
20
|
+
_meta: z
|
|
21
|
+
.object({
|
|
22
|
+
sessionId: z.string(),
|
|
23
|
+
senderRole: z.string(),
|
|
24
|
+
slotIndex: z.number().int().min(0).optional(),
|
|
25
|
+
timestamp: z.string(),
|
|
26
|
+
})
|
|
27
|
+
.passthrough(),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* /ws/session system.* events. Types confirmed in backend:
|
|
31
|
+
* peer_connected/peer_disconnected (ws-handler.ts), peer_offline (ws-handler.ts),
|
|
32
|
+
* blocked (ws-handler.ts security gateway), error (ws-agent-handler.ts / ws-handler.ts),
|
|
33
|
+
* session_ended (client-manager.ts closeSessionClients — carries `reason`).
|
|
34
|
+
*/
|
|
35
|
+
export const wsSystemEventSchema = z.object({
|
|
36
|
+
type: z.enum([
|
|
37
|
+
'system.peer_connected',
|
|
38
|
+
'system.peer_disconnected',
|
|
39
|
+
'system.peer_offline',
|
|
40
|
+
'system.blocked',
|
|
41
|
+
'system.error',
|
|
42
|
+
'system.session_ended',
|
|
43
|
+
]),
|
|
44
|
+
sessionId: z.string().optional(),
|
|
45
|
+
payload: z.record(z.unknown()).optional(),
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* /ws/agent control channel events delivered via `sendToAgent(agentId, {type, payload})`.
|
|
49
|
+
* Discriminator is `type` (not `event`) and fields live under `payload` — confirmed at
|
|
50
|
+
* sessions.routes.ts:201-212 / 572-580 and orders.routes.ts:229-237.
|
|
51
|
+
*
|
|
52
|
+
* Note: backend does NOT push `session.ended` on /ws/agent. Session terminations arrive
|
|
53
|
+
* as `system.session_ended` on /ws/session (see wsSystemEventSchema).
|
|
54
|
+
*/
|
|
55
|
+
export const wsAgentControlEventSchema = z.discriminatedUnion('type', [
|
|
56
|
+
z.object({
|
|
57
|
+
type: z.literal('session.new'),
|
|
58
|
+
payload: z.object({
|
|
59
|
+
sessionId: z.string(),
|
|
60
|
+
sessionToken: z.string().optional(),
|
|
61
|
+
status: z.string().optional(),
|
|
62
|
+
consumerUserId: z.string().optional(),
|
|
63
|
+
taskDescription: z.string().optional(),
|
|
64
|
+
pricingSnapshot: z.unknown().optional(),
|
|
65
|
+
orderId: z.string().optional(),
|
|
66
|
+
timestamp: z.string().optional(),
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
z.object({
|
|
70
|
+
type: z.literal('session.approved'),
|
|
71
|
+
payload: z.object({
|
|
72
|
+
sessionId: z.string(),
|
|
73
|
+
sessionToken: z.string().optional(),
|
|
74
|
+
status: z.string().optional(),
|
|
75
|
+
timestamp: z.string().optional(),
|
|
76
|
+
}),
|
|
77
|
+
}),
|
|
78
|
+
]);
|
|
79
|
+
//# sourceMappingURL=ws-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws-events.js","sourceRoot":"","sources":["../src/ws-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,SAAS,EAAE,CAAC,CAAC,MAAM,EAA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ist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,12 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.7.0",
|
|
24
|
-
"
|
|
25
|
-
"@clawrent/shared-types": "0.
|
|
24
|
+
"vitest": "^3.0.0",
|
|
25
|
+
"@clawrent/shared-types": "0.2.0",
|
|
26
|
+
"@clawrent/config": "0.1.0"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
|
-
"build": "tsc",
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
29
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "vitest run",
|
|
30
32
|
"lint": "eslint src/"
|
|
31
33
|
}
|
|
32
34
|
}
|