@veruna/api-contracts 1.0.25 → 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/rest-api.d.ts +2 -1
- package/build/rest-api.js +2 -1
- package/build/routes/chat.routes.d.ts +2 -1
- package/build/routes/chat.routes.js +2 -1
- package/build/routes/message.routes.d.ts +1 -1
- package/build/routes/message.routes.js +1 -1
- package/build/v1/ai/ai.errors.d.ts +16 -0
- package/build/v1/ai/ai.errors.js +72 -0
- package/build/v1/ai/index.d.ts +1 -0
- package/build/v1/ai/index.js +17 -0
- package/build/v1/chat/commands/{get-or-create-unreg-chat.command.d.ts → create-unreg-chat.command.d.ts} +4 -4
- package/build/v1/chat/commands/create-unreg-chat.command.js +18 -0
- package/build/v1/chat/commands/index.d.ts +1 -1
- package/build/v1/chat/commands/index.js +3 -3
- package/build/v1/chat/index.d.ts +1 -0
- package/build/v1/chat/index.js +1 -0
- package/build/v1/chat/queries/get-unreg-chat.query.d.ts +32 -0
- package/build/v1/chat/queries/get-unreg-chat.query.js +18 -0
- package/build/v1/chat/queries/index.d.ts +1 -0
- package/build/v1/chat/queries/index.js +5 -0
- package/build/v1/chat/schemas/chat-status.enum.d.ts +1 -0
- package/build/v1/chat/schemas/chat-status.enum.js +1 -0
- package/build/v1/index.d.ts +1 -0
- package/build/v1/index.js +1 -0
- 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
- package/build/v1/chat/commands/get-or-create-unreg-chat.command.js +0 -18
package/build/rest-api.d.ts
CHANGED
|
@@ -106,7 +106,8 @@ export declare const REST_API: {
|
|
|
106
106
|
};
|
|
107
107
|
readonly CHAT: {
|
|
108
108
|
readonly UNREG: {
|
|
109
|
-
readonly
|
|
109
|
+
readonly GET: (pageId: string) => string;
|
|
110
|
+
readonly CREATE: (pageId: string) => string;
|
|
110
111
|
};
|
|
111
112
|
};
|
|
112
113
|
readonly MESSAGE: {
|
package/build/rest-api.js
CHANGED
|
@@ -123,7 +123,8 @@ exports.REST_API = {
|
|
|
123
123
|
},
|
|
124
124
|
CHAT: {
|
|
125
125
|
UNREG: {
|
|
126
|
-
|
|
126
|
+
GET: (pageId) => `${exports.ROOT}/${controllers_1.CHAT_UNREG_CONTROLLER.replace(':pageId', pageId)}`,
|
|
127
|
+
CREATE: (pageId) => `${exports.ROOT}/${controllers_1.CHAT_UNREG_CONTROLLER.replace(':pageId', pageId)}`,
|
|
127
128
|
},
|
|
128
129
|
},
|
|
129
130
|
MESSAGE: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ErrorMetadata } from '../../shared';
|
|
2
|
+
export declare enum AIErrorCode {
|
|
3
|
+
GENERATION_FAILED = "GENERATION_FAILED",
|
|
4
|
+
GENERATION_TIMEOUT = "GENERATION_TIMEOUT",
|
|
5
|
+
CONTENT_FILTERED = "CONTENT_FILTERED",
|
|
6
|
+
CONTEXT_TOO_LONG = "CONTEXT_TOO_LONG",
|
|
7
|
+
MODEL_NOT_FOUND = "MODEL_NOT_FOUND",
|
|
8
|
+
MODEL_UNAVAILABLE = "MODEL_UNAVAILABLE",
|
|
9
|
+
NO_SUITABLE_MODEL = "NO_SUITABLE_MODEL",
|
|
10
|
+
INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
|
|
11
|
+
COST_LIMIT_EXCEEDED = "COST_LIMIT_EXCEEDED",
|
|
12
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
13
|
+
PROVIDER_RATE_LIMIT = "PROVIDER_RATE_LIMIT",
|
|
14
|
+
PROVIDER_TIMEOUT = "PROVIDER_TIMEOUT"
|
|
15
|
+
}
|
|
16
|
+
export declare const AI_ERRORS: Record<AIErrorCode, ErrorMetadata>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AI_ERRORS = exports.AIErrorCode = void 0;
|
|
4
|
+
var AIErrorCode;
|
|
5
|
+
(function (AIErrorCode) {
|
|
6
|
+
// Generation
|
|
7
|
+
AIErrorCode["GENERATION_FAILED"] = "GENERATION_FAILED";
|
|
8
|
+
AIErrorCode["GENERATION_TIMEOUT"] = "GENERATION_TIMEOUT";
|
|
9
|
+
AIErrorCode["CONTENT_FILTERED"] = "CONTENT_FILTERED";
|
|
10
|
+
AIErrorCode["CONTEXT_TOO_LONG"] = "CONTEXT_TOO_LONG";
|
|
11
|
+
// Model
|
|
12
|
+
AIErrorCode["MODEL_NOT_FOUND"] = "MODEL_NOT_FOUND";
|
|
13
|
+
AIErrorCode["MODEL_UNAVAILABLE"] = "MODEL_UNAVAILABLE";
|
|
14
|
+
AIErrorCode["NO_SUITABLE_MODEL"] = "NO_SUITABLE_MODEL";
|
|
15
|
+
// Billing
|
|
16
|
+
AIErrorCode["INSUFFICIENT_BALANCE"] = "INSUFFICIENT_BALANCE";
|
|
17
|
+
AIErrorCode["COST_LIMIT_EXCEEDED"] = "COST_LIMIT_EXCEEDED";
|
|
18
|
+
// Provider
|
|
19
|
+
AIErrorCode["PROVIDER_ERROR"] = "PROVIDER_ERROR";
|
|
20
|
+
AIErrorCode["PROVIDER_RATE_LIMIT"] = "PROVIDER_RATE_LIMIT";
|
|
21
|
+
AIErrorCode["PROVIDER_TIMEOUT"] = "PROVIDER_TIMEOUT";
|
|
22
|
+
})(AIErrorCode || (exports.AIErrorCode = AIErrorCode = {}));
|
|
23
|
+
exports.AI_ERRORS = {
|
|
24
|
+
[AIErrorCode.GENERATION_FAILED]: {
|
|
25
|
+
code: AIErrorCode.GENERATION_FAILED,
|
|
26
|
+
statusCode: 500,
|
|
27
|
+
},
|
|
28
|
+
[AIErrorCode.GENERATION_TIMEOUT]: {
|
|
29
|
+
code: AIErrorCode.GENERATION_TIMEOUT,
|
|
30
|
+
statusCode: 504,
|
|
31
|
+
},
|
|
32
|
+
[AIErrorCode.CONTENT_FILTERED]: {
|
|
33
|
+
code: AIErrorCode.CONTENT_FILTERED,
|
|
34
|
+
statusCode: 400,
|
|
35
|
+
},
|
|
36
|
+
[AIErrorCode.CONTEXT_TOO_LONG]: {
|
|
37
|
+
code: AIErrorCode.CONTEXT_TOO_LONG,
|
|
38
|
+
statusCode: 400,
|
|
39
|
+
},
|
|
40
|
+
[AIErrorCode.MODEL_NOT_FOUND]: {
|
|
41
|
+
code: AIErrorCode.MODEL_NOT_FOUND,
|
|
42
|
+
statusCode: 404,
|
|
43
|
+
},
|
|
44
|
+
[AIErrorCode.MODEL_UNAVAILABLE]: {
|
|
45
|
+
code: AIErrorCode.MODEL_UNAVAILABLE,
|
|
46
|
+
statusCode: 503,
|
|
47
|
+
},
|
|
48
|
+
[AIErrorCode.NO_SUITABLE_MODEL]: {
|
|
49
|
+
code: AIErrorCode.NO_SUITABLE_MODEL,
|
|
50
|
+
statusCode: 400,
|
|
51
|
+
},
|
|
52
|
+
[AIErrorCode.INSUFFICIENT_BALANCE]: {
|
|
53
|
+
code: AIErrorCode.INSUFFICIENT_BALANCE,
|
|
54
|
+
statusCode: 402,
|
|
55
|
+
},
|
|
56
|
+
[AIErrorCode.COST_LIMIT_EXCEEDED]: {
|
|
57
|
+
code: AIErrorCode.COST_LIMIT_EXCEEDED,
|
|
58
|
+
statusCode: 402,
|
|
59
|
+
},
|
|
60
|
+
[AIErrorCode.PROVIDER_ERROR]: {
|
|
61
|
+
code: AIErrorCode.PROVIDER_ERROR,
|
|
62
|
+
statusCode: 502,
|
|
63
|
+
},
|
|
64
|
+
[AIErrorCode.PROVIDER_RATE_LIMIT]: {
|
|
65
|
+
code: AIErrorCode.PROVIDER_RATE_LIMIT,
|
|
66
|
+
statusCode: 429,
|
|
67
|
+
},
|
|
68
|
+
[AIErrorCode.PROVIDER_TIMEOUT]: {
|
|
69
|
+
code: AIErrorCode.PROVIDER_TIMEOUT,
|
|
70
|
+
statusCode: 504,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ai.errors';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ai.errors"), exports);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { HttpMethod } from '../../../shared/http-method';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Create Unreg Chat Command
|
|
5
|
+
* POST /api/v1/unreg/page/:pageId/chat
|
|
6
6
|
*/
|
|
7
|
-
export declare namespace
|
|
7
|
+
export declare namespace CreateUnregChatCommand {
|
|
8
8
|
const Request: z.ZodObject<{}, z.core.$strip>;
|
|
9
9
|
const Response: z.ZodObject<{
|
|
10
10
|
uuid: z.ZodString;
|
|
@@ -26,7 +26,7 @@ export declare namespace GetOrCreateUnregChatCommand {
|
|
|
26
26
|
}, z.core.$strip>>;
|
|
27
27
|
}, z.core.$strip>;
|
|
28
28
|
const URL: (pageId: string) => string;
|
|
29
|
-
const METHOD = HttpMethod.
|
|
29
|
+
const METHOD = HttpMethod.POST;
|
|
30
30
|
type RequestType = z.infer<typeof Request>;
|
|
31
31
|
type ResponseType = z.infer<typeof Response>;
|
|
32
32
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateUnregChatCommand = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schemas_1 = require("../schemas");
|
|
6
|
+
const rest_api_1 = require("../../../rest-api");
|
|
7
|
+
const http_method_1 = require("../../../shared/http-method");
|
|
8
|
+
/**
|
|
9
|
+
* Create Unreg Chat Command
|
|
10
|
+
* POST /api/v1/unreg/page/:pageId/chat
|
|
11
|
+
*/
|
|
12
|
+
var CreateUnregChatCommand;
|
|
13
|
+
(function (CreateUnregChatCommand) {
|
|
14
|
+
CreateUnregChatCommand.Request = zod_1.z.object({});
|
|
15
|
+
CreateUnregChatCommand.Response = schemas_1.ChatWithMessagesResponseSchema;
|
|
16
|
+
CreateUnregChatCommand.URL = (pageId) => rest_api_1.REST_API.V1.CHAT.UNREG.CREATE(pageId);
|
|
17
|
+
CreateUnregChatCommand.METHOD = http_method_1.HttpMethod.POST;
|
|
18
|
+
})(CreateUnregChatCommand || (exports.CreateUnregChatCommand = CreateUnregChatCommand = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CreateUnregChatCommand } from './create-unreg-chat.command';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.CreateUnregChatCommand = void 0;
|
|
4
|
+
var create_unreg_chat_command_1 = require("./create-unreg-chat.command");
|
|
5
|
+
Object.defineProperty(exports, "CreateUnregChatCommand", { enumerable: true, get: function () { return create_unreg_chat_command_1.CreateUnregChatCommand; } });
|
package/build/v1/chat/index.d.ts
CHANGED
package/build/v1/chat/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./schemas"), exports);
|
|
18
18
|
__exportStar(require("./commands"), exports);
|
|
19
|
+
__exportStar(require("./queries"), exports);
|
|
19
20
|
__exportStar(require("./chat.errors"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HttpMethod } from '../../../shared/http-method';
|
|
3
|
+
/**
|
|
4
|
+
* Get Unreg Chat Query
|
|
5
|
+
* GET /api/v1/unreg/page/:pageId/chat
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace GetUnregChatQuery {
|
|
8
|
+
const Request: z.ZodObject<{}, z.core.$strip>;
|
|
9
|
+
const Response: z.ZodObject<{
|
|
10
|
+
uuid: z.ZodString;
|
|
11
|
+
title: z.ZodString;
|
|
12
|
+
status: z.ZodEnum<typeof import("../schemas").ChatStatus>;
|
|
13
|
+
pageId: z.ZodNullable<z.ZodString>;
|
|
14
|
+
folderId: z.ZodNullable<z.ZodString>;
|
|
15
|
+
createdAt: z.ZodString;
|
|
16
|
+
updatedAt: z.ZodString;
|
|
17
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
18
|
+
uuid: z.ZodString;
|
|
19
|
+
role: z.ZodEnum<typeof import("../..").MessageRole>;
|
|
20
|
+
status: z.ZodEnum<typeof import("../..").MessageStatus>;
|
|
21
|
+
content: z.ZodString;
|
|
22
|
+
aiModelId: z.ZodNullable<z.ZodString>;
|
|
23
|
+
userRating: z.ZodNullable<z.ZodEnum<typeof import("../..").UserRating>>;
|
|
24
|
+
createdAt: z.ZodString;
|
|
25
|
+
updatedAt: z.ZodString;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
const URL: (pageId: string) => string;
|
|
29
|
+
const METHOD = HttpMethod.GET;
|
|
30
|
+
type RequestType = z.infer<typeof Request>;
|
|
31
|
+
type ResponseType = z.infer<typeof Response>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetUnregChatQuery = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schemas_1 = require("../schemas");
|
|
6
|
+
const rest_api_1 = require("../../../rest-api");
|
|
7
|
+
const http_method_1 = require("../../../shared/http-method");
|
|
8
|
+
/**
|
|
9
|
+
* Get Unreg Chat Query
|
|
10
|
+
* GET /api/v1/unreg/page/:pageId/chat
|
|
11
|
+
*/
|
|
12
|
+
var GetUnregChatQuery;
|
|
13
|
+
(function (GetUnregChatQuery) {
|
|
14
|
+
GetUnregChatQuery.Request = zod_1.z.object({});
|
|
15
|
+
GetUnregChatQuery.Response = schemas_1.ChatWithMessagesResponseSchema;
|
|
16
|
+
GetUnregChatQuery.URL = (pageId) => rest_api_1.REST_API.V1.CHAT.UNREG.GET(pageId);
|
|
17
|
+
GetUnregChatQuery.METHOD = http_method_1.HttpMethod.GET;
|
|
18
|
+
})(GetUnregChatQuery || (exports.GetUnregChatQuery = GetUnregChatQuery = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GetUnregChatQuery } from './get-unreg-chat.query';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetUnregChatQuery = void 0;
|
|
4
|
+
var get_unreg_chat_query_1 = require("./get-unreg-chat.query");
|
|
5
|
+
Object.defineProperty(exports, "GetUnregChatQuery", { enumerable: true, get: function () { return get_unreg_chat_query_1.GetUnregChatQuery; } });
|
package/build/v1/index.d.ts
CHANGED
package/build/v1/index.js
CHANGED
|
@@ -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 },
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetOrCreateUnregChatCommand = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const schemas_1 = require("../schemas");
|
|
6
|
-
const rest_api_1 = require("../../../rest-api");
|
|
7
|
-
const http_method_1 = require("../../../shared/http-method");
|
|
8
|
-
/**
|
|
9
|
-
* Get or Create Unreg Chat Command
|
|
10
|
-
* PUT /api/v1/unreg/page/:pageId/chat
|
|
11
|
-
*/
|
|
12
|
-
var GetOrCreateUnregChatCommand;
|
|
13
|
-
(function (GetOrCreateUnregChatCommand) {
|
|
14
|
-
GetOrCreateUnregChatCommand.Request = zod_1.z.object({});
|
|
15
|
-
GetOrCreateUnregChatCommand.Response = schemas_1.ChatWithMessagesResponseSchema;
|
|
16
|
-
GetOrCreateUnregChatCommand.URL = (pageId) => rest_api_1.REST_API.V1.CHAT.UNREG.GET_OR_CREATE(pageId);
|
|
17
|
-
GetOrCreateUnregChatCommand.METHOD = http_method_1.HttpMethod.PUT;
|
|
18
|
-
})(GetOrCreateUnregChatCommand || (exports.GetOrCreateUnregChatCommand = GetOrCreateUnregChatCommand = {}));
|