@opencode-ai/sdk 0.1.0-alpha.14 → 0.1.0-alpha.16
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 +26 -0
- package/client.d.mts +17 -14
- package/client.d.mts.map +1 -1
- package/client.d.ts +17 -14
- package/client.d.ts.map +1 -1
- package/client.js +12 -9
- package/client.js.map +1 -1
- package/client.mjs +14 -11
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts +5 -3
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts +5 -3
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +16 -10
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +16 -10
- package/core/streaming.mjs.map +1 -1
- package/internal/parse.js +2 -2
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +2 -2
- package/internal/parse.mjs.map +1 -1
- package/internal/request-options.d.mts +42 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +42 -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/package.json +1 -1
- package/resources/app.d.mts +49 -2
- package/resources/app.d.mts.map +1 -1
- package/resources/app.d.ts +49 -2
- package/resources/app.d.ts.map +1 -1
- package/resources/app.js +12 -0
- package/resources/app.js.map +1 -1
- package/resources/app.mjs +12 -0
- package/resources/app.mjs.map +1 -1
- package/resources/config.d.mts +120 -34
- package/resources/config.d.mts.map +1 -1
- package/resources/config.d.ts +120 -34
- package/resources/config.d.ts.map +1 -1
- package/resources/config.js.map +1 -1
- package/resources/config.mjs.map +1 -1
- package/resources/event.d.mts +14 -15
- package/resources/event.d.mts.map +1 -1
- package/resources/event.d.ts +14 -15
- package/resources/event.d.ts.map +1 -1
- package/resources/file.d.mts +10 -12
- package/resources/file.d.mts.map +1 -1
- package/resources/file.d.ts +10 -12
- package/resources/file.d.ts.map +1 -1
- package/resources/file.js +3 -3
- package/resources/file.js.map +1 -1
- package/resources/file.mjs +1 -1
- package/resources/file.mjs.map +1 -1
- package/resources/find.d.mts +48 -23
- package/resources/find.d.mts.map +1 -1
- package/resources/find.d.ts +48 -23
- package/resources/find.d.ts.map +1 -1
- package/resources/index.d.mts +4 -4
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +4 -4
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +2 -2
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/resources/session.d.mts +169 -110
- package/resources/session.d.mts.map +1 -1
- package/resources/session.d.ts +169 -110
- package/resources/session.d.ts.map +1 -1
- package/resources/session.js.map +1 -1
- package/resources/session.mjs.map +1 -1
- package/resources/shared.d.mts +4 -0
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +4 -0
- package/resources/shared.d.ts.map +1 -1
- package/src/client.ts +65 -32
- package/src/core/streaming.ts +22 -8
- package/src/internal/parse.ts +2 -2
- package/src/internal/request-options.ts +53 -0
- package/src/resources/app.ts +72 -3
- package/src/resources/config.ts +139 -34
- package/src/resources/event.ts +21 -19
- package/src/resources/file.ts +14 -15
- package/src/resources/find.ts +60 -22
- package/src/resources/index.ts +28 -9
- package/src/resources/session.ts +211 -122
- package/src/resources/shared.ts +6 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -16,7 +16,16 @@ import * as Errors from './core/error';
|
|
|
16
16
|
import * as Uploads from './core/uploads';
|
|
17
17
|
import * as API from './resources/index';
|
|
18
18
|
import { APIPromise } from './core/api-promise';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
App,
|
|
21
|
+
AppInitResponse,
|
|
22
|
+
AppLogParams,
|
|
23
|
+
AppLogResponse,
|
|
24
|
+
AppModesResponse,
|
|
25
|
+
AppResource,
|
|
26
|
+
LogLevel,
|
|
27
|
+
Mode,
|
|
28
|
+
} from './resources/app';
|
|
20
29
|
import {
|
|
21
30
|
Config,
|
|
22
31
|
ConfigProvidersResponse,
|
|
@@ -28,7 +37,7 @@ import {
|
|
|
28
37
|
Provider,
|
|
29
38
|
} from './resources/config';
|
|
30
39
|
import { Event, EventListResponse } from './resources/event';
|
|
31
|
-
import { File, FileReadParams, FileReadResponse, FileStatusResponse } from './resources/file';
|
|
40
|
+
import { File, FileReadParams, FileReadResponse, FileResource, FileStatusResponse } from './resources/file';
|
|
32
41
|
import {
|
|
33
42
|
Find,
|
|
34
43
|
FindFilesParams,
|
|
@@ -37,12 +46,14 @@ import {
|
|
|
37
46
|
FindSymbolsResponse,
|
|
38
47
|
FindTextParams,
|
|
39
48
|
FindTextResponse,
|
|
49
|
+
Match,
|
|
50
|
+
Symbol,
|
|
40
51
|
} from './resources/find';
|
|
41
52
|
import {
|
|
53
|
+
AssistantMessage,
|
|
42
54
|
FilePart,
|
|
43
55
|
Message,
|
|
44
|
-
|
|
45
|
-
ReasoningPart,
|
|
56
|
+
Part,
|
|
46
57
|
Session,
|
|
47
58
|
SessionAbortResponse,
|
|
48
59
|
SessionChatParams,
|
|
@@ -54,20 +65,22 @@ import {
|
|
|
54
65
|
SessionResource,
|
|
55
66
|
SessionSummarizeParams,
|
|
56
67
|
SessionSummarizeResponse,
|
|
57
|
-
|
|
68
|
+
StepFinishPart,
|
|
58
69
|
StepStartPart,
|
|
59
70
|
TextPart,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
ToolPart,
|
|
72
|
+
ToolStateCompleted,
|
|
73
|
+
ToolStateError,
|
|
74
|
+
ToolStatePending,
|
|
75
|
+
ToolStateRunning,
|
|
76
|
+
UserMessage,
|
|
64
77
|
} from './resources/session';
|
|
65
78
|
import { type Fetch } from './internal/builtin-types';
|
|
66
79
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
67
80
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
68
81
|
import { readEnv } from './internal/utils/env';
|
|
69
82
|
import {
|
|
70
|
-
type LogLevel,
|
|
83
|
+
type LogLevel as ClientLogLevel,
|
|
71
84
|
type Logger,
|
|
72
85
|
formatRequestDetails,
|
|
73
86
|
loggerFor,
|
|
@@ -89,6 +102,8 @@ export interface ClientOptions {
|
|
|
89
102
|
*
|
|
90
103
|
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
91
104
|
* much longer than this timeout before the promise succeeds or fails.
|
|
105
|
+
*
|
|
106
|
+
* @unit milliseconds
|
|
92
107
|
*/
|
|
93
108
|
timeout?: number | undefined;
|
|
94
109
|
/**
|
|
@@ -133,7 +148,7 @@ export interface ClientOptions {
|
|
|
133
148
|
*
|
|
134
149
|
* Defaults to process.env['OPENCODE_LOG'] or 'warn' if it isn't set.
|
|
135
150
|
*/
|
|
136
|
-
logLevel?:
|
|
151
|
+
logLevel?: ClientLogLevel | undefined;
|
|
137
152
|
|
|
138
153
|
/**
|
|
139
154
|
* Set the logger.
|
|
@@ -151,7 +166,7 @@ export class Opencode {
|
|
|
151
166
|
maxRetries: number;
|
|
152
167
|
timeout: number;
|
|
153
168
|
logger: Logger | undefined;
|
|
154
|
-
logLevel:
|
|
169
|
+
logLevel: ClientLogLevel | undefined;
|
|
155
170
|
fetchOptions: MergedRequestInit | undefined;
|
|
156
171
|
|
|
157
172
|
private fetch: Fetch;
|
|
@@ -198,7 +213,7 @@ export class Opencode {
|
|
|
198
213
|
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
199
214
|
*/
|
|
200
215
|
withOptions(options: Partial<ClientOptions>): this {
|
|
201
|
-
|
|
216
|
+
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
202
217
|
...this._options,
|
|
203
218
|
baseURL: this.baseURL,
|
|
204
219
|
maxRetries: this.maxRetries,
|
|
@@ -209,6 +224,7 @@ export class Opencode {
|
|
|
209
224
|
fetchOptions: this.fetchOptions,
|
|
210
225
|
...options,
|
|
211
226
|
});
|
|
227
|
+
return client;
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
/**
|
|
@@ -354,7 +370,9 @@ export class Opencode {
|
|
|
354
370
|
|
|
355
371
|
await this.prepareOptions(options);
|
|
356
372
|
|
|
357
|
-
const { req, url, timeout } = this.buildRequest(options, {
|
|
373
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
374
|
+
retryCount: maxRetries - retriesRemaining,
|
|
375
|
+
});
|
|
358
376
|
|
|
359
377
|
await this.prepareRequest(req, { url, options });
|
|
360
378
|
|
|
@@ -432,7 +450,7 @@ export class Opencode {
|
|
|
432
450
|
} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
433
451
|
|
|
434
452
|
if (!response.ok) {
|
|
435
|
-
const shouldRetry = this.shouldRetry(response);
|
|
453
|
+
const shouldRetry = await this.shouldRetry(response);
|
|
436
454
|
if (retriesRemaining && shouldRetry) {
|
|
437
455
|
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
438
456
|
|
|
@@ -531,7 +549,7 @@ export class Opencode {
|
|
|
531
549
|
}
|
|
532
550
|
}
|
|
533
551
|
|
|
534
|
-
private shouldRetry(response: Response): boolean {
|
|
552
|
+
private async shouldRetry(response: Response): Promise<boolean> {
|
|
535
553
|
// Note this is not a standard header.
|
|
536
554
|
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
537
555
|
|
|
@@ -608,10 +626,10 @@ export class Opencode {
|
|
|
608
626
|
return sleepSeconds * jitter * 1000;
|
|
609
627
|
}
|
|
610
628
|
|
|
611
|
-
buildRequest(
|
|
629
|
+
async buildRequest(
|
|
612
630
|
inputOptions: FinalRequestOptions,
|
|
613
631
|
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
614
|
-
): { req: FinalizedRequestInit; url: string; timeout: number } {
|
|
632
|
+
): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
|
|
615
633
|
const options = { ...inputOptions };
|
|
616
634
|
const { method, path, query, defaultBaseURL } = options;
|
|
617
635
|
|
|
@@ -619,7 +637,7 @@ export class Opencode {
|
|
|
619
637
|
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
620
638
|
options.timeout = options.timeout ?? this.timeout;
|
|
621
639
|
const { bodyHeaders, body } = this.buildBody({ options });
|
|
622
|
-
const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
640
|
+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
623
641
|
|
|
624
642
|
const req: FinalizedRequestInit = {
|
|
625
643
|
method,
|
|
@@ -635,7 +653,7 @@ export class Opencode {
|
|
|
635
653
|
return { req, url, timeout: options.timeout };
|
|
636
654
|
}
|
|
637
655
|
|
|
638
|
-
private buildHeaders({
|
|
656
|
+
private async buildHeaders({
|
|
639
657
|
options,
|
|
640
658
|
method,
|
|
641
659
|
bodyHeaders,
|
|
@@ -645,7 +663,7 @@ export class Opencode {
|
|
|
645
663
|
method: HTTPMethod;
|
|
646
664
|
bodyHeaders: HeadersLike;
|
|
647
665
|
retryCount: number;
|
|
648
|
-
}): Headers {
|
|
666
|
+
}): Promise<Headers> {
|
|
649
667
|
let idempotencyHeaders: HeadersLike = {};
|
|
650
668
|
if (this.idempotencyHeader && method !== 'get') {
|
|
651
669
|
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
|
|
@@ -730,14 +748,14 @@ export class Opencode {
|
|
|
730
748
|
event: API.Event = new API.Event(this);
|
|
731
749
|
app: API.AppResource = new API.AppResource(this);
|
|
732
750
|
find: API.Find = new API.Find(this);
|
|
733
|
-
file: API.
|
|
751
|
+
file: API.FileResource = new API.FileResource(this);
|
|
734
752
|
config: API.ConfigResource = new API.ConfigResource(this);
|
|
735
753
|
session: API.SessionResource = new API.SessionResource(this);
|
|
736
754
|
}
|
|
737
755
|
Opencode.Event = Event;
|
|
738
756
|
Opencode.AppResource = AppResource;
|
|
739
757
|
Opencode.Find = Find;
|
|
740
|
-
Opencode.
|
|
758
|
+
Opencode.FileResource = FileResource;
|
|
741
759
|
Opencode.ConfigResource = ConfigResource;
|
|
742
760
|
Opencode.SessionResource = SessionResource;
|
|
743
761
|
export declare namespace Opencode {
|
|
@@ -745,10 +763,21 @@ export declare namespace Opencode {
|
|
|
745
763
|
|
|
746
764
|
export { Event as Event, type EventListResponse as EventListResponse };
|
|
747
765
|
|
|
748
|
-
export {
|
|
766
|
+
export {
|
|
767
|
+
AppResource as AppResource,
|
|
768
|
+
type App as App,
|
|
769
|
+
type LogLevel as LogLevel,
|
|
770
|
+
type Mode as Mode,
|
|
771
|
+
type AppInitResponse as AppInitResponse,
|
|
772
|
+
type AppLogResponse as AppLogResponse,
|
|
773
|
+
type AppModesResponse as AppModesResponse,
|
|
774
|
+
type AppLogParams as AppLogParams,
|
|
775
|
+
};
|
|
749
776
|
|
|
750
777
|
export {
|
|
751
778
|
Find as Find,
|
|
779
|
+
type Match as Match,
|
|
780
|
+
type Symbol as Symbol,
|
|
752
781
|
type FindFilesResponse as FindFilesResponse,
|
|
753
782
|
type FindSymbolsResponse as FindSymbolsResponse,
|
|
754
783
|
type FindTextResponse as FindTextResponse,
|
|
@@ -758,7 +787,8 @@ export declare namespace Opencode {
|
|
|
758
787
|
};
|
|
759
788
|
|
|
760
789
|
export {
|
|
761
|
-
|
|
790
|
+
FileResource as FileResource,
|
|
791
|
+
type File as File,
|
|
762
792
|
type FileReadResponse as FileReadResponse,
|
|
763
793
|
type FileStatusResponse as FileStatusResponse,
|
|
764
794
|
type FileReadParams as FileReadParams,
|
|
@@ -777,18 +807,20 @@ export declare namespace Opencode {
|
|
|
777
807
|
|
|
778
808
|
export {
|
|
779
809
|
SessionResource as SessionResource,
|
|
810
|
+
type AssistantMessage as AssistantMessage,
|
|
780
811
|
type FilePart as FilePart,
|
|
781
812
|
type Message as Message,
|
|
782
|
-
type
|
|
783
|
-
type ReasoningPart as ReasoningPart,
|
|
813
|
+
type Part as Part,
|
|
784
814
|
type Session as Session,
|
|
785
|
-
type
|
|
815
|
+
type StepFinishPart as StepFinishPart,
|
|
786
816
|
type StepStartPart as StepStartPart,
|
|
787
817
|
type TextPart as TextPart,
|
|
788
|
-
type
|
|
789
|
-
type
|
|
790
|
-
type
|
|
791
|
-
type
|
|
818
|
+
type ToolPart as ToolPart,
|
|
819
|
+
type ToolStateCompleted as ToolStateCompleted,
|
|
820
|
+
type ToolStateError as ToolStateError,
|
|
821
|
+
type ToolStatePending as ToolStatePending,
|
|
822
|
+
type ToolStateRunning as ToolStateRunning,
|
|
823
|
+
type UserMessage as UserMessage,
|
|
792
824
|
type SessionListResponse as SessionListResponse,
|
|
793
825
|
type SessionDeleteResponse as SessionDeleteResponse,
|
|
794
826
|
type SessionAbortResponse as SessionAbortResponse,
|
|
@@ -800,6 +832,7 @@ export declare namespace Opencode {
|
|
|
800
832
|
type SessionSummarizeParams as SessionSummarizeParams,
|
|
801
833
|
};
|
|
802
834
|
|
|
835
|
+
export type MessageAbortedError = API.MessageAbortedError;
|
|
803
836
|
export type ProviderAuthError = API.ProviderAuthError;
|
|
804
837
|
export type UnknownError = API.UnknownError;
|
|
805
838
|
}
|
package/src/core/streaming.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';
|
|
|
5
5
|
import { ReadableStreamToAsyncIterable } from '../internal/shims';
|
|
6
6
|
import { isAbortError } from '../internal/errors';
|
|
7
7
|
import { encodeUTF8 } from '../internal/utils/bytes';
|
|
8
|
+
import { loggerFor } from '../internal/utils/log';
|
|
9
|
+
import type { Opencode } from '../client';
|
|
8
10
|
|
|
9
11
|
type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;
|
|
10
12
|
|
|
@@ -16,16 +18,24 @@ export type ServerSentEvent = {
|
|
|
16
18
|
|
|
17
19
|
export class Stream<Item> implements AsyncIterable<Item> {
|
|
18
20
|
controller: AbortController;
|
|
21
|
+
#client: Opencode | undefined;
|
|
19
22
|
|
|
20
23
|
constructor(
|
|
21
24
|
private iterator: () => AsyncIterator<Item>,
|
|
22
25
|
controller: AbortController,
|
|
26
|
+
client?: Opencode,
|
|
23
27
|
) {
|
|
24
28
|
this.controller = controller;
|
|
29
|
+
this.#client = client;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
static fromSSEResponse<Item>(
|
|
32
|
+
static fromSSEResponse<Item>(
|
|
33
|
+
response: Response,
|
|
34
|
+
controller: AbortController,
|
|
35
|
+
client?: Opencode,
|
|
36
|
+
): Stream<Item> {
|
|
28
37
|
let consumed = false;
|
|
38
|
+
const logger = client ? loggerFor(client) : console;
|
|
29
39
|
|
|
30
40
|
async function* iterator(): AsyncIterator<Item, any, undefined> {
|
|
31
41
|
if (consumed) {
|
|
@@ -38,8 +48,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
38
48
|
try {
|
|
39
49
|
yield JSON.parse(sse.data);
|
|
40
50
|
} catch (e) {
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
52
|
+
logger.error(`From chunk:`, sse.raw);
|
|
43
53
|
throw e;
|
|
44
54
|
}
|
|
45
55
|
}
|
|
@@ -54,14 +64,18 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
return new Stream(iterator, controller);
|
|
67
|
+
return new Stream(iterator, controller, client);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
61
71
|
* Generates a Stream from a newline-separated ReadableStream
|
|
62
72
|
* where each item is a JSON value.
|
|
63
73
|
*/
|
|
64
|
-
static fromReadableStream<Item>(
|
|
74
|
+
static fromReadableStream<Item>(
|
|
75
|
+
readableStream: ReadableStream,
|
|
76
|
+
controller: AbortController,
|
|
77
|
+
client?: Opencode,
|
|
78
|
+
): Stream<Item> {
|
|
65
79
|
let consumed = false;
|
|
66
80
|
|
|
67
81
|
async function* iterLines(): AsyncGenerator<string, void, unknown> {
|
|
@@ -101,7 +115,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
117
|
|
|
104
|
-
return new Stream(iterator, controller);
|
|
118
|
+
return new Stream(iterator, controller, client);
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
[Symbol.asyncIterator](): AsyncIterator<Item> {
|
|
@@ -131,8 +145,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
131
145
|
};
|
|
132
146
|
|
|
133
147
|
return [
|
|
134
|
-
new Stream(() => teeIterator(left), this.controller),
|
|
135
|
-
new Stream(() => teeIterator(right), this.controller),
|
|
148
|
+
new Stream(() => teeIterator(left), this.controller, this.#client),
|
|
149
|
+
new Stream(() => teeIterator(right), this.controller, this.#client),
|
|
136
150
|
];
|
|
137
151
|
}
|
|
138
152
|
|
package/src/internal/parse.ts
CHANGED
|
@@ -24,10 +24,10 @@ export async function defaultParseResponse<T>(client: Opencode, props: APIRespon
|
|
|
24
24
|
// that if you set `stream: true` the response type must also be `Stream<T>`
|
|
25
25
|
|
|
26
26
|
if (props.options.__streamClass) {
|
|
27
|
-
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any;
|
|
27
|
+
return props.options.__streamClass.fromSSEResponse(response, props.controller, client) as any;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
return Stream.fromSSEResponse(response, props.controller) as any;
|
|
30
|
+
return Stream.fromSSEResponse(response, props.controller, client) as any;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// fetch refuses to read the body when the status code is 204.
|
|
@@ -10,17 +10,70 @@ import { type HeadersLike } from './headers';
|
|
|
10
10
|
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
|
|
11
11
|
|
|
12
12
|
export type RequestOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
|
|
15
|
+
*/
|
|
13
16
|
method?: HTTPMethod;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The URL path for the request.
|
|
20
|
+
*
|
|
21
|
+
* @example "/v1/foo"
|
|
22
|
+
*/
|
|
14
23
|
path?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Query parameters to include in the request URL.
|
|
27
|
+
*/
|
|
15
28
|
query?: object | undefined | null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The request body. Can be a string, JSON object, FormData, or other supported types.
|
|
32
|
+
*/
|
|
16
33
|
body?: unknown;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
|
|
37
|
+
*/
|
|
17
38
|
headers?: HeadersLike;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
42
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
43
|
+
*
|
|
44
|
+
* @default 2
|
|
45
|
+
*/
|
|
18
46
|
maxRetries?: number;
|
|
47
|
+
|
|
19
48
|
stream?: boolean | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
52
|
+
* from the server before timing out a single request.
|
|
53
|
+
*
|
|
54
|
+
* @unit milliseconds
|
|
55
|
+
*/
|
|
20
56
|
timeout?: number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Additional `RequestInit` options to be passed to the underlying `fetch` call.
|
|
60
|
+
* These options will be merged with the client's default fetch options.
|
|
61
|
+
*/
|
|
21
62
|
fetchOptions?: MergedRequestInit;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* An AbortSignal that can be used to cancel the request.
|
|
66
|
+
*/
|
|
22
67
|
signal?: AbortSignal | undefined | null;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A unique key for this request to enable idempotency.
|
|
71
|
+
*/
|
|
23
72
|
idempotencyKey?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Override the default base URL for this specific request.
|
|
76
|
+
*/
|
|
24
77
|
defaultBaseURL?: string | undefined;
|
|
25
78
|
|
|
26
79
|
__binaryResponse?: boolean | undefined;
|
package/src/resources/app.ts
CHANGED
|
@@ -18,6 +18,20 @@ export class AppResource extends APIResource {
|
|
|
18
18
|
init(options?: RequestOptions): APIPromise<AppInitResponse> {
|
|
19
19
|
return this._client.post('/app/init', options);
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Write a log entry to the server logs
|
|
24
|
+
*/
|
|
25
|
+
log(body: AppLogParams, options?: RequestOptions): APIPromise<AppLogResponse> {
|
|
26
|
+
return this._client.post('/log', { body, ...options });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* List all modes
|
|
31
|
+
*/
|
|
32
|
+
modes(options?: RequestOptions): APIPromise<AppModesResponse> {
|
|
33
|
+
return this._client.get('/mode', options);
|
|
34
|
+
}
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
export interface App {
|
|
@@ -28,8 +42,6 @@ export interface App {
|
|
|
28
42
|
path: App.Path;
|
|
29
43
|
|
|
30
44
|
time: App.Time;
|
|
31
|
-
|
|
32
|
-
user: string;
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
export namespace App {
|
|
@@ -50,8 +62,65 @@ export namespace App {
|
|
|
50
62
|
}
|
|
51
63
|
}
|
|
52
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Log level
|
|
67
|
+
*/
|
|
68
|
+
export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
69
|
+
|
|
70
|
+
export interface Mode {
|
|
71
|
+
name: string;
|
|
72
|
+
|
|
73
|
+
tools: { [key: string]: boolean };
|
|
74
|
+
|
|
75
|
+
model?: Mode.Model;
|
|
76
|
+
|
|
77
|
+
prompt?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export namespace Mode {
|
|
81
|
+
export interface Model {
|
|
82
|
+
modelID: string;
|
|
83
|
+
|
|
84
|
+
providerID: string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
53
88
|
export type AppInitResponse = boolean;
|
|
54
89
|
|
|
90
|
+
export type AppLogResponse = boolean;
|
|
91
|
+
|
|
92
|
+
export type AppModesResponse = Array<Mode>;
|
|
93
|
+
|
|
94
|
+
export interface AppLogParams {
|
|
95
|
+
/**
|
|
96
|
+
* Log level
|
|
97
|
+
*/
|
|
98
|
+
level: 'debug' | 'info' | 'error' | 'warn';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Log message
|
|
102
|
+
*/
|
|
103
|
+
message: string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Service name for the log entry
|
|
107
|
+
*/
|
|
108
|
+
service: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Additional metadata for the log entry
|
|
112
|
+
*/
|
|
113
|
+
extra?: { [key: string]: unknown };
|
|
114
|
+
}
|
|
115
|
+
|
|
55
116
|
export declare namespace AppResource {
|
|
56
|
-
export {
|
|
117
|
+
export {
|
|
118
|
+
type App as App,
|
|
119
|
+
type LogLevel as LogLevel,
|
|
120
|
+
type Mode as Mode,
|
|
121
|
+
type AppInitResponse as AppInitResponse,
|
|
122
|
+
type AppLogResponse as AppLogResponse,
|
|
123
|
+
type AppModesResponse as AppModesResponse,
|
|
124
|
+
type AppLogParams as AppLogParams,
|
|
125
|
+
};
|
|
57
126
|
}
|