@orq-ai/node 3.9.4 → 3.9.6
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/README.md +2 -5
- package/bin/mcp-server.js +560 -866
- package/bin/mcp-server.js.map +36 -36
- package/docs/sdks/knowledge/README.md +77 -0
- package/examples/README.md +26 -0
- package/examples/contactsCreate.example.ts +40 -0
- package/examples/package-lock.json +626 -0
- package/examples/package.json +18 -0
- package/funcs/deploymentsStream.js +7 -7
- package/funcs/deploymentsStream.js.map +1 -1
- package/funcs/{knowledgeBasesChunkText.d.ts → knowledgeCreate.d.ts} +3 -6
- package/funcs/knowledgeCreate.d.ts.map +1 -0
- package/funcs/{knowledgeBasesChunkText.js → knowledgeCreate.js} +7 -10
- package/funcs/knowledgeCreate.js.map +1 -0
- package/jsr.json +1 -1
- package/lib/config.d.ts +3 -3
- package/lib/config.js +3 -3
- package/lib/event-streams.d.ts +4 -10
- package/lib/event-streams.d.ts.map +1 -1
- package/lib/event-streams.js +110 -194
- package/lib/event-streams.js.map +1 -1
- package/lib/matchers.d.ts.map +1 -1
- package/lib/matchers.js +1 -4
- package/lib/matchers.js.map +1 -1
- package/mcp-server/mcp-server.js +1 -1
- package/mcp-server/server.js +3 -3
- package/mcp-server/server.js.map +1 -1
- package/mcp-server/tools/knowledgeCreate.d.ts +8 -0
- package/mcp-server/tools/knowledgeCreate.d.ts.map +1 -0
- package/mcp-server/tools/{knowledgeBasesChunkText.js → knowledgeCreate.js} +8 -10
- package/mcp-server/tools/knowledgeCreate.js.map +1 -0
- package/models/operations/createcontact.js +2 -2
- package/models/operations/createdataset.js +2 -2
- package/models/operations/createdatasetitem.js +2 -2
- package/models/operations/createdatasource.js +2 -2
- package/models/operations/createeval.js +16 -16
- package/models/operations/createknowledge.d.ts +426 -0
- package/models/operations/createknowledge.d.ts.map +1 -0
- package/models/operations/createknowledge.js +431 -0
- package/models/operations/createknowledge.js.map +1 -0
- package/models/operations/fileget.js +2 -2
- package/models/operations/filelist.js +2 -2
- package/models/operations/fileupload.js +2 -2
- package/models/operations/getevals.js +28 -28
- package/models/operations/index.d.ts +1 -1
- package/models/operations/index.d.ts.map +1 -1
- package/models/operations/index.js +1 -1
- package/models/operations/index.js.map +1 -1
- package/models/operations/listcontacts.js +2 -2
- package/models/operations/listdatasetdatapoints.js +2 -2
- package/models/operations/listdatasets.js +2 -2
- package/models/operations/listdatasources.js +2 -2
- package/models/operations/retrievecontact.js +2 -2
- package/models/operations/retrievedatapoint.js +2 -2
- package/models/operations/retrievedataset.js +2 -2
- package/models/operations/retrievedatasource.js +2 -2
- package/models/operations/updatecontact.js +2 -2
- package/models/operations/updatedatapoint.js +2 -2
- package/models/operations/updatedataset.js +2 -2
- package/models/operations/updatedatasource.js +2 -2
- package/models/operations/updateeval.js +16 -16
- package/models/operations/updateknowledge.d.ts +106 -106
- package/models/operations/updateknowledge.d.ts.map +1 -1
- package/models/operations/updateknowledge.js +125 -129
- package/models/operations/updateknowledge.js.map +1 -1
- package/package.json +1 -1
- package/packages/orq-rc/examples/README.md +26 -0
- package/packages/orq-rc/examples/contactsCreate.example.ts +40 -0
- package/packages/orq-rc/examples/package-lock.json +626 -0
- package/packages/orq-rc/examples/package.json +18 -0
- package/packages/orq-rc/jsr.json +1 -1
- package/packages/orq-rc/package-lock.json +2 -2
- package/packages/orq-rc/package.json +1 -1
- package/packages/orq-rc/src/funcs/deploymentsStream.ts +7 -8
- package/packages/orq-rc/src/lib/config.ts +3 -3
- package/packages/orq-rc/src/lib/event-streams.ts +114 -231
- package/packages/orq-rc/src/lib/matchers.ts +1 -4
- package/packages/orq-rc/src/mcp-server/mcp-server.ts +1 -1
- package/packages/orq-rc/src/mcp-server/server.ts +1 -1
- package/packages/orq-rc/src/models/operations/createcontact.ts +2 -2
- package/packages/orq-rc/src/models/operations/createdataset.ts +2 -2
- package/packages/orq-rc/src/models/operations/createdatasetitem.ts +2 -2
- package/packages/orq-rc/src/models/operations/createdatasource.ts +2 -2
- package/packages/orq-rc/src/models/operations/createeval.ts +16 -16
- package/packages/orq-rc/src/models/operations/fileget.ts +2 -2
- package/packages/orq-rc/src/models/operations/filelist.ts +2 -2
- package/packages/orq-rc/src/models/operations/fileupload.ts +2 -2
- package/packages/orq-rc/src/models/operations/getevals.ts +28 -28
- package/packages/orq-rc/src/models/operations/listcontacts.ts +2 -2
- package/packages/orq-rc/src/models/operations/listdatasetdatapoints.ts +2 -2
- package/packages/orq-rc/src/models/operations/listdatasets.ts +2 -2
- package/packages/orq-rc/src/models/operations/listdatasources.ts +2 -2
- package/packages/orq-rc/src/models/operations/retrievecontact.ts +2 -2
- package/packages/orq-rc/src/models/operations/retrievedatapoint.ts +2 -2
- package/packages/orq-rc/src/models/operations/retrievedataset.ts +2 -2
- package/packages/orq-rc/src/models/operations/retrievedatasource.ts +2 -2
- package/packages/orq-rc/src/models/operations/updatecontact.ts +2 -2
- package/packages/orq-rc/src/models/operations/updatedatapoint.ts +2 -2
- package/packages/orq-rc/src/models/operations/updatedataset.ts +2 -2
- package/packages/orq-rc/src/models/operations/updatedatasource.ts +2 -2
- package/packages/orq-rc/src/models/operations/updateeval.ts +16 -16
- package/sdk/knowledge.d.ts +4 -0
- package/sdk/knowledge.d.ts.map +1 -1
- package/sdk/knowledge.js +7 -0
- package/sdk/knowledge.js.map +1 -1
- package/sdk/sdk.d.ts +0 -3
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +0 -4
- package/sdk/sdk.js.map +1 -1
- package/src/funcs/deploymentsStream.ts +7 -8
- package/src/funcs/{knowledgeBasesChunkText.ts → knowledgeCreate.ts} +11 -13
- package/src/lib/config.ts +3 -3
- package/src/lib/event-streams.ts +114 -231
- package/src/lib/matchers.ts +1 -4
- package/src/mcp-server/mcp-server.ts +1 -1
- package/src/mcp-server/server.ts +3 -3
- package/src/mcp-server/tools/knowledgeCreate.ts +35 -0
- package/src/models/operations/createcontact.ts +2 -2
- package/src/models/operations/createdataset.ts +2 -2
- package/src/models/operations/createdatasetitem.ts +2 -2
- package/src/models/operations/createdatasource.ts +2 -2
- package/src/models/operations/createeval.ts +16 -16
- package/src/models/operations/createknowledge.ts +846 -0
- package/src/models/operations/fileget.ts +2 -2
- package/src/models/operations/filelist.ts +2 -2
- package/src/models/operations/fileupload.ts +2 -2
- package/src/models/operations/getevals.ts +28 -28
- package/src/models/operations/index.ts +1 -1
- package/src/models/operations/listcontacts.ts +2 -2
- package/src/models/operations/listdatasetdatapoints.ts +2 -2
- package/src/models/operations/listdatasets.ts +2 -2
- package/src/models/operations/listdatasources.ts +2 -2
- package/src/models/operations/retrievecontact.ts +2 -2
- package/src/models/operations/retrievedatapoint.ts +2 -2
- package/src/models/operations/retrievedataset.ts +2 -2
- package/src/models/operations/retrievedatasource.ts +2 -2
- package/src/models/operations/updatecontact.ts +2 -2
- package/src/models/operations/updatedatapoint.ts +2 -2
- package/src/models/operations/updatedataset.ts +2 -2
- package/src/models/operations/updatedatasource.ts +2 -2
- package/src/models/operations/updateeval.ts +16 -16
- package/src/models/operations/updateknowledge.ts +266 -206
- package/src/sdk/knowledge.ts +15 -0
- package/src/sdk/sdk.ts +0 -6
- package/docs/sdks/knowledgebases/README.md +0 -94
- package/funcs/knowledgeBasesChunkText.d.ts.map +0 -1
- package/funcs/knowledgeBasesChunkText.js.map +0 -1
- package/mcp-server/tools/knowledgeBasesChunkText.d.ts +0 -8
- package/mcp-server/tools/knowledgeBasesChunkText.d.ts.map +0 -1
- package/mcp-server/tools/knowledgeBasesChunkText.js.map +0 -1
- package/models/operations/chunktext.d.ts +0 -961
- package/models/operations/chunktext.d.ts.map +0 -1
- package/models/operations/chunktext.js +0 -883
- package/models/operations/chunktext.js.map +0 -1
- package/sdk/knowledgebases.d.ts +0 -12
- package/sdk/knowledgebases.d.ts.map +0 -1
- package/sdk/knowledgebases.js +0 -22
- package/sdk/knowledgebases.js.map +0 -1
- package/src/mcp-server/tools/knowledgeBasesChunkText.ts +0 -37
- package/src/models/operations/chunktext.ts +0 -1629
- package/src/sdk/knowledgebases.ts +0 -27
|
@@ -25,18 +25,15 @@ import { APICall, APIPromise } from "../types/async.js";
|
|
|
25
25
|
import { Result } from "../types/fp.js";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* Split large text documents into smaller, manageable chunks using different chunking strategies optimized for RAG (Retrieval-Augmented Generation) workflows. This endpoint supports multiple chunking algorithms including token-based, sentence-based, recursive, semantic, and specialized strategies.
|
|
28
|
+
* Create a knowledge
|
|
32
29
|
*/
|
|
33
|
-
export function
|
|
30
|
+
export function knowledgeCreate(
|
|
34
31
|
client: OrqCore,
|
|
35
|
-
request: operations.
|
|
32
|
+
request: operations.CreateKnowledgeRequestBody,
|
|
36
33
|
options?: RequestOptions,
|
|
37
34
|
): APIPromise<
|
|
38
35
|
Result<
|
|
39
|
-
operations.
|
|
36
|
+
operations.CreateKnowledgeResponseBody,
|
|
40
37
|
| OrqError
|
|
41
38
|
| ResponseValidationError
|
|
42
39
|
| ConnectionError
|
|
@@ -56,12 +53,12 @@ export function knowledgeBasesChunkText(
|
|
|
56
53
|
|
|
57
54
|
async function $do(
|
|
58
55
|
client: OrqCore,
|
|
59
|
-
request: operations.
|
|
56
|
+
request: operations.CreateKnowledgeRequestBody,
|
|
60
57
|
options?: RequestOptions,
|
|
61
58
|
): Promise<
|
|
62
59
|
[
|
|
63
60
|
Result<
|
|
64
|
-
operations.
|
|
61
|
+
operations.CreateKnowledgeResponseBody,
|
|
65
62
|
| OrqError
|
|
66
63
|
| ResponseValidationError
|
|
67
64
|
| ConnectionError
|
|
@@ -76,7 +73,8 @@ async function $do(
|
|
|
76
73
|
> {
|
|
77
74
|
const parsed = safeParse(
|
|
78
75
|
request,
|
|
79
|
-
(value) =>
|
|
76
|
+
(value) =>
|
|
77
|
+
operations.CreateKnowledgeRequestBody$outboundSchema.parse(value),
|
|
80
78
|
"Input validation failed",
|
|
81
79
|
);
|
|
82
80
|
if (!parsed.ok) {
|
|
@@ -99,7 +97,7 @@ async function $do(
|
|
|
99
97
|
const context = {
|
|
100
98
|
options: client._options,
|
|
101
99
|
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
102
|
-
operationID: "
|
|
100
|
+
operationID: "CreateKnowledge",
|
|
103
101
|
oAuth2Scopes: [],
|
|
104
102
|
|
|
105
103
|
resolvedSecurity: requestSecurity,
|
|
@@ -138,7 +136,7 @@ async function $do(
|
|
|
138
136
|
const response = doResult.value;
|
|
139
137
|
|
|
140
138
|
const [result] = await M.match<
|
|
141
|
-
operations.
|
|
139
|
+
operations.CreateKnowledgeResponseBody,
|
|
142
140
|
| OrqError
|
|
143
141
|
| ResponseValidationError
|
|
144
142
|
| ConnectionError
|
|
@@ -148,7 +146,7 @@ async function $do(
|
|
|
148
146
|
| UnexpectedClientError
|
|
149
147
|
| SDKValidationError
|
|
150
148
|
>(
|
|
151
|
-
M.json(200, operations.
|
|
149
|
+
M.json(200, operations.CreateKnowledgeResponseBody$inboundSchema),
|
|
152
150
|
M.fail("4XX"),
|
|
153
151
|
M.fail("5XX"),
|
|
154
152
|
)(response, req);
|
package/src/lib/config.ts
CHANGED
|
@@ -68,7 +68,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
68
68
|
export const SDK_METADATA = {
|
|
69
69
|
language: "typescript",
|
|
70
70
|
openapiDocVersion: "2.0",
|
|
71
|
-
sdkVersion: "3.9.
|
|
72
|
-
genVersion: "2.
|
|
73
|
-
userAgent: "speakeasy-sdk/typescript 3.9.
|
|
71
|
+
sdkVersion: "3.9.6",
|
|
72
|
+
genVersion: "2.654.2",
|
|
73
|
+
userAgent: "speakeasy-sdk/typescript 3.9.6 2.654.2 2.0 @orq-ai/node",
|
|
74
74
|
} as const;
|
package/src/lib/event-streams.ts
CHANGED
|
@@ -5,260 +5,143 @@
|
|
|
5
5
|
export type ServerEvent<T> = {
|
|
6
6
|
data?: T | undefined;
|
|
7
7
|
event?: string | undefined;
|
|
8
|
-
retry?: number | undefined;
|
|
9
8
|
id?: string | undefined;
|
|
9
|
+
retry?: number | undefined;
|
|
10
10
|
};
|
|
11
|
-
const LF = 0x0a;
|
|
12
|
-
const CR = 0x0d;
|
|
13
|
-
const NEWLINE_CHARS = new Set([LF, CR]);
|
|
14
|
-
const MESSAGE_BOUNDARIES = [
|
|
15
|
-
new Uint8Array([CR, LF, CR, LF]),
|
|
16
|
-
new Uint8Array([CR, CR]),
|
|
17
|
-
new Uint8Array([LF, LF]),
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
export class EventStream<Event extends ServerEvent<unknown>> {
|
|
21
|
-
private readonly stream: ReadableStream<Uint8Array>;
|
|
22
|
-
private readonly decoder: (rawEvent: ServerEvent<string>) => Event;
|
|
23
|
-
|
|
24
|
-
constructor(init: {
|
|
25
|
-
stream: ReadableStream<Uint8Array>;
|
|
26
|
-
decoder: (rawEvent: ServerEvent<string>) => Event;
|
|
27
|
-
}) {
|
|
28
|
-
this.stream = init.stream;
|
|
29
|
-
this.decoder = init.decoder;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async *[Symbol.asyncIterator](): AsyncGenerator<Event, void, unknown> {
|
|
33
|
-
const reader = this.stream.getReader();
|
|
34
|
-
let buffer = new Uint8Array([]);
|
|
35
|
-
let position = 0;
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
while (true) {
|
|
39
|
-
const { done, value } = await reader.read();
|
|
40
|
-
if (done) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const newBuffer = new Uint8Array(buffer.length + value.length);
|
|
45
|
-
newBuffer.set(buffer);
|
|
46
|
-
newBuffer.set(value, buffer.length);
|
|
47
|
-
buffer = newBuffer;
|
|
48
|
-
|
|
49
|
-
for (let i = position; i < buffer.length; i++) {
|
|
50
|
-
const boundary = findBoundary(buffer, i);
|
|
51
|
-
if (boundary == null) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
11
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
12
|
+
export class EventStream<T extends ServerEvent<unknown>>
|
|
13
|
+
extends ReadableStream<T>
|
|
14
|
+
{
|
|
15
|
+
constructor(
|
|
16
|
+
stream: ReadableStream<Uint8Array>,
|
|
17
|
+
parse: (x: ServerEvent<string>) => IteratorResult<T, undefined>,
|
|
18
|
+
) {
|
|
19
|
+
const reader = stream.getReader();
|
|
20
|
+
let buffer: Uint8Array = new Uint8Array();
|
|
21
|
+
super({
|
|
22
|
+
async pull(controller) {
|
|
23
|
+
try {
|
|
24
|
+
const r = await reader.read();
|
|
25
|
+
if (r.done) return controller.close();
|
|
26
|
+
buffer = concatBuffer(buffer, r.value);
|
|
27
|
+
for (const { chunk, remainder } of chunks(buffer)) {
|
|
28
|
+
buffer = remainder;
|
|
29
|
+
const item = parseChunk(chunk, parse);
|
|
30
|
+
if (item?.value) controller.enqueue(item.value);
|
|
31
|
+
if (item?.done) {
|
|
32
|
+
await reader.cancel("done");
|
|
33
|
+
return controller.close();
|
|
34
|
+
}
|
|
60
35
|
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
await reader.cancel(e);
|
|
38
|
+
controller.error(e);
|
|
61
39
|
}
|
|
40
|
+
},
|
|
41
|
+
cancel: reason => reader.cancel(reason),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
62
44
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
45
|
+
// Polyfill for older browsers
|
|
46
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T, void, unknown> {
|
|
47
|
+
const fn = (ReadableStream.prototype as any)[Symbol.asyncIterator];
|
|
48
|
+
if (typeof fn === "function") return fn.call(this);
|
|
49
|
+
const reader = this.getReader();
|
|
50
|
+
return {
|
|
51
|
+
next: async () => {
|
|
52
|
+
const r = await reader.read();
|
|
53
|
+
if (r.done) {
|
|
54
|
+
reader.releaseLock();
|
|
55
|
+
return { done: true, value: undefined };
|
|
73
56
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
57
|
+
return { done: false, value: r.value };
|
|
58
|
+
},
|
|
59
|
+
throw: async (e) => {
|
|
60
|
+
await reader.cancel(e);
|
|
61
|
+
reader.releaseLock();
|
|
62
|
+
return { done: true, value: undefined };
|
|
63
|
+
},
|
|
64
|
+
return: async () => {
|
|
65
|
+
await reader.cancel("done");
|
|
66
|
+
reader.releaseLock();
|
|
67
|
+
return { done: true, value: undefined };
|
|
68
|
+
},
|
|
69
|
+
[Symbol.asyncIterator]() {
|
|
70
|
+
return this;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
84
73
|
}
|
|
85
74
|
}
|
|
86
75
|
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
char1 == null
|
|
95
|
-
|| char2 == null
|
|
96
|
-
|| !NEWLINE_CHARS.has(char1)
|
|
97
|
-
|| !NEWLINE_CHARS.has(char2)
|
|
98
|
-
) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
76
|
+
function concatBuffer(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
77
|
+
const c = new Uint8Array(a.length + b.length);
|
|
78
|
+
c.set(a, 0);
|
|
79
|
+
c.set(b, a.length);
|
|
80
|
+
return c;
|
|
81
|
+
}
|
|
101
82
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
83
|
+
/** Finds the first (CR,LF,CR,LF) or (CR,CR) or (LF,LF) */
|
|
84
|
+
function findBoundary(
|
|
85
|
+
buf: Uint8Array,
|
|
86
|
+
): { index: number; length: number } | null {
|
|
87
|
+
const len = buf.length;
|
|
88
|
+
for (let i = 0; i < len; i++) {
|
|
89
|
+
if (
|
|
90
|
+
i <= len - 4
|
|
91
|
+
&& buf[i] === 13 && buf[i + 1] === 10 && buf[i + 2] === 13
|
|
92
|
+
&& buf[i + 3] === 10
|
|
93
|
+
) {
|
|
94
|
+
return { index: i, length: 4 };
|
|
95
|
+
}
|
|
96
|
+
if (i <= len - 2 && buf[i] === 13 && buf[i + 1] === 13) {
|
|
97
|
+
return { index: i, length: 2 };
|
|
98
|
+
}
|
|
99
|
+
if (i <= len - 2 && buf[i] === 10 && buf[i + 1] === 10) {
|
|
100
|
+
return { index: i, length: 2 };
|
|
106
101
|
}
|
|
107
102
|
}
|
|
108
|
-
|
|
109
103
|
return null;
|
|
110
104
|
}
|
|
111
105
|
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
for (let i = 0; i < sequence.length; i++) {
|
|
122
|
-
if (buffer[position + i] !== sequence[i]) {
|
|
123
|
-
return null;
|
|
106
|
+
function* chunks(
|
|
107
|
+
remainder: Uint8Array,
|
|
108
|
+
): Generator<{ chunk: Uint8Array; remainder: Uint8Array }> {
|
|
109
|
+
while (true) {
|
|
110
|
+
const match = findBoundary(remainder);
|
|
111
|
+
if (!match) {
|
|
112
|
+
yield { chunk: new Uint8Array(), remainder };
|
|
113
|
+
return;
|
|
124
114
|
}
|
|
115
|
+
const chunk = remainder.slice(0, match.index);
|
|
116
|
+
remainder = remainder.slice(match.index + match.length);
|
|
117
|
+
yield { chunk, remainder };
|
|
125
118
|
}
|
|
126
|
-
|
|
127
|
-
return sequence;
|
|
128
119
|
}
|
|
129
120
|
|
|
130
|
-
function
|
|
121
|
+
function parseChunk<T extends ServerEvent<unknown>>(
|
|
131
122
|
chunk: Uint8Array,
|
|
132
|
-
|
|
123
|
+
parse: (x: ServerEvent<string>) => IteratorResult<T, undefined>,
|
|
133
124
|
) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const raw = td.decode(chunk);
|
|
140
|
-
const lines = raw.split(/\r?\n|\r/g);
|
|
141
|
-
let publish = false;
|
|
142
|
-
const rawEvent: ServerEvent<string> = {};
|
|
143
|
-
|
|
125
|
+
const text = new TextDecoder().decode(chunk);
|
|
126
|
+
const lines = text.split(/\r\n|\r|\n/);
|
|
127
|
+
const dataLines: string[] = [];
|
|
128
|
+
const ret: ServerEvent<string> = {};
|
|
129
|
+
let ignore = true;
|
|
144
130
|
for (const line of lines) {
|
|
145
|
-
if (!line)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
let value = delim > 0 ? line.substring(delim + 1) : "";
|
|
157
|
-
if (value.charAt(0) === " ") {
|
|
158
|
-
value = value.substring(1);
|
|
131
|
+
if (!line || line.startsWith(":")) continue;
|
|
132
|
+
ignore = false;
|
|
133
|
+
const i = line.indexOf(":");
|
|
134
|
+
const field = line.slice(0, i);
|
|
135
|
+
const value = line[i + 1] === " " ? line.slice(i + 2) : line.slice(i + 1);
|
|
136
|
+
if (field === "data") dataLines.push(value);
|
|
137
|
+
else if (field === "event") ret.event = value;
|
|
138
|
+
else if (field === "id") ret.id = value;
|
|
139
|
+
else if (field === "retry") {
|
|
140
|
+
const n = Number(value);
|
|
141
|
+
if (!isNaN(n)) ret.retry = n;
|
|
159
142
|
}
|
|
160
|
-
|
|
161
|
-
switch (field) {
|
|
162
|
-
case "event": {
|
|
163
|
-
publish = true;
|
|
164
|
-
rawEvent.event = value;
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case "data": {
|
|
168
|
-
publish = true;
|
|
169
|
-
rawEvent.data ??= "";
|
|
170
|
-
rawEvent.data += value + "\n";
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
case "id": {
|
|
174
|
-
publish = true;
|
|
175
|
-
rawEvent.id = value;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
case "retry": {
|
|
179
|
-
const r = parseInt(value, 10);
|
|
180
|
-
if (!Number.isNaN(r)) {
|
|
181
|
-
publish = true;
|
|
182
|
-
rawEvent.retry = r;
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!publish) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (rawEvent.data != null) {
|
|
194
|
-
rawEvent.data = rawEvent.data.slice(0, -1);
|
|
195
143
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export function discardSentinel(
|
|
201
|
-
stream: ReadableStream<Uint8Array>,
|
|
202
|
-
sentinel: string,
|
|
203
|
-
): ReadableStream<Uint8Array> {
|
|
204
|
-
return new ReadableStream<Uint8Array>({
|
|
205
|
-
async start(controller) {
|
|
206
|
-
let buffer = new Uint8Array([]);
|
|
207
|
-
let position = 0;
|
|
208
|
-
let done = false;
|
|
209
|
-
let discard = false;
|
|
210
|
-
const rdr = stream.getReader();
|
|
211
|
-
try {
|
|
212
|
-
while (!done) {
|
|
213
|
-
const result = await rdr.read();
|
|
214
|
-
const value = result.value;
|
|
215
|
-
done = done || result.done;
|
|
216
|
-
// We keep consuming from the source to its completion so it can
|
|
217
|
-
// flush all its contents and release resources.
|
|
218
|
-
if (discard) {
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (typeof value === "undefined") {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const newBuffer = new Uint8Array(buffer.length + value.length);
|
|
226
|
-
newBuffer.set(buffer);
|
|
227
|
-
newBuffer.set(value, buffer.length);
|
|
228
|
-
buffer = newBuffer;
|
|
229
|
-
|
|
230
|
-
for (let i = position; i < buffer.length; i++) {
|
|
231
|
-
const boundary = findBoundary(buffer, i);
|
|
232
|
-
if (boundary == null) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const start = position;
|
|
237
|
-
const chunk = buffer.slice(start, i);
|
|
238
|
-
position = i + boundary.length;
|
|
239
|
-
const event = parseEvent(chunk, id);
|
|
240
|
-
if (event?.data === sentinel) {
|
|
241
|
-
controller.enqueue(buffer.slice(0, start));
|
|
242
|
-
discard = true;
|
|
243
|
-
} else {
|
|
244
|
-
controller.enqueue(buffer.slice(0, position));
|
|
245
|
-
buffer = buffer.slice(position);
|
|
246
|
-
position = 0;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
} catch (e) {
|
|
251
|
-
controller.error(e);
|
|
252
|
-
} finally {
|
|
253
|
-
// If the source stream terminates, flush its contents and terminate.
|
|
254
|
-
// If the sentinel event was found, flush everything up to its start.
|
|
255
|
-
controller.close();
|
|
256
|
-
rdr.releaseLock();
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function id<T>(v: T): T {
|
|
263
|
-
return v;
|
|
144
|
+
if (ignore) return;
|
|
145
|
+
if (dataLines.length) ret.data = dataLines.join("\n");
|
|
146
|
+
return parse(ret);
|
|
264
147
|
}
|
package/src/lib/matchers.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { APIError } from "../models/errors/apierror.js";
|
|
6
6
|
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
7
7
|
import { ERR, OK, Result } from "../types/fp.js";
|
|
8
|
-
import { discardSentinel } from "./event-streams.js";
|
|
9
8
|
import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js";
|
|
10
9
|
import { isPlainObject } from "./is-plain-object.js";
|
|
11
10
|
|
|
@@ -238,9 +237,7 @@ export function match<T, E>(
|
|
|
238
237
|
raw = body;
|
|
239
238
|
break;
|
|
240
239
|
case "sse":
|
|
241
|
-
raw = response.body
|
|
242
|
-
? discardSentinel(response.body, matcher.sseSentinel)
|
|
243
|
-
: response.body;
|
|
240
|
+
raw = response.body;
|
|
244
241
|
break;
|
|
245
242
|
case "nil":
|
|
246
243
|
body = await response.text();
|
package/src/mcp-server/server.ts
CHANGED
|
@@ -81,7 +81,7 @@ import { tool$filesCreate } from "./tools/filesCreate.js";
|
|
|
81
81
|
import { tool$filesDelete } from "./tools/filesDelete.js";
|
|
82
82
|
import { tool$filesGet } from "./tools/filesGet.js";
|
|
83
83
|
import { tool$filesList } from "./tools/filesList.js";
|
|
84
|
-
import { tool$
|
|
84
|
+
import { tool$knowledgeCreate } from "./tools/knowledgeCreate.js";
|
|
85
85
|
import { tool$knowledgeCreateChunks } from "./tools/knowledgeCreateChunks.js";
|
|
86
86
|
import { tool$knowledgeCreateDatasource } from "./tools/knowledgeCreateDatasource.js";
|
|
87
87
|
import { tool$knowledgeDelete } from "./tools/knowledgeDelete.js";
|
|
@@ -119,7 +119,7 @@ export function createMCPServer(deps: {
|
|
|
119
119
|
}) {
|
|
120
120
|
const server = new McpServer({
|
|
121
121
|
name: "Orq",
|
|
122
|
-
version: "3.9.
|
|
122
|
+
version: "3.9.6",
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
const client = new OrqCore({
|
|
@@ -186,6 +186,7 @@ export function createMCPServer(deps: {
|
|
|
186
186
|
tool(tool$datasetsDeleteDatapoint);
|
|
187
187
|
tool(tool$datasetsClear);
|
|
188
188
|
tool(tool$knowledgeList);
|
|
189
|
+
tool(tool$knowledgeCreate);
|
|
189
190
|
tool(tool$knowledgeRetrieve);
|
|
190
191
|
tool(tool$knowledgeUpdate);
|
|
191
192
|
tool(tool$knowledgeDelete);
|
|
@@ -200,7 +201,6 @@ export function createMCPServer(deps: {
|
|
|
200
201
|
tool(tool$knowledgeUpdateChunk);
|
|
201
202
|
tool(tool$knowledgeDeleteChunk);
|
|
202
203
|
tool(tool$knowledgeRetrieveChunk);
|
|
203
|
-
tool(tool$knowledgeBasesChunkText);
|
|
204
204
|
tool(tool$evalsAll);
|
|
205
205
|
tool(tool$evalsCreate);
|
|
206
206
|
tool(tool$evalsUpdate);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { knowledgeCreate } from "../../funcs/knowledgeCreate.js";
|
|
6
|
+
import * as operations from "../../models/operations/index.js";
|
|
7
|
+
import { formatResult, ToolDefinition } from "../tools.js";
|
|
8
|
+
|
|
9
|
+
const args = {
|
|
10
|
+
request: operations.CreateKnowledgeRequestBody$inboundSchema,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const tool$knowledgeCreate: ToolDefinition<typeof args> = {
|
|
14
|
+
name: "knowledge-create",
|
|
15
|
+
description: `Create a knowledge`,
|
|
16
|
+
args,
|
|
17
|
+
tool: async (client, args, ctx) => {
|
|
18
|
+
const [result, apiCall] = await knowledgeCreate(
|
|
19
|
+
client,
|
|
20
|
+
args.request,
|
|
21
|
+
{ fetchOptions: { signal: ctx.signal } },
|
|
22
|
+
).$inspect();
|
|
23
|
+
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
return {
|
|
26
|
+
content: [{ type: "text", text: result.error.message }],
|
|
27
|
+
isError: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const value = result.value;
|
|
32
|
+
|
|
33
|
+
return formatResult(value, apiCall);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -182,7 +182,7 @@ export const CreateContactResponseBody$inboundSchema: z.ZodType<
|
|
|
182
182
|
created: z.string().datetime({ offset: true }).transform(v => new Date(v))
|
|
183
183
|
.optional(),
|
|
184
184
|
updated: z.string().datetime({ offset: true }).default(
|
|
185
|
-
"2025-07-
|
|
185
|
+
"2025-07-09T19:14:34.200Z",
|
|
186
186
|
).transform(v => new Date(v)),
|
|
187
187
|
}).transform((v) => {
|
|
188
188
|
return remap$(v, {
|
|
@@ -223,7 +223,7 @@ export const CreateContactResponseBody$outboundSchema: z.ZodType<
|
|
|
223
223
|
tags: z.array(z.string()).optional(),
|
|
224
224
|
metadata: z.record(z.any()).optional(),
|
|
225
225
|
created: z.date().transform(v => v.toISOString()).optional(),
|
|
226
|
-
updated: z.date().default(() => new Date("2025-07-
|
|
226
|
+
updated: z.date().default(() => new Date("2025-07-09T19:14:34.200Z"))
|
|
227
227
|
.transform(v => v.toISOString()),
|
|
228
228
|
}).transform((v) => {
|
|
229
229
|
return remap$(v, {
|
|
@@ -211,7 +211,7 @@ export const CreateDatasetResponseBody$inboundSchema: z.ZodType<
|
|
|
211
211
|
created: z.string().datetime({ offset: true }).transform(v => new Date(v))
|
|
212
212
|
.optional(),
|
|
213
213
|
updated: z.string().datetime({ offset: true }).default(
|
|
214
|
-
"2025-07-
|
|
214
|
+
"2025-07-09T19:14:34.200Z",
|
|
215
215
|
).transform(v => new Date(v)),
|
|
216
216
|
}).transform((v) => {
|
|
217
217
|
return remap$(v, {
|
|
@@ -251,7 +251,7 @@ export const CreateDatasetResponseBody$outboundSchema: z.ZodType<
|
|
|
251
251
|
updatedById: z.string().optional(),
|
|
252
252
|
metadata: z.lazy(() => CreateDatasetMetadata$outboundSchema),
|
|
253
253
|
created: z.date().transform(v => v.toISOString()).optional(),
|
|
254
|
-
updated: z.date().default(() => new Date("2025-07-
|
|
254
|
+
updated: z.date().default(() => new Date("2025-07-09T19:14:34.200Z"))
|
|
255
255
|
.transform(v => v.toISOString()),
|
|
256
256
|
}).transform((v) => {
|
|
257
257
|
return remap$(v, {
|
|
@@ -5111,7 +5111,7 @@ export const CreateDatasetItemResponseBody$inboundSchema: z.ZodType<
|
|
|
5111
5111
|
created: z.string().datetime({ offset: true }).transform(v => new Date(v))
|
|
5112
5112
|
.optional(),
|
|
5113
5113
|
updated: z.string().datetime({ offset: true }).default(
|
|
5114
|
-
"2025-07-
|
|
5114
|
+
"2025-07-09T19:14:34.200Z",
|
|
5115
5115
|
).transform(v => new Date(v)),
|
|
5116
5116
|
}).transform((v) => {
|
|
5117
5117
|
return remap$(v, {
|
|
@@ -5175,7 +5175,7 @@ export const CreateDatasetItemResponseBody$outboundSchema: z.ZodType<
|
|
|
5175
5175
|
createdById: z.string().optional(),
|
|
5176
5176
|
updatedById: z.string().optional(),
|
|
5177
5177
|
created: z.date().transform(v => v.toISOString()).optional(),
|
|
5178
|
-
updated: z.date().default(() => new Date("2025-07-
|
|
5178
|
+
updated: z.date().default(() => new Date("2025-07-09T19:14:34.200Z"))
|
|
5179
5179
|
.transform(v => v.toISOString()),
|
|
5180
5180
|
}).transform((v) => {
|
|
5181
5181
|
return remap$(v, {
|
|
@@ -751,7 +751,7 @@ export const CreateDatasourceResponseBody$inboundSchema: z.ZodType<
|
|
|
751
751
|
z.ZodTypeDef,
|
|
752
752
|
unknown
|
|
753
753
|
> = z.object({
|
|
754
|
-
_id: z.string().default("
|
|
754
|
+
_id: z.string().default("01JZR9S4ZP9F6NPM8XS0RT7ZSZ"),
|
|
755
755
|
display_name: z.string(),
|
|
756
756
|
description: z.string().optional(),
|
|
757
757
|
status: CreateDatasourceStatus$inboundSchema,
|
|
@@ -795,7 +795,7 @@ export const CreateDatasourceResponseBody$outboundSchema: z.ZodType<
|
|
|
795
795
|
z.ZodTypeDef,
|
|
796
796
|
CreateDatasourceResponseBody
|
|
797
797
|
> = z.object({
|
|
798
|
-
id: z.string().default("
|
|
798
|
+
id: z.string().default("01JZR9S4ZP9F6NPM8XS0RT7ZSZ"),
|
|
799
799
|
displayName: z.string(),
|
|
800
800
|
description: z.string().optional(),
|
|
801
801
|
status: CreateDatasourceStatus$outboundSchema,
|