@veruna/api-contracts 1.0.26 → 1.0.27
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/build/routes/message.routes.d.ts +1 -1
- package/build/routes/message.routes.js +1 -1
- package/build/v1/message/commands/create-message.command.d.ts +81 -2
- package/build/v1/message/commands/create-message.command.js +43 -1
- package/build/v1/message/schemas/index.d.ts +1 -0
- package/build/v1/message/schemas/index.js +7 -1
- package/build/v1/message/schemas/stream-events.schema.d.ts +65 -0
- package/build/v1/message/schemas/stream-events.schema.js +66 -0
- package/build/v1/unregistered-users/unregistered-users.errors.d.ts +1 -0
- package/build/v1/unregistered-users/unregistered-users.errors.js +2 -0
- package/package.json +1 -1
|
@@ -1,15 +1,94 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { HttpMethod } from '../../../shared/http-method';
|
|
3
|
+
/**
|
|
4
|
+
* Send message and get AI response as NDJSON stream
|
|
5
|
+
*
|
|
6
|
+
* Response format: application/x-ndjson
|
|
7
|
+
* Each line is a JSON object that can be parsed with JSON.parse()
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const response = await fetch(url, { method: 'POST', body: JSON.stringify(request) });
|
|
12
|
+
* const reader = response.body.getReader();
|
|
13
|
+
* const decoder = new TextDecoder();
|
|
14
|
+
* let buffer = '';
|
|
15
|
+
*
|
|
16
|
+
* while (true) {
|
|
17
|
+
* const { done, value } = await reader.read();
|
|
18
|
+
* if (done) break;
|
|
19
|
+
*
|
|
20
|
+
* buffer += decoder.decode(value, { stream: true });
|
|
21
|
+
* const lines = buffer.split('\n');
|
|
22
|
+
* buffer = lines.pop()!;
|
|
23
|
+
*
|
|
24
|
+
* for (const line of lines) {
|
|
25
|
+
* if (line.trim()) {
|
|
26
|
+
* const event: CreateMessageCommand.StreamEventType = JSON.parse(line);
|
|
27
|
+
* switch (event.type) {
|
|
28
|
+
* case 'chunk': console.log(event.content); break;
|
|
29
|
+
* case 'done': console.log('Complete!'); break;
|
|
30
|
+
* case 'error': console.error('Error!'); break;
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
3
37
|
export declare namespace CreateMessageCommand {
|
|
4
38
|
const Request: z.ZodObject<{
|
|
5
39
|
aiModelId: z.ZodString;
|
|
6
40
|
text: z.ZodString;
|
|
7
41
|
}, z.core.$strip>;
|
|
8
|
-
|
|
42
|
+
/** Discriminated union of all stream events */
|
|
43
|
+
const StreamEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
44
|
+
id: z.ZodNumber;
|
|
45
|
+
chatId: z.ZodString;
|
|
9
46
|
messageId: z.ZodString;
|
|
47
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.CHUNK>;
|
|
48
|
+
content: z.ZodString;
|
|
49
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
50
|
+
id: z.ZodNumber;
|
|
51
|
+
chatId: z.ZodString;
|
|
52
|
+
messageId: z.ZodString;
|
|
53
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.DONE>;
|
|
54
|
+
content: z.ZodLiteral<"">;
|
|
55
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
56
|
+
id: z.ZodNumber;
|
|
57
|
+
chatId: z.ZodString;
|
|
58
|
+
messageId: z.ZodString;
|
|
59
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.ERROR>;
|
|
60
|
+
content: z.ZodLiteral<"">;
|
|
61
|
+
}, z.core.$strip>], "type">;
|
|
62
|
+
const ChunkEvent: z.ZodObject<{
|
|
63
|
+
id: z.ZodNumber;
|
|
64
|
+
chatId: z.ZodString;
|
|
65
|
+
messageId: z.ZodString;
|
|
66
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.CHUNK>;
|
|
67
|
+
content: z.ZodString;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
const DoneEvent: z.ZodObject<{
|
|
70
|
+
id: z.ZodNumber;
|
|
71
|
+
chatId: z.ZodString;
|
|
72
|
+
messageId: z.ZodString;
|
|
73
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.DONE>;
|
|
74
|
+
content: z.ZodLiteral<"">;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
const ErrorEvent: z.ZodObject<{
|
|
77
|
+
id: z.ZodNumber;
|
|
78
|
+
chatId: z.ZodString;
|
|
79
|
+
messageId: z.ZodString;
|
|
80
|
+
type: z.ZodLiteral<import("../schemas").StreamEventType.ERROR>;
|
|
81
|
+
content: z.ZodLiteral<"">;
|
|
10
82
|
}, z.core.$strip>;
|
|
11
83
|
const URL: (pageId: string, chatId: string) => string;
|
|
12
84
|
const METHOD = HttpMethod.POST;
|
|
85
|
+
/** Response content type */
|
|
86
|
+
const CONTENT_TYPE: "application/x-ndjson";
|
|
87
|
+
/** This endpoint returns a stream, not a single response */
|
|
88
|
+
const IS_STREAM: true;
|
|
13
89
|
type RequestType = z.infer<typeof Request>;
|
|
14
|
-
type
|
|
90
|
+
type StreamEventType = z.infer<typeof StreamEvent>;
|
|
91
|
+
type ChunkEventType = z.infer<typeof ChunkEvent>;
|
|
92
|
+
type DoneEventType = z.infer<typeof DoneEvent>;
|
|
93
|
+
type ErrorEventType = z.infer<typeof ErrorEvent>;
|
|
15
94
|
}
|
|
@@ -4,10 +4,52 @@ exports.CreateMessageCommand = void 0;
|
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const rest_api_1 = require("../../../rest-api");
|
|
6
6
|
const http_method_1 = require("../../../shared/http-method");
|
|
7
|
+
/**
|
|
8
|
+
* Send message and get AI response as NDJSON stream
|
|
9
|
+
*
|
|
10
|
+
* Response format: application/x-ndjson
|
|
11
|
+
* Each line is a JSON object that can be parsed with JSON.parse()
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const response = await fetch(url, { method: 'POST', body: JSON.stringify(request) });
|
|
16
|
+
* const reader = response.body.getReader();
|
|
17
|
+
* const decoder = new TextDecoder();
|
|
18
|
+
* let buffer = '';
|
|
19
|
+
*
|
|
20
|
+
* while (true) {
|
|
21
|
+
* const { done, value } = await reader.read();
|
|
22
|
+
* if (done) break;
|
|
23
|
+
*
|
|
24
|
+
* buffer += decoder.decode(value, { stream: true });
|
|
25
|
+
* const lines = buffer.split('\n');
|
|
26
|
+
* buffer = lines.pop()!;
|
|
27
|
+
*
|
|
28
|
+
* for (const line of lines) {
|
|
29
|
+
* if (line.trim()) {
|
|
30
|
+
* const event: CreateMessageCommand.StreamEventType = JSON.parse(line);
|
|
31
|
+
* switch (event.type) {
|
|
32
|
+
* case 'chunk': console.log(event.content); break;
|
|
33
|
+
* case 'done': console.log('Complete!'); break;
|
|
34
|
+
* case 'error': console.error('Error!'); break;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
7
41
|
var CreateMessageCommand;
|
|
8
42
|
(function (CreateMessageCommand) {
|
|
9
43
|
CreateMessageCommand.Request = schemas_1.CreateMessageRequestSchema;
|
|
10
|
-
|
|
44
|
+
/** Discriminated union of all stream events */
|
|
45
|
+
CreateMessageCommand.StreamEvent = schemas_1.StreamEventSchema;
|
|
46
|
+
CreateMessageCommand.ChunkEvent = schemas_1.StreamChunkEventSchema;
|
|
47
|
+
CreateMessageCommand.DoneEvent = schemas_1.StreamDoneEventSchema;
|
|
48
|
+
CreateMessageCommand.ErrorEvent = schemas_1.StreamErrorEventSchema;
|
|
11
49
|
CreateMessageCommand.URL = (pageId, chatId) => rest_api_1.REST_API.V1.MESSAGE.UNREG.CREATE(pageId, chatId);
|
|
12
50
|
CreateMessageCommand.METHOD = http_method_1.HttpMethod.POST;
|
|
51
|
+
/** Response content type */
|
|
52
|
+
CreateMessageCommand.CONTENT_TYPE = 'application/x-ndjson';
|
|
53
|
+
/** This endpoint returns a stream, not a single response */
|
|
54
|
+
CreateMessageCommand.IS_STREAM = true;
|
|
13
55
|
})(CreateMessageCommand || (exports.CreateMessageCommand = CreateMessageCommand = {}));
|
|
@@ -4,3 +4,4 @@ export { UserRating } from './user-rating.enum';
|
|
|
4
4
|
export { CreateMessageRequestSchema } from './create-message-request.schema';
|
|
5
5
|
export { CreateMessageResponseSchema } from './create-message-response.schema';
|
|
6
6
|
export { MessageResponseSchema } from './message-response.schema';
|
|
7
|
+
export { StreamEventType, StreamEventSchema, StreamChunkEventSchema, StreamDoneEventSchema, StreamErrorEventSchema, } from './stream-events.schema';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageResponseSchema = exports.CreateMessageResponseSchema = exports.CreateMessageRequestSchema = exports.UserRating = exports.MessageStatus = exports.MessageRole = void 0;
|
|
3
|
+
exports.StreamErrorEventSchema = exports.StreamDoneEventSchema = exports.StreamChunkEventSchema = exports.StreamEventSchema = exports.StreamEventType = exports.MessageResponseSchema = exports.CreateMessageResponseSchema = exports.CreateMessageRequestSchema = exports.UserRating = exports.MessageStatus = exports.MessageRole = void 0;
|
|
4
4
|
var message_role_enum_1 = require("./message-role.enum");
|
|
5
5
|
Object.defineProperty(exports, "MessageRole", { enumerable: true, get: function () { return message_role_enum_1.MessageRole; } });
|
|
6
6
|
var message_status_enum_1 = require("./message-status.enum");
|
|
@@ -13,3 +13,9 @@ var create_message_response_schema_1 = require("./create-message-response.schema
|
|
|
13
13
|
Object.defineProperty(exports, "CreateMessageResponseSchema", { enumerable: true, get: function () { return create_message_response_schema_1.CreateMessageResponseSchema; } });
|
|
14
14
|
var message_response_schema_1 = require("./message-response.schema");
|
|
15
15
|
Object.defineProperty(exports, "MessageResponseSchema", { enumerable: true, get: function () { return message_response_schema_1.MessageResponseSchema; } });
|
|
16
|
+
var stream_events_schema_1 = require("./stream-events.schema");
|
|
17
|
+
Object.defineProperty(exports, "StreamEventType", { enumerable: true, get: function () { return stream_events_schema_1.StreamEventType; } });
|
|
18
|
+
Object.defineProperty(exports, "StreamEventSchema", { enumerable: true, get: function () { return stream_events_schema_1.StreamEventSchema; } });
|
|
19
|
+
Object.defineProperty(exports, "StreamChunkEventSchema", { enumerable: true, get: function () { return stream_events_schema_1.StreamChunkEventSchema; } });
|
|
20
|
+
Object.defineProperty(exports, "StreamDoneEventSchema", { enumerable: true, get: function () { return stream_events_schema_1.StreamDoneEventSchema; } });
|
|
21
|
+
Object.defineProperty(exports, "StreamErrorEventSchema", { enumerable: true, get: function () { return stream_events_schema_1.StreamErrorEventSchema; } });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Stream Event Types for message streaming (NDJSON format)
|
|
4
|
+
*/
|
|
5
|
+
export declare enum StreamEventType {
|
|
6
|
+
/** Content chunk from AI */
|
|
7
|
+
CHUNK = "chunk",
|
|
8
|
+
/** Stream completed successfully */
|
|
9
|
+
DONE = "done",
|
|
10
|
+
/** Error occurred during streaming */
|
|
11
|
+
ERROR = "error"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Content chunk event - contains partial AI response
|
|
15
|
+
*/
|
|
16
|
+
export declare const StreamChunkEventSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodNumber;
|
|
18
|
+
chatId: z.ZodString;
|
|
19
|
+
messageId: z.ZodString;
|
|
20
|
+
type: z.ZodLiteral<StreamEventType.CHUNK>;
|
|
21
|
+
content: z.ZodString;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* Done event - stream completed successfully
|
|
25
|
+
*/
|
|
26
|
+
export declare const StreamDoneEventSchema: z.ZodObject<{
|
|
27
|
+
id: z.ZodNumber;
|
|
28
|
+
chatId: z.ZodString;
|
|
29
|
+
messageId: z.ZodString;
|
|
30
|
+
type: z.ZodLiteral<StreamEventType.DONE>;
|
|
31
|
+
content: z.ZodLiteral<"">;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/**
|
|
34
|
+
* Error event - error occurred during streaming
|
|
35
|
+
*/
|
|
36
|
+
export declare const StreamErrorEventSchema: z.ZodObject<{
|
|
37
|
+
id: z.ZodNumber;
|
|
38
|
+
chatId: z.ZodString;
|
|
39
|
+
messageId: z.ZodString;
|
|
40
|
+
type: z.ZodLiteral<StreamEventType.ERROR>;
|
|
41
|
+
content: z.ZodLiteral<"">;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
/**
|
|
44
|
+
* Discriminated union of all stream events
|
|
45
|
+
* Use `type` field to narrow the type
|
|
46
|
+
*/
|
|
47
|
+
export declare const StreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
48
|
+
id: z.ZodNumber;
|
|
49
|
+
chatId: z.ZodString;
|
|
50
|
+
messageId: z.ZodString;
|
|
51
|
+
type: z.ZodLiteral<StreamEventType.CHUNK>;
|
|
52
|
+
content: z.ZodString;
|
|
53
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
54
|
+
id: z.ZodNumber;
|
|
55
|
+
chatId: z.ZodString;
|
|
56
|
+
messageId: z.ZodString;
|
|
57
|
+
type: z.ZodLiteral<StreamEventType.DONE>;
|
|
58
|
+
content: z.ZodLiteral<"">;
|
|
59
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
60
|
+
id: z.ZodNumber;
|
|
61
|
+
chatId: z.ZodString;
|
|
62
|
+
messageId: z.ZodString;
|
|
63
|
+
type: z.ZodLiteral<StreamEventType.ERROR>;
|
|
64
|
+
content: z.ZodLiteral<"">;
|
|
65
|
+
}, z.core.$strip>], "type">;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamEventSchema = exports.StreamErrorEventSchema = exports.StreamDoneEventSchema = exports.StreamChunkEventSchema = exports.StreamEventType = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Stream Event Types for message streaming (NDJSON format)
|
|
7
|
+
*/
|
|
8
|
+
var StreamEventType;
|
|
9
|
+
(function (StreamEventType) {
|
|
10
|
+
/** Content chunk from AI */
|
|
11
|
+
StreamEventType["CHUNK"] = "chunk";
|
|
12
|
+
/** Stream completed successfully */
|
|
13
|
+
StreamEventType["DONE"] = "done";
|
|
14
|
+
/** Error occurred during streaming */
|
|
15
|
+
StreamEventType["ERROR"] = "error";
|
|
16
|
+
})(StreamEventType || (exports.StreamEventType = StreamEventType = {}));
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Base Event Schema
|
|
19
|
+
// ============================================================================
|
|
20
|
+
const BaseStreamEventSchema = zod_1.z.object({
|
|
21
|
+
/** Sequential event ID (starts from 1) */
|
|
22
|
+
id: zod_1.z.number().int().positive(),
|
|
23
|
+
/** Chat UUID */
|
|
24
|
+
chatId: zod_1.z.string().uuid(),
|
|
25
|
+
/** AI Message UUID */
|
|
26
|
+
messageId: zod_1.z.string().uuid(),
|
|
27
|
+
});
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Specific Event Schemas
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Content chunk event - contains partial AI response
|
|
33
|
+
*/
|
|
34
|
+
exports.StreamChunkEventSchema = BaseStreamEventSchema.extend({
|
|
35
|
+
type: zod_1.z.literal(StreamEventType.CHUNK),
|
|
36
|
+
/** Partial content from AI */
|
|
37
|
+
content: zod_1.z.string().min(1),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Done event - stream completed successfully
|
|
41
|
+
*/
|
|
42
|
+
exports.StreamDoneEventSchema = BaseStreamEventSchema.extend({
|
|
43
|
+
type: zod_1.z.literal(StreamEventType.DONE),
|
|
44
|
+
/** Always empty for done event */
|
|
45
|
+
content: zod_1.z.literal(''),
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Error event - error occurred during streaming
|
|
49
|
+
*/
|
|
50
|
+
exports.StreamErrorEventSchema = BaseStreamEventSchema.extend({
|
|
51
|
+
type: zod_1.z.literal(StreamEventType.ERROR),
|
|
52
|
+
/** Always empty for error event */
|
|
53
|
+
content: zod_1.z.literal(''),
|
|
54
|
+
});
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Union Schema
|
|
57
|
+
// ============================================================================
|
|
58
|
+
/**
|
|
59
|
+
* Discriminated union of all stream events
|
|
60
|
+
* Use `type` field to narrow the type
|
|
61
|
+
*/
|
|
62
|
+
exports.StreamEventSchema = zod_1.z.discriminatedUnion('type', [
|
|
63
|
+
exports.StreamChunkEventSchema,
|
|
64
|
+
exports.StreamDoneEventSchema,
|
|
65
|
+
exports.StreamErrorEventSchema,
|
|
66
|
+
]);
|
|
@@ -2,6 +2,7 @@ import { ErrorMetadata } from '../../shared/error-metadata';
|
|
|
2
2
|
export declare enum UnregUserErrorCode {
|
|
3
3
|
INVALID_TOKEN = "INVALID_TOKEN",
|
|
4
4
|
TOKEN_EXPIRED = "TOKEN_EXPIRED",
|
|
5
|
+
USER_NOT_FOUND = "USER_NOT_FOUND",
|
|
5
6
|
IP_MISMATCH = "IP_MISMATCH",
|
|
6
7
|
FRAUD_DETECTED = "FRAUD_DETECTED",
|
|
7
8
|
TOKEN_VERSION_MISMATCH = "TOKEN_VERSION_MISMATCH",
|
|
@@ -5,6 +5,7 @@ var UnregUserErrorCode;
|
|
|
5
5
|
(function (UnregUserErrorCode) {
|
|
6
6
|
UnregUserErrorCode["INVALID_TOKEN"] = "INVALID_TOKEN";
|
|
7
7
|
UnregUserErrorCode["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
|
|
8
|
+
UnregUserErrorCode["USER_NOT_FOUND"] = "USER_NOT_FOUND";
|
|
8
9
|
UnregUserErrorCode["IP_MISMATCH"] = "IP_MISMATCH";
|
|
9
10
|
UnregUserErrorCode["FRAUD_DETECTED"] = "FRAUD_DETECTED";
|
|
10
11
|
UnregUserErrorCode["TOKEN_VERSION_MISMATCH"] = "TOKEN_VERSION_MISMATCH";
|
|
@@ -17,6 +18,7 @@ var UnregUserErrorCode;
|
|
|
17
18
|
exports.UNREG_USER_ERRORS = {
|
|
18
19
|
[UnregUserErrorCode.INVALID_TOKEN]: { code: UnregUserErrorCode.INVALID_TOKEN, statusCode: 401 },
|
|
19
20
|
[UnregUserErrorCode.TOKEN_EXPIRED]: { code: UnregUserErrorCode.TOKEN_EXPIRED, statusCode: 401 },
|
|
21
|
+
[UnregUserErrorCode.USER_NOT_FOUND]: { code: UnregUserErrorCode.USER_NOT_FOUND, statusCode: 404 },
|
|
20
22
|
[UnregUserErrorCode.IP_MISMATCH]: { code: UnregUserErrorCode.IP_MISMATCH, statusCode: 403 },
|
|
21
23
|
[UnregUserErrorCode.FRAUD_DETECTED]: { code: UnregUserErrorCode.FRAUD_DETECTED, statusCode: 403 },
|
|
22
24
|
[UnregUserErrorCode.TOKEN_VERSION_MISMATCH]: { code: UnregUserErrorCode.TOKEN_VERSION_MISMATCH, statusCode: 401 },
|