@orq-ai/node 3.1.6 → 3.1.8
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/jsr.json +1 -1
- package/lib/config.d.ts +3 -3
- package/lib/config.js +3 -3
- package/models/operations/createcontact.js +2 -2
- package/models/operations/fileget.js +2 -2
- package/models/operations/filelist.js +2 -2
- package/models/operations/fileupload.js +2 -2
- package/package.json +1 -1
- package/packages/orq-rc/README.md +8 -61
- package/packages/orq-rc/docs/sdks/deployments/README.md +0 -81
- package/packages/orq-rc/docs/sdks/files/README.md +8 -8
- package/packages/orq-rc/docs/sdks/{remoteconfig → remoteconfigs}/README.md +8 -8
- package/packages/orq-rc/jsr.json +1 -2
- package/packages/orq-rc/package-lock.json +2 -2
- package/packages/orq-rc/package.json +1 -1
- package/packages/orq-rc/src/funcs/contactsCreate.ts +1 -0
- package/packages/orq-rc/src/funcs/deploymentsGetConfig.ts +1 -0
- package/packages/orq-rc/src/funcs/deploymentsInvoke.ts +1 -0
- package/packages/orq-rc/src/funcs/deploymentsList.ts +1 -0
- package/packages/orq-rc/src/funcs/deploymentsMetricsCreate.ts +1 -0
- package/packages/orq-rc/src/funcs/feedbackCreate.ts +1 -0
- package/packages/orq-rc/src/funcs/{filesUpload.ts → filesCreate.ts} +3 -2
- package/packages/orq-rc/src/funcs/filesDelete.ts +1 -0
- package/packages/orq-rc/src/funcs/filesGet.ts +5 -1
- package/packages/orq-rc/src/funcs/filesList.ts +6 -3
- package/packages/orq-rc/src/funcs/promptsCreate.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsDelete.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsGetVersion.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsList.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsListVersions.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsRetrieve.ts +1 -0
- package/packages/orq-rc/src/funcs/promptsUpdate.ts +1 -0
- package/packages/orq-rc/src/funcs/{remoteconfigGetConfig.ts → remoteconfigsRetrieve.ts} +3 -2
- package/packages/orq-rc/src/hooks/types.ts +1 -0
- package/packages/orq-rc/src/lib/config.ts +3 -3
- package/packages/orq-rc/src/lib/matchers.ts +1 -4
- package/packages/orq-rc/src/lib/security.ts +0 -1
- package/packages/orq-rc/src/models/errors/index.ts +0 -1
- package/packages/orq-rc/src/models/operations/createcontact.ts +2 -2
- package/packages/orq-rc/src/models/operations/createprompt.ts +668 -770
- package/packages/orq-rc/src/models/operations/fileget.ts +2 -2
- package/packages/orq-rc/src/models/operations/filelist.ts +31 -16
- package/packages/orq-rc/src/models/operations/fileupload.ts +2 -2
- package/packages/orq-rc/src/models/operations/index.ts +0 -7
- package/packages/orq-rc/src/models/operations/updateprompt.ts +64 -81
- package/packages/orq-rc/src/sdk/deployments.ts +0 -19
- package/packages/orq-rc/src/sdk/files.ts +11 -5
- package/packages/orq-rc/src/sdk/{remoteconfig.ts → remoteconfigs.ts} +5 -5
- package/packages/orq-rc/src/sdk/sdk.ts +4 -10
- package/src/lib/config.ts +3 -3
- package/src/models/operations/createcontact.ts +2 -2
- 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/packages/orq-rc/docs/sdks/promptsnippets/README.md +0 -534
- package/packages/orq-rc/src/funcs/deploymentsStream.ts +0 -150
- package/packages/orq-rc/src/funcs/promptSnippetsCreate.ts +0 -128
- package/packages/orq-rc/src/funcs/promptSnippetsDelete.ts +0 -131
- package/packages/orq-rc/src/funcs/promptSnippetsGet.ts +0 -130
- package/packages/orq-rc/src/funcs/promptSnippetsGetByKey.ts +0 -132
- package/packages/orq-rc/src/funcs/promptSnippetsList.ts +0 -132
- package/packages/orq-rc/src/funcs/promptSnippetsUpdate.ts +0 -139
- package/packages/orq-rc/src/lib/event-streams.ts +0 -264
- package/packages/orq-rc/src/models/errors/updatepromptsnippet.ts +0 -71
- package/packages/orq-rc/src/models/operations/createpromptsnippet.ts +0 -6239
- package/packages/orq-rc/src/models/operations/deletepromptsnippet.ts +0 -69
- package/packages/orq-rc/src/models/operations/deploymentstream.ts +0 -3062
- package/packages/orq-rc/src/models/operations/findonebykeypromptsnippet.ts +0 -4483
- package/packages/orq-rc/src/models/operations/findonepromptsnippet.ts +0 -4343
- package/packages/orq-rc/src/models/operations/getallpromptsnippets.ts +0 -4472
- package/packages/orq-rc/src/models/operations/updatepromptsnippet.ts +0 -6544
- package/packages/orq-rc/src/sdk/promptsnippets.ts +0 -99
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OrqCore } from "../core.js";
|
|
6
|
-
import { encodeFormQuery } from "../lib/encodings.js";
|
|
7
|
-
import * as M from "../lib/matchers.js";
|
|
8
|
-
import { compactMap } from "../lib/primitives.js";
|
|
9
|
-
import { safeParse } from "../lib/schemas.js";
|
|
10
|
-
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
-
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
12
|
-
import { pathToFunc } from "../lib/url.js";
|
|
13
|
-
import { APIError } from "../models/errors/apierror.js";
|
|
14
|
-
import {
|
|
15
|
-
ConnectionError,
|
|
16
|
-
InvalidRequestError,
|
|
17
|
-
RequestAbortedError,
|
|
18
|
-
RequestTimeoutError,
|
|
19
|
-
UnexpectedClientError,
|
|
20
|
-
} from "../models/errors/httpclienterrors.js";
|
|
21
|
-
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
22
|
-
import * as operations from "../models/operations/index.js";
|
|
23
|
-
import { Result } from "../types/fp.js";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* List all prompts snippets
|
|
27
|
-
*/
|
|
28
|
-
export async function promptSnippetsList(
|
|
29
|
-
client: OrqCore,
|
|
30
|
-
request?: operations.GetAllPromptSnippetsRequest | undefined,
|
|
31
|
-
options?: RequestOptions,
|
|
32
|
-
): Promise<
|
|
33
|
-
Result<
|
|
34
|
-
operations.GetAllPromptSnippetsResponseBody,
|
|
35
|
-
| APIError
|
|
36
|
-
| SDKValidationError
|
|
37
|
-
| UnexpectedClientError
|
|
38
|
-
| InvalidRequestError
|
|
39
|
-
| RequestAbortedError
|
|
40
|
-
| RequestTimeoutError
|
|
41
|
-
| ConnectionError
|
|
42
|
-
>
|
|
43
|
-
> {
|
|
44
|
-
const parsed = safeParse(
|
|
45
|
-
request,
|
|
46
|
-
(value) =>
|
|
47
|
-
operations.GetAllPromptSnippetsRequest$outboundSchema.optional().parse(
|
|
48
|
-
value,
|
|
49
|
-
),
|
|
50
|
-
"Input validation failed",
|
|
51
|
-
);
|
|
52
|
-
if (!parsed.ok) {
|
|
53
|
-
return parsed;
|
|
54
|
-
}
|
|
55
|
-
const payload = parsed.value;
|
|
56
|
-
const body = null;
|
|
57
|
-
|
|
58
|
-
const path = pathToFunc("/v2/resources/prompts/snippets/")();
|
|
59
|
-
|
|
60
|
-
const query = encodeFormQuery({
|
|
61
|
-
"ending_before": payload?.ending_before,
|
|
62
|
-
"limit": payload?.limit,
|
|
63
|
-
"starting_after": payload?.starting_after,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const headers = new Headers(compactMap({
|
|
67
|
-
Accept: "application/json",
|
|
68
|
-
}));
|
|
69
|
-
|
|
70
|
-
const secConfig = await extractSecurity(client._options.apiKey);
|
|
71
|
-
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
72
|
-
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
73
|
-
|
|
74
|
-
const context = {
|
|
75
|
-
operationID: "GetAllPromptSnippets",
|
|
76
|
-
oAuth2Scopes: [],
|
|
77
|
-
|
|
78
|
-
resolvedSecurity: requestSecurity,
|
|
79
|
-
|
|
80
|
-
securitySource: client._options.apiKey,
|
|
81
|
-
retryConfig: options?.retries
|
|
82
|
-
|| client._options.retryConfig
|
|
83
|
-
|| { strategy: "none" },
|
|
84
|
-
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const requestRes = client._createRequest(context, {
|
|
88
|
-
security: requestSecurity,
|
|
89
|
-
method: "GET",
|
|
90
|
-
baseURL: options?.serverURL,
|
|
91
|
-
path: path,
|
|
92
|
-
headers: headers,
|
|
93
|
-
query: query,
|
|
94
|
-
body: body,
|
|
95
|
-
timeoutMs: options?.timeoutMs || client._options.timeoutMs || 600000,
|
|
96
|
-
}, options);
|
|
97
|
-
if (!requestRes.ok) {
|
|
98
|
-
return requestRes;
|
|
99
|
-
}
|
|
100
|
-
const req = requestRes.value;
|
|
101
|
-
|
|
102
|
-
const doResult = await client._do(req, {
|
|
103
|
-
context,
|
|
104
|
-
errorCodes: ["4XX", "5XX"],
|
|
105
|
-
retryConfig: context.retryConfig,
|
|
106
|
-
retryCodes: context.retryCodes,
|
|
107
|
-
});
|
|
108
|
-
if (!doResult.ok) {
|
|
109
|
-
return doResult;
|
|
110
|
-
}
|
|
111
|
-
const response = doResult.value;
|
|
112
|
-
|
|
113
|
-
const [result] = await M.match<
|
|
114
|
-
operations.GetAllPromptSnippetsResponseBody,
|
|
115
|
-
| APIError
|
|
116
|
-
| SDKValidationError
|
|
117
|
-
| UnexpectedClientError
|
|
118
|
-
| InvalidRequestError
|
|
119
|
-
| RequestAbortedError
|
|
120
|
-
| RequestTimeoutError
|
|
121
|
-
| ConnectionError
|
|
122
|
-
>(
|
|
123
|
-
M.json(200, operations.GetAllPromptSnippetsResponseBody$inboundSchema),
|
|
124
|
-
M.fail("4XX"),
|
|
125
|
-
M.fail("5XX"),
|
|
126
|
-
)(response);
|
|
127
|
-
if (!result.ok) {
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { OrqCore } from "../core.js";
|
|
6
|
-
import { encodeJSON, encodeSimple } from "../lib/encodings.js";
|
|
7
|
-
import * as M from "../lib/matchers.js";
|
|
8
|
-
import { compactMap } from "../lib/primitives.js";
|
|
9
|
-
import { safeParse } from "../lib/schemas.js";
|
|
10
|
-
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
-
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
12
|
-
import { pathToFunc } from "../lib/url.js";
|
|
13
|
-
import { APIError } from "../models/errors/apierror.js";
|
|
14
|
-
import {
|
|
15
|
-
ConnectionError,
|
|
16
|
-
InvalidRequestError,
|
|
17
|
-
RequestAbortedError,
|
|
18
|
-
RequestTimeoutError,
|
|
19
|
-
UnexpectedClientError,
|
|
20
|
-
} from "../models/errors/httpclienterrors.js";
|
|
21
|
-
import * as errors from "../models/errors/index.js";
|
|
22
|
-
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
23
|
-
import * as operations from "../models/operations/index.js";
|
|
24
|
-
import { Result } from "../types/fp.js";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Update a prompt snippet
|
|
28
|
-
*/
|
|
29
|
-
export async function promptSnippetsUpdate(
|
|
30
|
-
client: OrqCore,
|
|
31
|
-
request: operations.UpdatePromptSnippetRequest,
|
|
32
|
-
options?: RequestOptions,
|
|
33
|
-
): Promise<
|
|
34
|
-
Result<
|
|
35
|
-
operations.UpdatePromptSnippetResponseBody,
|
|
36
|
-
| errors.UpdatePromptSnippetResponseBody
|
|
37
|
-
| APIError
|
|
38
|
-
| SDKValidationError
|
|
39
|
-
| UnexpectedClientError
|
|
40
|
-
| InvalidRequestError
|
|
41
|
-
| RequestAbortedError
|
|
42
|
-
| RequestTimeoutError
|
|
43
|
-
| ConnectionError
|
|
44
|
-
>
|
|
45
|
-
> {
|
|
46
|
-
const parsed = safeParse(
|
|
47
|
-
request,
|
|
48
|
-
(value) =>
|
|
49
|
-
operations.UpdatePromptSnippetRequest$outboundSchema.parse(value),
|
|
50
|
-
"Input validation failed",
|
|
51
|
-
);
|
|
52
|
-
if (!parsed.ok) {
|
|
53
|
-
return parsed;
|
|
54
|
-
}
|
|
55
|
-
const payload = parsed.value;
|
|
56
|
-
const body = encodeJSON("body", payload.RequestBody, { explode: true });
|
|
57
|
-
|
|
58
|
-
const pathParams = {
|
|
59
|
-
id: encodeSimple("id", payload.id, {
|
|
60
|
-
explode: false,
|
|
61
|
-
charEncoding: "percent",
|
|
62
|
-
}),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const path = pathToFunc("/v2/resources/prompts/snippets/{id}")(pathParams);
|
|
66
|
-
|
|
67
|
-
const headers = new Headers(compactMap({
|
|
68
|
-
"Content-Type": "application/json",
|
|
69
|
-
Accept: "application/json",
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
const secConfig = await extractSecurity(client._options.apiKey);
|
|
73
|
-
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
74
|
-
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
75
|
-
|
|
76
|
-
const context = {
|
|
77
|
-
operationID: "UpdatePromptSnippet",
|
|
78
|
-
oAuth2Scopes: [],
|
|
79
|
-
|
|
80
|
-
resolvedSecurity: requestSecurity,
|
|
81
|
-
|
|
82
|
-
securitySource: client._options.apiKey,
|
|
83
|
-
retryConfig: options?.retries
|
|
84
|
-
|| client._options.retryConfig
|
|
85
|
-
|| { strategy: "none" },
|
|
86
|
-
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const requestRes = client._createRequest(context, {
|
|
90
|
-
security: requestSecurity,
|
|
91
|
-
method: "PATCH",
|
|
92
|
-
baseURL: options?.serverURL,
|
|
93
|
-
path: path,
|
|
94
|
-
headers: headers,
|
|
95
|
-
body: body,
|
|
96
|
-
timeoutMs: options?.timeoutMs || client._options.timeoutMs || 600000,
|
|
97
|
-
}, options);
|
|
98
|
-
if (!requestRes.ok) {
|
|
99
|
-
return requestRes;
|
|
100
|
-
}
|
|
101
|
-
const req = requestRes.value;
|
|
102
|
-
|
|
103
|
-
const doResult = await client._do(req, {
|
|
104
|
-
context,
|
|
105
|
-
errorCodes: ["404", "4XX", "5XX"],
|
|
106
|
-
retryConfig: context.retryConfig,
|
|
107
|
-
retryCodes: context.retryCodes,
|
|
108
|
-
});
|
|
109
|
-
if (!doResult.ok) {
|
|
110
|
-
return doResult;
|
|
111
|
-
}
|
|
112
|
-
const response = doResult.value;
|
|
113
|
-
|
|
114
|
-
const responseFields = {
|
|
115
|
-
HttpMeta: { Response: response, Request: req },
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const [result] = await M.match<
|
|
119
|
-
operations.UpdatePromptSnippetResponseBody,
|
|
120
|
-
| errors.UpdatePromptSnippetResponseBody
|
|
121
|
-
| APIError
|
|
122
|
-
| SDKValidationError
|
|
123
|
-
| UnexpectedClientError
|
|
124
|
-
| InvalidRequestError
|
|
125
|
-
| RequestAbortedError
|
|
126
|
-
| RequestTimeoutError
|
|
127
|
-
| ConnectionError
|
|
128
|
-
>(
|
|
129
|
-
M.json(200, operations.UpdatePromptSnippetResponseBody$inboundSchema),
|
|
130
|
-
M.jsonErr(404, errors.UpdatePromptSnippetResponseBody$inboundSchema),
|
|
131
|
-
M.fail("4XX"),
|
|
132
|
-
M.fail("5XX"),
|
|
133
|
-
)(response, { extraFields: responseFields });
|
|
134
|
-
if (!result.ok) {
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type ServerEvent<T> = {
|
|
6
|
-
data?: T | undefined;
|
|
7
|
-
event?: string | undefined;
|
|
8
|
-
retry?: number | undefined;
|
|
9
|
-
id?: string | undefined;
|
|
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
|
-
|
|
55
|
-
const chunk = buffer.slice(position, i);
|
|
56
|
-
position = i + boundary.length;
|
|
57
|
-
const event = parseEvent(chunk, this.decoder);
|
|
58
|
-
if (event != null) {
|
|
59
|
-
yield event;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (position > 0) {
|
|
64
|
-
buffer = buffer.slice(position);
|
|
65
|
-
position = 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (buffer.length > 0) {
|
|
70
|
-
const event = parseEvent(buffer, this.decoder);
|
|
71
|
-
if (event != null) {
|
|
72
|
-
yield event;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} catch (e: unknown) {
|
|
76
|
-
if (e instanceof Error && e.name === "AbortError") {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
throw e;
|
|
81
|
-
} finally {
|
|
82
|
-
reader.releaseLock();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function findBoundary(buffer: Uint8Array, start: number): Uint8Array | null {
|
|
88
|
-
const char1 = buffer[start];
|
|
89
|
-
const char2 = buffer[start + 1];
|
|
90
|
-
|
|
91
|
-
// Don't bother checking if the first two characters are not new line
|
|
92
|
-
// characters.
|
|
93
|
-
if (
|
|
94
|
-
char1 == null
|
|
95
|
-
|| char2 == null
|
|
96
|
-
|| !NEWLINE_CHARS.has(char1)
|
|
97
|
-
|| !NEWLINE_CHARS.has(char2)
|
|
98
|
-
) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (const s of MESSAGE_BOUNDARIES) {
|
|
103
|
-
const seq = peekSequence(start, buffer, s);
|
|
104
|
-
if (seq != null) {
|
|
105
|
-
return seq;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function peekSequence(
|
|
113
|
-
position: number,
|
|
114
|
-
buffer: Uint8Array,
|
|
115
|
-
sequence: Uint8Array,
|
|
116
|
-
): Uint8Array | null {
|
|
117
|
-
if (sequence.length > buffer.length - position) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
for (let i = 0; i < sequence.length; i++) {
|
|
122
|
-
if (buffer[position + i] !== sequence[i]) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return sequence;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function parseEvent<Event extends ServerEvent<unknown>>(
|
|
131
|
-
chunk: Uint8Array,
|
|
132
|
-
decoder: (rawEvent: ServerEvent<string>) => Event,
|
|
133
|
-
) {
|
|
134
|
-
if (!chunk.length) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const td = new TextDecoder();
|
|
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
|
-
|
|
144
|
-
for (const line of lines) {
|
|
145
|
-
if (!line) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const delim = line.indexOf(":");
|
|
150
|
-
// Lines starting with a colon are ignored.
|
|
151
|
-
if (delim === 0) {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const field = delim > 0 ? line.substring(0, delim) : "";
|
|
156
|
-
let value = delim > 0 ? line.substring(delim + 1) : "";
|
|
157
|
-
if (value.charAt(0) === " ") {
|
|
158
|
-
value = value.substring(1);
|
|
159
|
-
}
|
|
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
|
-
}
|
|
196
|
-
|
|
197
|
-
return decoder(rawEvent);
|
|
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;
|
|
264
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as z from "zod";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Prompt snippet not found.
|
|
9
|
-
*/
|
|
10
|
-
export type UpdatePromptSnippetResponseBodyData = {
|
|
11
|
-
message: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Prompt snippet not found.
|
|
16
|
-
*/
|
|
17
|
-
export class UpdatePromptSnippetResponseBody extends Error {
|
|
18
|
-
/** The original data that was passed to this error instance. */
|
|
19
|
-
data$: UpdatePromptSnippetResponseBodyData;
|
|
20
|
-
|
|
21
|
-
constructor(err: UpdatePromptSnippetResponseBodyData) {
|
|
22
|
-
const message = "message" in err && typeof err.message === "string"
|
|
23
|
-
? err.message
|
|
24
|
-
: `API error occurred: ${JSON.stringify(err)}`;
|
|
25
|
-
super(message);
|
|
26
|
-
this.data$ = err;
|
|
27
|
-
|
|
28
|
-
this.name = "UpdatePromptSnippetResponseBody";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @internal */
|
|
33
|
-
export const UpdatePromptSnippetResponseBody$inboundSchema: z.ZodType<
|
|
34
|
-
UpdatePromptSnippetResponseBody,
|
|
35
|
-
z.ZodTypeDef,
|
|
36
|
-
unknown
|
|
37
|
-
> = z.object({
|
|
38
|
-
message: z.string(),
|
|
39
|
-
})
|
|
40
|
-
.transform((v) => {
|
|
41
|
-
return new UpdatePromptSnippetResponseBody(v);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
/** @internal */
|
|
45
|
-
export type UpdatePromptSnippetResponseBody$Outbound = {
|
|
46
|
-
message: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/** @internal */
|
|
50
|
-
export const UpdatePromptSnippetResponseBody$outboundSchema: z.ZodType<
|
|
51
|
-
UpdatePromptSnippetResponseBody$Outbound,
|
|
52
|
-
z.ZodTypeDef,
|
|
53
|
-
UpdatePromptSnippetResponseBody
|
|
54
|
-
> = z.instanceof(UpdatePromptSnippetResponseBody)
|
|
55
|
-
.transform(v => v.data$)
|
|
56
|
-
.pipe(z.object({
|
|
57
|
-
message: z.string(),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @internal
|
|
62
|
-
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
|
|
63
|
-
*/
|
|
64
|
-
export namespace UpdatePromptSnippetResponseBody$ {
|
|
65
|
-
/** @deprecated use `UpdatePromptSnippetResponseBody$inboundSchema` instead. */
|
|
66
|
-
export const inboundSchema = UpdatePromptSnippetResponseBody$inboundSchema;
|
|
67
|
-
/** @deprecated use `UpdatePromptSnippetResponseBody$outboundSchema` instead. */
|
|
68
|
-
export const outboundSchema = UpdatePromptSnippetResponseBody$outboundSchema;
|
|
69
|
-
/** @deprecated use `UpdatePromptSnippetResponseBody$Outbound` instead. */
|
|
70
|
-
export type Outbound = UpdatePromptSnippetResponseBody$Outbound;
|
|
71
|
-
}
|