@opencode-ai/sdk 0.1.0-alpha.1 → 0.1.0-alpha.11
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/CHANGELOG.md +87 -0
- package/LICENSE +198 -4
- package/README.md +20 -6
- package/client.d.mts +15 -56
- package/client.d.mts.map +1 -1
- package/client.d.ts +15 -56
- package/client.d.ts.map +1 -1
- package/client.js +14 -67
- package/client.js.map +1 -1
- package/client.mjs +14 -67
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts +31 -0
- package/core/streaming.d.mts.map +1 -0
- package/core/streaming.d.ts +31 -0
- package/core/streaming.d.ts.map +1 -0
- package/core/streaming.js +257 -0
- package/core/streaming.js.map +1 -0
- package/core/streaming.mjs +252 -0
- package/core/streaming.mjs.map +1 -0
- package/internal/decoders/line.d.mts +17 -0
- package/internal/decoders/line.d.mts.map +1 -0
- package/internal/decoders/line.d.ts +17 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +113 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +108 -0
- package/internal/decoders/line.mjs.map +1 -0
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +10 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +10 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/request-options.d.mts +2 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +2 -0
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/tslib.js +6 -6
- package/internal/types.d.mts +8 -6
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +8 -6
- package/internal/types.d.ts.map +1 -1
- package/internal/uploads.js +1 -1
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +1 -1
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/log.js +1 -1
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +1 -1
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.d.mts.map +1 -1
- package/internal/utils/path.d.ts.map +1 -1
- package/internal/utils/path.js +26 -5
- package/internal/utils/path.js.map +1 -1
- package/internal/utils/path.mjs +26 -5
- package/internal/utils/path.mjs.map +1 -1
- package/package.json +13 -3
- package/resources/app.d.mts +37 -0
- package/resources/app.d.mts.map +1 -0
- package/resources/app.d.ts +37 -0
- package/resources/app.d.ts.map +1 -0
- package/resources/app.js +21 -0
- package/resources/app.js.map +1 -0
- package/resources/app.mjs +17 -0
- package/resources/app.mjs.map +1 -0
- package/resources/config.d.mts +314 -0
- package/resources/config.d.mts.map +1 -0
- package/resources/config.d.ts +314 -0
- package/resources/config.d.ts.map +1 -0
- package/resources/config.js +21 -0
- package/resources/config.js.map +1 -0
- package/resources/config.mjs +17 -0
- package/resources/config.mjs.map +1 -0
- package/resources/event.d.mts +61 -27
- package/resources/event.d.mts.map +1 -1
- package/resources/event.d.ts +61 -27
- package/resources/event.d.ts.map +1 -1
- package/resources/event.js +1 -1
- package/resources/event.js.map +1 -1
- package/resources/event.mjs +1 -1
- package/resources/event.mjs.map +1 -1
- package/resources/file.d.mts +17 -0
- package/resources/file.d.mts.map +1 -0
- package/resources/file.d.ts +17 -0
- package/resources/file.d.ts.map +1 -0
- package/resources/{file-search.js → file.js} +6 -6
- package/resources/file.js.map +1 -0
- package/resources/{file-search.mjs → file.mjs} +4 -4
- package/resources/file.mjs.map +1 -0
- package/resources/index.d.mts +5 -16
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +5 -16
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +11 -33
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +5 -16
- package/resources/index.mjs.map +1 -1
- package/resources/session.d.mts +207 -0
- package/resources/session.d.mts.map +1 -0
- package/resources/session.d.ts +207 -0
- package/resources/session.d.ts.map +1 -0
- package/resources/session.js +70 -0
- package/resources/session.js.map +1 -0
- package/resources/session.mjs +66 -0
- package/resources/session.mjs.map +1 -0
- package/resources/shared.d.mts +20 -0
- package/resources/shared.d.mts.map +1 -0
- package/resources/shared.d.ts +20 -0
- package/resources/shared.d.ts.map +1 -0
- package/resources/shared.js +4 -0
- package/resources/shared.js.map +1 -0
- package/resources/shared.mjs +3 -0
- package/resources/shared.mjs.map +1 -0
- package/src/client.ts +79 -156
- package/src/core/streaming.ts +301 -0
- package/src/internal/decoders/line.ts +135 -0
- package/src/internal/parse.ts +14 -0
- package/src/internal/request-options.ts +2 -0
- package/src/internal/types.ts +9 -6
- package/src/internal/uploads.ts +1 -1
- package/src/internal/utils/log.ts +1 -1
- package/src/internal/utils/path.ts +32 -7
- package/src/resources/app.ts +57 -0
- package/src/resources/config.ts +404 -0
- package/src/resources/event.ts +84 -36
- package/src/resources/file.ts +24 -0
- package/src/resources/index.ts +35 -33
- package/src/resources/session.ts +355 -0
- package/src/resources/shared.ts +27 -0
- package/src/streaming.ts +2 -0
- package/src/version.ts +1 -1
- package/streaming.d.mts +2 -0
- package/streaming.d.mts.map +1 -0
- package/streaming.d.ts +2 -0
- package/streaming.d.ts.map +1 -0
- package/streaming.js +6 -0
- package/streaming.js.map +1 -0
- package/streaming.mjs +2 -0
- package/streaming.mjs.map +1 -0
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/app-info.d.mts +0 -31
- package/resources/app-info.d.mts.map +0 -1
- package/resources/app-info.d.ts +0 -31
- package/resources/app-info.d.ts.map +0 -1
- package/resources/app-info.js +0 -15
- package/resources/app-info.js.map +0 -1
- package/resources/app-info.mjs +0 -11
- package/resources/app-info.mjs.map +0 -1
- package/resources/app-initialize.d.mts +0 -14
- package/resources/app-initialize.d.mts.map +0 -1
- package/resources/app-initialize.d.ts +0 -14
- package/resources/app-initialize.d.ts.map +0 -1
- package/resources/app-initialize.js +0 -15
- package/resources/app-initialize.js.map +0 -1
- package/resources/app-initialize.mjs +0 -11
- package/resources/app-initialize.mjs.map +0 -1
- package/resources/config-get.d.mts +0 -236
- package/resources/config-get.d.mts.map +0 -1
- package/resources/config-get.d.ts +0 -236
- package/resources/config-get.d.ts.map +0 -1
- package/resources/config-get.js +0 -15
- package/resources/config-get.js.map +0 -1
- package/resources/config-get.mjs +0 -11
- package/resources/config-get.mjs.map +0 -1
- package/resources/file-search.d.mts +0 -17
- package/resources/file-search.d.mts.map +0 -1
- package/resources/file-search.d.ts +0 -17
- package/resources/file-search.d.ts.map +0 -1
- package/resources/file-search.js.map +0 -1
- package/resources/file-search.mjs.map +0 -1
- package/resources/installation-info.d.mts +0 -17
- package/resources/installation-info.d.mts.map +0 -1
- package/resources/installation-info.d.ts +0 -17
- package/resources/installation-info.d.ts.map +0 -1
- package/resources/installation-info.js +0 -15
- package/resources/installation-info.js.map +0 -1
- package/resources/installation-info.mjs +0 -11
- package/resources/installation-info.mjs.map +0 -1
- package/resources/path-get.d.mts +0 -19
- package/resources/path-get.d.mts.map +0 -1
- package/resources/path-get.d.ts +0 -19
- package/resources/path-get.d.ts.map +0 -1
- package/resources/path-get.js +0 -15
- package/resources/path-get.js.map +0 -1
- package/resources/path-get.mjs +0 -11
- package/resources/path-get.mjs.map +0 -1
- package/resources/provider-list.d.mts +0 -58
- package/resources/provider-list.d.mts.map +0 -1
- package/resources/provider-list.d.ts +0 -58
- package/resources/provider-list.d.ts.map +0 -1
- package/resources/provider-list.js +0 -15
- package/resources/provider-list.js.map +0 -1
- package/resources/provider-list.mjs +0 -11
- package/resources/provider-list.mjs.map +0 -1
- package/resources/session-abort.d.mts +0 -17
- package/resources/session-abort.d.mts.map +0 -1
- package/resources/session-abort.d.ts +0 -17
- package/resources/session-abort.d.ts.map +0 -1
- package/resources/session-abort.js +0 -15
- package/resources/session-abort.js.map +0 -1
- package/resources/session-abort.mjs +0 -11
- package/resources/session-abort.mjs.map +0 -1
- package/resources/session-chat.d.mts +0 -160
- package/resources/session-chat.d.mts.map +0 -1
- package/resources/session-chat.d.ts +0 -160
- package/resources/session-chat.d.ts.map +0 -1
- package/resources/session-chat.js +0 -15
- package/resources/session-chat.js.map +0 -1
- package/resources/session-chat.mjs +0 -11
- package/resources/session-chat.mjs.map +0 -1
- package/resources/session-create.d.mts +0 -30
- package/resources/session-create.d.mts.map +0 -1
- package/resources/session-create.d.ts +0 -30
- package/resources/session-create.d.ts.map +0 -1
- package/resources/session-create.js +0 -15
- package/resources/session-create.js.map +0 -1
- package/resources/session-create.mjs +0 -11
- package/resources/session-create.mjs.map +0 -1
- package/resources/session-initialize.d.mts +0 -19
- package/resources/session-initialize.d.mts.map +0 -1
- package/resources/session-initialize.d.ts +0 -19
- package/resources/session-initialize.d.ts.map +0 -1
- package/resources/session-initialize.js +0 -15
- package/resources/session-initialize.js.map +0 -1
- package/resources/session-initialize.mjs +0 -11
- package/resources/session-initialize.mjs.map +0 -1
- package/resources/session-list.d.mts +0 -15
- package/resources/session-list.d.mts.map +0 -1
- package/resources/session-list.d.ts +0 -15
- package/resources/session-list.d.ts.map +0 -1
- package/resources/session-list.js +0 -15
- package/resources/session-list.js.map +0 -1
- package/resources/session-list.mjs +0 -11
- package/resources/session-list.mjs.map +0 -1
- package/resources/session-messages.d.mts +0 -18
- package/resources/session-messages.d.mts.map +0 -1
- package/resources/session-messages.d.ts +0 -18
- package/resources/session-messages.d.ts.map +0 -1
- package/resources/session-messages.js +0 -15
- package/resources/session-messages.js.map +0 -1
- package/resources/session-messages.mjs +0 -11
- package/resources/session-messages.mjs.map +0 -1
- package/resources/session-share.d.mts +0 -17
- package/resources/session-share.d.mts.map +0 -1
- package/resources/session-share.d.ts +0 -17
- package/resources/session-share.d.ts.map +0 -1
- package/resources/session-share.js +0 -15
- package/resources/session-share.js.map +0 -1
- package/resources/session-share.mjs +0 -11
- package/resources/session-share.mjs.map +0 -1
- package/resources/session-summarize.d.mts +0 -19
- package/resources/session-summarize.d.mts.map +0 -1
- package/resources/session-summarize.d.ts +0 -19
- package/resources/session-summarize.d.ts.map +0 -1
- package/resources/session-summarize.js +0 -15
- package/resources/session-summarize.js.map +0 -1
- package/resources/session-summarize.mjs +0 -11
- package/resources/session-summarize.mjs.map +0 -1
- package/resources/session-unshare.d.mts +0 -17
- package/resources/session-unshare.d.mts.map +0 -1
- package/resources/session-unshare.d.ts +0 -17
- package/resources/session-unshare.d.ts.map +0 -1
- package/resources/session-unshare.js +0 -15
- package/resources/session-unshare.js.map +0 -1
- package/resources/session-unshare.mjs +0 -11
- package/resources/session-unshare.mjs.map +0 -1
- package/src/resources/app-info.ts +0 -46
- package/src/resources/app-initialize.ts +0 -20
- package/src/resources/config-get.ts +0 -294
- package/src/resources/file-search.ts +0 -27
- package/src/resources/installation-info.ts +0 -24
- package/src/resources/path-get.ts +0 -28
- package/src/resources/provider-list.ts +0 -80
- package/src/resources/session-abort.ts +0 -27
- package/src/resources/session-chat.ts +0 -250
- package/src/resources/session-create.ts +0 -44
- package/src/resources/session-initialize.ts +0 -34
- package/src/resources/session-list.ts +0 -21
- package/src/resources/session-messages.ts +0 -31
- package/src/resources/session-share.ts +0 -23
- package/src/resources/session-summarize.ts +0 -34
- package/src/resources/session-unshare.ts +0 -26
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { concatBytes, decodeUTF8, encodeUTF8 } from '../utils/bytes';
|
|
2
|
+
|
|
3
|
+
export type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
7
|
+
* reading lines from text.
|
|
8
|
+
*
|
|
9
|
+
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
10
|
+
*/
|
|
11
|
+
export class LineDecoder {
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
static NEWLINE_CHARS = new Set(['\n', '\r']);
|
|
14
|
+
static NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
15
|
+
|
|
16
|
+
#buffer: Uint8Array;
|
|
17
|
+
#carriageReturnIndex: number | null;
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.#buffer = new Uint8Array();
|
|
21
|
+
this.#carriageReturnIndex = null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
decode(chunk: Bytes): string[] {
|
|
25
|
+
if (chunk == null) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const binaryChunk =
|
|
30
|
+
chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
31
|
+
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
|
32
|
+
: chunk;
|
|
33
|
+
|
|
34
|
+
this.#buffer = concatBytes([this.#buffer, binaryChunk]);
|
|
35
|
+
|
|
36
|
+
const lines: string[] = [];
|
|
37
|
+
let patternIndex;
|
|
38
|
+
while ((patternIndex = findNewlineIndex(this.#buffer, this.#carriageReturnIndex)) != null) {
|
|
39
|
+
if (patternIndex.carriage && this.#carriageReturnIndex == null) {
|
|
40
|
+
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
|
41
|
+
this.#carriageReturnIndex = patternIndex.index;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// we got double \r or \rtext\n
|
|
46
|
+
if (
|
|
47
|
+
this.#carriageReturnIndex != null &&
|
|
48
|
+
(patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
|
|
49
|
+
) {
|
|
50
|
+
lines.push(decodeUTF8(this.#buffer.subarray(0, this.#carriageReturnIndex - 1)));
|
|
51
|
+
this.#buffer = this.#buffer.subarray(this.#carriageReturnIndex);
|
|
52
|
+
this.#carriageReturnIndex = null;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const endIndex =
|
|
57
|
+
this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
|
58
|
+
|
|
59
|
+
const line = decodeUTF8(this.#buffer.subarray(0, endIndex));
|
|
60
|
+
lines.push(line);
|
|
61
|
+
|
|
62
|
+
this.#buffer = this.#buffer.subarray(patternIndex.index);
|
|
63
|
+
this.#carriageReturnIndex = null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return lines;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
flush(): string[] {
|
|
70
|
+
if (!this.#buffer.length) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
return this.decode('\n');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* This function searches the buffer for the end patterns, (\r or \n)
|
|
79
|
+
* and returns an object with the index preceding the matched newline and the
|
|
80
|
+
* index after the newline char. `null` is returned if no new line is found.
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function findNewlineIndex(
|
|
87
|
+
buffer: Uint8Array,
|
|
88
|
+
startIndex: number | null,
|
|
89
|
+
): { preceding: number; index: number; carriage: boolean } | null {
|
|
90
|
+
const newline = 0x0a; // \n
|
|
91
|
+
const carriage = 0x0d; // \r
|
|
92
|
+
|
|
93
|
+
for (let i = startIndex ?? 0; i < buffer.length; i++) {
|
|
94
|
+
if (buffer[i] === newline) {
|
|
95
|
+
return { preceding: i, index: i + 1, carriage: false };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (buffer[i] === carriage) {
|
|
99
|
+
return { preceding: i, index: i + 1, carriage: true };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function findDoubleNewlineIndex(buffer: Uint8Array): number {
|
|
107
|
+
// This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
|
|
108
|
+
// and returns the index right after the first occurrence of any pattern,
|
|
109
|
+
// or -1 if none of the patterns are found.
|
|
110
|
+
const newline = 0x0a; // \n
|
|
111
|
+
const carriage = 0x0d; // \r
|
|
112
|
+
|
|
113
|
+
for (let i = 0; i < buffer.length - 1; i++) {
|
|
114
|
+
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
|
115
|
+
// \n\n
|
|
116
|
+
return i + 2;
|
|
117
|
+
}
|
|
118
|
+
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
|
119
|
+
// \r\r
|
|
120
|
+
return i + 2;
|
|
121
|
+
}
|
|
122
|
+
if (
|
|
123
|
+
buffer[i] === carriage &&
|
|
124
|
+
buffer[i + 1] === newline &&
|
|
125
|
+
i + 3 < buffer.length &&
|
|
126
|
+
buffer[i + 2] === carriage &&
|
|
127
|
+
buffer[i + 3] === newline
|
|
128
|
+
) {
|
|
129
|
+
// \r\n\r\n
|
|
130
|
+
return i + 4;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
+
import { Stream } from '../core/streaming';
|
|
4
5
|
import { type Opencode } from '../client';
|
|
5
6
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
7
|
|
|
@@ -16,6 +17,19 @@ export type APIResponseProps = {
|
|
|
16
17
|
export async function defaultParseResponse<T>(client: Opencode, props: APIResponseProps): Promise<T> {
|
|
17
18
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
19
|
const body = await (async () => {
|
|
20
|
+
if (props.options.stream) {
|
|
21
|
+
loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
|
|
22
|
+
|
|
23
|
+
// Note: there is an invariant here that isn't represented in the type system
|
|
24
|
+
// that if you set `stream: true` the response type must also be `Stream<T>`
|
|
25
|
+
|
|
26
|
+
if (props.options.__streamClass) {
|
|
27
|
+
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Stream.fromSSEResponse(response, props.controller) as any;
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
// fetch refuses to read the body when the status code is 204.
|
|
20
34
|
if (response.status === 204) {
|
|
21
35
|
return null as T;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { NullableHeaders } from './headers';
|
|
4
4
|
|
|
5
5
|
import type { BodyInit } from './builtin-types';
|
|
6
|
+
import { Stream } from '../core/streaming';
|
|
6
7
|
import type { HTTPMethod, MergedRequestInit } from './types';
|
|
7
8
|
import { type HeadersLike } from './headers';
|
|
8
9
|
|
|
@@ -23,6 +24,7 @@ export type RequestOptions = {
|
|
|
23
24
|
defaultBaseURL?: string | undefined;
|
|
24
25
|
|
|
25
26
|
__binaryResponse?: boolean | undefined;
|
|
27
|
+
__streamClass?: typeof Stream;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export type EncodedContent = { bodyHeaders: HeadersLike; body: BodyInit };
|
package/src/internal/types.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
|
|
7
7
|
|
|
8
8
|
export type FinalizedRequestInit = RequestInit & { headers: Headers };
|
|
9
9
|
|
|
10
|
-
type NotAny<T> = [
|
|
10
|
+
type NotAny<T> = [0] extends [1 & T] ? never : T;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
|
@@ -64,13 +64,15 @@ type OverloadedParameters<T> =
|
|
|
64
64
|
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
65
65
|
*/
|
|
66
66
|
/** @ts-ignore For users with \@types/node */
|
|
67
|
-
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
|
|
67
|
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
|
|
68
68
|
/** @ts-ignore For users with undici */
|
|
69
|
-
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
|
|
69
|
+
type UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;
|
|
70
70
|
/** @ts-ignore For users with \@types/bun */
|
|
71
71
|
type BunRequestInit = globalThis.FetchRequestInit;
|
|
72
|
-
/** @ts-ignore For users with node-fetch */
|
|
73
|
-
type
|
|
72
|
+
/** @ts-ignore For users with node-fetch@2 */
|
|
73
|
+
type NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;
|
|
74
|
+
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */
|
|
75
|
+
type NodeFetch3RequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
|
74
76
|
/** @ts-ignore For users who use Deno */
|
|
75
77
|
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
76
78
|
/* eslint-enable */
|
|
@@ -79,7 +81,8 @@ type RequestInits =
|
|
|
79
81
|
| NotAny<UndiciTypesRequestInit>
|
|
80
82
|
| NotAny<UndiciRequestInit>
|
|
81
83
|
| NotAny<BunRequestInit>
|
|
82
|
-
| NotAny<
|
|
84
|
+
| NotAny<NodeFetch2RequestInit>
|
|
85
|
+
| NotAny<NodeFetch3RequestInit>
|
|
83
86
|
| NotAny<RequestInit>
|
|
84
87
|
| NotAny<FetchRequestInit>;
|
|
85
88
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
|
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const supportsFormDataMap =
|
|
93
|
+
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
@@ -58,7 +58,7 @@ const noopLogger = {
|
|
|
58
58
|
debug: noop,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
let cachedLoggers =
|
|
61
|
+
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
63
|
export function loggerFor(client: Opencode): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
@@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
|
|
|
12
12
|
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16
|
+
|
|
15
17
|
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
16
18
|
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
17
19
|
// If there are no params, no processing is needed.
|
|
18
20
|
if (statics.length === 1) return statics[0]!;
|
|
19
21
|
|
|
20
22
|
let postPath = false;
|
|
23
|
+
const invalidSegments = [];
|
|
21
24
|
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
22
25
|
if (/[?#]/.test(currentValue)) {
|
|
23
26
|
postPath = true;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const value = params[index];
|
|
29
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
30
|
+
if (
|
|
31
|
+
index !== params.length &&
|
|
32
|
+
(value == null ||
|
|
33
|
+
(typeof value === 'object' &&
|
|
34
|
+
// handle values from other realms
|
|
35
|
+
value.toString ===
|
|
36
|
+
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
|
37
|
+
?.toString))
|
|
38
|
+
) {
|
|
39
|
+
encoded = value + '';
|
|
40
|
+
invalidSegments.push({
|
|
41
|
+
start: previousValue.length + currentValue.length,
|
|
42
|
+
length: encoded.length,
|
|
43
|
+
error: `Value of type ${Object.prototype.toString
|
|
44
|
+
.call(value)
|
|
45
|
+
.slice(8, -1)} is not a valid path parameter`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
30
49
|
}, '');
|
|
31
50
|
|
|
32
51
|
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
33
|
-
const invalidSegments = [];
|
|
34
52
|
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
35
53
|
let match;
|
|
36
54
|
|
|
@@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
39
57
|
invalidSegments.push({
|
|
40
58
|
start: match.index,
|
|
41
59
|
length: match[0].length,
|
|
60
|
+
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
|
42
61
|
});
|
|
43
62
|
}
|
|
44
63
|
|
|
64
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
65
|
+
|
|
45
66
|
if (invalidSegments.length > 0) {
|
|
46
67
|
let lastEnd = 0;
|
|
47
68
|
const underline = invalidSegments.reduce((acc, segment) => {
|
|
@@ -51,7 +72,11 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
51
72
|
return acc + spaces + arrows;
|
|
52
73
|
}, '');
|
|
53
74
|
|
|
54
|
-
throw new OpencodeError(
|
|
75
|
+
throw new OpencodeError(
|
|
76
|
+
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
|
+
.map((e) => e.error)
|
|
78
|
+
.join('\n')}\n${path}\n${underline}`,
|
|
79
|
+
);
|
|
55
80
|
}
|
|
56
81
|
|
|
57
82
|
return path;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import { APIPromise } from '../core/api-promise';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options';
|
|
6
|
+
|
|
7
|
+
export class AppResource extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* Get app info
|
|
10
|
+
*/
|
|
11
|
+
get(options?: RequestOptions): APIPromise<App> {
|
|
12
|
+
return this._client.get('/app', options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the app
|
|
17
|
+
*/
|
|
18
|
+
init(options?: RequestOptions): APIPromise<AppInitResponse> {
|
|
19
|
+
return this._client.post('/app/init', options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface App {
|
|
24
|
+
git: boolean;
|
|
25
|
+
|
|
26
|
+
hostname: string;
|
|
27
|
+
|
|
28
|
+
path: App.Path;
|
|
29
|
+
|
|
30
|
+
time: App.Time;
|
|
31
|
+
|
|
32
|
+
user: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export namespace App {
|
|
36
|
+
export interface Path {
|
|
37
|
+
config: string;
|
|
38
|
+
|
|
39
|
+
cwd: string;
|
|
40
|
+
|
|
41
|
+
data: string;
|
|
42
|
+
|
|
43
|
+
root: string;
|
|
44
|
+
|
|
45
|
+
state: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Time {
|
|
49
|
+
initialized?: number;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type AppInitResponse = boolean;
|
|
54
|
+
|
|
55
|
+
export declare namespace AppResource {
|
|
56
|
+
export { type App as App, type AppInitResponse as AppInitResponse };
|
|
57
|
+
}
|