@tipsy-studio/sdk 0.0.3 → 0.0.4
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 +155 -14
- package/dist/{chunk-2TOC6J52.js → chunk-NLCN4YRK.js} +18 -18
- package/dist/chunk-NLCN4YRK.js.map +1 -0
- package/dist/index.cjs +16 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -39
- package/dist/index.d.ts +86 -39
- package/dist/index.js +1 -1
- package/dist/react.cjs +36 -36
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +7 -7
- package/dist/react.d.ts +7 -7
- package/dist/react.js +18 -22
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2TOC6J52.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,36 +1,73 @@
|
|
|
1
1
|
declare const TIPSY_BRIDGE_PROTOCOL = "tipsy-bridge-v1";
|
|
2
2
|
declare const TIPSY_INIT_RETRY_MS = 500;
|
|
3
|
-
declare const
|
|
3
|
+
declare const RESPOND_METHOD = "sdk.respond";
|
|
4
4
|
type TipsyRole = "system" | "user" | "assistant";
|
|
5
|
-
type
|
|
5
|
+
type TipsyMessage = {
|
|
6
6
|
role: TipsyRole;
|
|
7
7
|
content: string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type TipsyUsage = {
|
|
10
|
+
prompt_tokens: number;
|
|
11
|
+
completion_tokens: number;
|
|
12
|
+
total_tokens: number;
|
|
13
|
+
};
|
|
14
|
+
type TipsyTextResponseFormat = {
|
|
15
|
+
type: "text";
|
|
16
|
+
};
|
|
17
|
+
type TipsyJsonSchemaResponseFormat = {
|
|
18
|
+
type: "json_schema";
|
|
19
|
+
name: string;
|
|
20
|
+
schema: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
type TipsyRespondResponseFormat = TipsyTextResponseFormat | TipsyJsonSchemaResponseFormat;
|
|
23
|
+
type TipsyRespondRequestBase = {
|
|
24
|
+
messages: TipsyMessage[];
|
|
25
|
+
model_id?: string | null;
|
|
26
|
+
response_format: TipsyRespondResponseFormat;
|
|
27
|
+
};
|
|
28
|
+
type TipsyRespondStreamRequest = TipsyRespondRequestBase & {
|
|
11
29
|
stream: true;
|
|
12
30
|
};
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
type TipsyRespondNonStreamRequest = TipsyRespondRequestBase & {
|
|
32
|
+
stream: false;
|
|
33
|
+
};
|
|
34
|
+
type TipsyRespondRequest = TipsyRespondStreamRequest | TipsyRespondNonStreamRequest;
|
|
35
|
+
type TipsyRespondEnvelope<T = unknown> = {
|
|
36
|
+
code: number;
|
|
37
|
+
msg: string;
|
|
38
|
+
trace_id: string;
|
|
39
|
+
data: {
|
|
40
|
+
message_id: string;
|
|
41
|
+
result: T;
|
|
42
|
+
response_format: TipsyTextResponseFormat | {
|
|
43
|
+
type: "json_schema";
|
|
44
|
+
name: string;
|
|
19
45
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
24
|
-
type TipsyChatCompletionChunk = {
|
|
25
|
-
type: "stream";
|
|
26
|
-
chunk: string;
|
|
27
|
-
raw: TipsyChatCompletionRawChunk;
|
|
28
|
-
isFinished: false;
|
|
46
|
+
usage: TipsyUsage;
|
|
47
|
+
};
|
|
29
48
|
};
|
|
30
|
-
type
|
|
31
|
-
type: "
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
type TipsyRespondTextStreamEvent = {
|
|
50
|
+
type: "delta";
|
|
51
|
+
delta: string;
|
|
52
|
+
};
|
|
53
|
+
type TipsyRespondJsonStreamEvent<T = unknown> = {
|
|
54
|
+
type: "delta";
|
|
55
|
+
snapshot: Partial<T> | T;
|
|
56
|
+
};
|
|
57
|
+
type TipsyRespondMetaEvent = {
|
|
58
|
+
type: "meta";
|
|
59
|
+
message_id: string;
|
|
60
|
+
usage: TipsyUsage;
|
|
61
|
+
trace_id: string;
|
|
62
|
+
};
|
|
63
|
+
type TipsyRespondStreamEvent<T = unknown> = TipsyRespondTextStreamEvent | TipsyRespondJsonStreamEvent<T> | TipsyRespondMetaEvent;
|
|
64
|
+
type TipsyRespondResult<T = unknown> = {
|
|
65
|
+
message_id: string;
|
|
66
|
+
result: T;
|
|
67
|
+
response_format: TipsyTextResponseFormat | {
|
|
68
|
+
type: "json_schema";
|
|
69
|
+
name: string;
|
|
70
|
+
};
|
|
34
71
|
};
|
|
35
72
|
type TipsyBridgeErrorCode = "UNAUTHORIZED" | "BAD_REQUEST" | "NETWORK_ERROR" | "STREAM_PARSE_ERROR" | "ORIGIN_MISMATCH" | "UNSUPPORTED_METHOD" | "INTERNAL_ERROR";
|
|
36
73
|
type TipsyBridgeError = {
|
|
@@ -38,10 +75,13 @@ type TipsyBridgeError = {
|
|
|
38
75
|
message: string;
|
|
39
76
|
};
|
|
40
77
|
type TipsyBridgeRequestMap = {
|
|
41
|
-
[
|
|
78
|
+
[RESPOND_METHOD]: TipsyRespondRequest;
|
|
79
|
+
};
|
|
80
|
+
type TipsyBridgeStreamMap = {
|
|
81
|
+
[RESPOND_METHOD]: TipsyRespondStreamEvent;
|
|
42
82
|
};
|
|
43
83
|
type TipsyBridgeResponseMap = {
|
|
44
|
-
[
|
|
84
|
+
[RESPOND_METHOD]: TipsyRespondEnvelope | TipsyRespondResult;
|
|
45
85
|
};
|
|
46
86
|
type TipsyInitMessage = {
|
|
47
87
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
@@ -56,19 +96,25 @@ type TipsyRequestMessage<M extends keyof TipsyBridgeRequestMap> = {
|
|
|
56
96
|
type: "tipsy:request";
|
|
57
97
|
requestId: string;
|
|
58
98
|
method: M;
|
|
59
|
-
|
|
99
|
+
params: TipsyBridgeRequestMap[M];
|
|
60
100
|
};
|
|
61
|
-
type TipsyStreamMessage = {
|
|
101
|
+
type TipsyStreamMessage<M extends keyof TipsyBridgeStreamMap> = {
|
|
62
102
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
63
103
|
type: "tipsy:stream";
|
|
64
104
|
requestId: string;
|
|
65
|
-
payload:
|
|
105
|
+
payload: {
|
|
106
|
+
method: M;
|
|
107
|
+
event: TipsyBridgeStreamMap[M];
|
|
108
|
+
};
|
|
66
109
|
};
|
|
67
110
|
type TipsyResponseMessage<M extends keyof TipsyBridgeResponseMap> = {
|
|
68
111
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
69
112
|
type: "tipsy:response";
|
|
70
113
|
requestId: string;
|
|
71
|
-
payload:
|
|
114
|
+
payload: {
|
|
115
|
+
method: M;
|
|
116
|
+
result: TipsyBridgeResponseMap[M];
|
|
117
|
+
};
|
|
72
118
|
};
|
|
73
119
|
type TipsyErrorMessage = {
|
|
74
120
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
@@ -81,13 +127,14 @@ type TipsyAbortMessage = {
|
|
|
81
127
|
type: "tipsy:abort";
|
|
82
128
|
requestId: string;
|
|
83
129
|
};
|
|
84
|
-
type TipsyBridgeMessage = TipsyInitMessage | TipsyInitAckMessage | TipsyRequestMessage<keyof TipsyBridgeRequestMap> | TipsyStreamMessage | TipsyResponseMessage<keyof TipsyBridgeResponseMap> | TipsyErrorMessage | TipsyAbortMessage;
|
|
85
|
-
type TipsyRequestController = {
|
|
130
|
+
type TipsyBridgeMessage = TipsyInitMessage | TipsyInitAckMessage | TipsyRequestMessage<keyof TipsyBridgeRequestMap> | TipsyStreamMessage<keyof TipsyBridgeStreamMap> | TipsyResponseMessage<keyof TipsyBridgeResponseMap> | TipsyErrorMessage | TipsyAbortMessage;
|
|
131
|
+
type TipsyRequestController<M extends keyof TipsyBridgeRequestMap> = {
|
|
86
132
|
signal?: AbortSignal;
|
|
133
|
+
onEvent?: (event: TipsyBridgeStreamMap[M]) => void;
|
|
87
134
|
};
|
|
88
|
-
type
|
|
89
|
-
|
|
90
|
-
|
|
135
|
+
type TipsyRespondController<T = unknown> = {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
onEvent?: (event: TipsyRespondStreamEvent<T>) => void;
|
|
91
138
|
};
|
|
92
139
|
declare class TipsyBridgeClientError extends Error {
|
|
93
140
|
code: TipsyBridgeErrorCode;
|
|
@@ -107,12 +154,12 @@ type TipsyStudioClient = {
|
|
|
107
154
|
isReady: () => boolean;
|
|
108
155
|
subscribe: (listener: (isReady: boolean) => void) => () => void;
|
|
109
156
|
waitForReady: (signal?: AbortSignal) => Promise<void>;
|
|
110
|
-
call: <M extends keyof TipsyBridgeRequestMap>(method: M,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
157
|
+
call: <M extends keyof TipsyBridgeRequestMap>(method: M, params: TipsyBridgeRequestMap[M], controller?: TipsyRequestController<M>) => Promise<TipsyBridgeResponseMap[M]>;
|
|
158
|
+
respond<T = string>(request: TipsyRespondNonStreamRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondEnvelope<T>>;
|
|
159
|
+
respond<T = string>(request: TipsyRespondStreamRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondResult<T>>;
|
|
160
|
+
respond<T = string>(request: TipsyRespondRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondEnvelope<T> | TipsyRespondResult<T>>;
|
|
114
161
|
destroy: () => void;
|
|
115
162
|
};
|
|
116
163
|
declare function createTipsyStudioClient(options?: TipsyStudioClientOptions): TipsyStudioClient;
|
|
117
164
|
|
|
118
|
-
export {
|
|
165
|
+
export { RESPOND_METHOD, TIPSY_BRIDGE_PROTOCOL, TIPSY_INIT_RETRY_MS, type TipsyAbortMessage, TipsyBridgeClientError, type TipsyBridgeError, type TipsyBridgeErrorCode, type TipsyBridgeMessage, type TipsyBridgeRequestMap, type TipsyBridgeResponseMap, type TipsyBridgeStreamMap, type TipsyJsonSchemaResponseFormat, type TipsyMessage, type TipsyRequestController, type TipsyRequestMessage, type TipsyRespondController, type TipsyRespondEnvelope, type TipsyRespondMetaEvent, type TipsyRespondNonStreamRequest, type TipsyRespondRequest, type TipsyRespondResponseFormat, type TipsyRespondResult, type TipsyRespondStreamEvent, type TipsyRespondStreamRequest, type TipsyRole, type TipsyStudioClient, type TipsyStudioClientOptions, type TipsyTextResponseFormat, type TipsyUsage, createRequestId, createTipsyStudioClient, getParentOriginFromReferrer, isBridgeMessage, normalizeTargetOrigin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,73 @@
|
|
|
1
1
|
declare const TIPSY_BRIDGE_PROTOCOL = "tipsy-bridge-v1";
|
|
2
2
|
declare const TIPSY_INIT_RETRY_MS = 500;
|
|
3
|
-
declare const
|
|
3
|
+
declare const RESPOND_METHOD = "sdk.respond";
|
|
4
4
|
type TipsyRole = "system" | "user" | "assistant";
|
|
5
|
-
type
|
|
5
|
+
type TipsyMessage = {
|
|
6
6
|
role: TipsyRole;
|
|
7
7
|
content: string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type TipsyUsage = {
|
|
10
|
+
prompt_tokens: number;
|
|
11
|
+
completion_tokens: number;
|
|
12
|
+
total_tokens: number;
|
|
13
|
+
};
|
|
14
|
+
type TipsyTextResponseFormat = {
|
|
15
|
+
type: "text";
|
|
16
|
+
};
|
|
17
|
+
type TipsyJsonSchemaResponseFormat = {
|
|
18
|
+
type: "json_schema";
|
|
19
|
+
name: string;
|
|
20
|
+
schema: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
type TipsyRespondResponseFormat = TipsyTextResponseFormat | TipsyJsonSchemaResponseFormat;
|
|
23
|
+
type TipsyRespondRequestBase = {
|
|
24
|
+
messages: TipsyMessage[];
|
|
25
|
+
model_id?: string | null;
|
|
26
|
+
response_format: TipsyRespondResponseFormat;
|
|
27
|
+
};
|
|
28
|
+
type TipsyRespondStreamRequest = TipsyRespondRequestBase & {
|
|
11
29
|
stream: true;
|
|
12
30
|
};
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
type TipsyRespondNonStreamRequest = TipsyRespondRequestBase & {
|
|
32
|
+
stream: false;
|
|
33
|
+
};
|
|
34
|
+
type TipsyRespondRequest = TipsyRespondStreamRequest | TipsyRespondNonStreamRequest;
|
|
35
|
+
type TipsyRespondEnvelope<T = unknown> = {
|
|
36
|
+
code: number;
|
|
37
|
+
msg: string;
|
|
38
|
+
trace_id: string;
|
|
39
|
+
data: {
|
|
40
|
+
message_id: string;
|
|
41
|
+
result: T;
|
|
42
|
+
response_format: TipsyTextResponseFormat | {
|
|
43
|
+
type: "json_schema";
|
|
44
|
+
name: string;
|
|
19
45
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
24
|
-
type TipsyChatCompletionChunk = {
|
|
25
|
-
type: "stream";
|
|
26
|
-
chunk: string;
|
|
27
|
-
raw: TipsyChatCompletionRawChunk;
|
|
28
|
-
isFinished: false;
|
|
46
|
+
usage: TipsyUsage;
|
|
47
|
+
};
|
|
29
48
|
};
|
|
30
|
-
type
|
|
31
|
-
type: "
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
type TipsyRespondTextStreamEvent = {
|
|
50
|
+
type: "delta";
|
|
51
|
+
delta: string;
|
|
52
|
+
};
|
|
53
|
+
type TipsyRespondJsonStreamEvent<T = unknown> = {
|
|
54
|
+
type: "delta";
|
|
55
|
+
snapshot: Partial<T> | T;
|
|
56
|
+
};
|
|
57
|
+
type TipsyRespondMetaEvent = {
|
|
58
|
+
type: "meta";
|
|
59
|
+
message_id: string;
|
|
60
|
+
usage: TipsyUsage;
|
|
61
|
+
trace_id: string;
|
|
62
|
+
};
|
|
63
|
+
type TipsyRespondStreamEvent<T = unknown> = TipsyRespondTextStreamEvent | TipsyRespondJsonStreamEvent<T> | TipsyRespondMetaEvent;
|
|
64
|
+
type TipsyRespondResult<T = unknown> = {
|
|
65
|
+
message_id: string;
|
|
66
|
+
result: T;
|
|
67
|
+
response_format: TipsyTextResponseFormat | {
|
|
68
|
+
type: "json_schema";
|
|
69
|
+
name: string;
|
|
70
|
+
};
|
|
34
71
|
};
|
|
35
72
|
type TipsyBridgeErrorCode = "UNAUTHORIZED" | "BAD_REQUEST" | "NETWORK_ERROR" | "STREAM_PARSE_ERROR" | "ORIGIN_MISMATCH" | "UNSUPPORTED_METHOD" | "INTERNAL_ERROR";
|
|
36
73
|
type TipsyBridgeError = {
|
|
@@ -38,10 +75,13 @@ type TipsyBridgeError = {
|
|
|
38
75
|
message: string;
|
|
39
76
|
};
|
|
40
77
|
type TipsyBridgeRequestMap = {
|
|
41
|
-
[
|
|
78
|
+
[RESPOND_METHOD]: TipsyRespondRequest;
|
|
79
|
+
};
|
|
80
|
+
type TipsyBridgeStreamMap = {
|
|
81
|
+
[RESPOND_METHOD]: TipsyRespondStreamEvent;
|
|
42
82
|
};
|
|
43
83
|
type TipsyBridgeResponseMap = {
|
|
44
|
-
[
|
|
84
|
+
[RESPOND_METHOD]: TipsyRespondEnvelope | TipsyRespondResult;
|
|
45
85
|
};
|
|
46
86
|
type TipsyInitMessage = {
|
|
47
87
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
@@ -56,19 +96,25 @@ type TipsyRequestMessage<M extends keyof TipsyBridgeRequestMap> = {
|
|
|
56
96
|
type: "tipsy:request";
|
|
57
97
|
requestId: string;
|
|
58
98
|
method: M;
|
|
59
|
-
|
|
99
|
+
params: TipsyBridgeRequestMap[M];
|
|
60
100
|
};
|
|
61
|
-
type TipsyStreamMessage = {
|
|
101
|
+
type TipsyStreamMessage<M extends keyof TipsyBridgeStreamMap> = {
|
|
62
102
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
63
103
|
type: "tipsy:stream";
|
|
64
104
|
requestId: string;
|
|
65
|
-
payload:
|
|
105
|
+
payload: {
|
|
106
|
+
method: M;
|
|
107
|
+
event: TipsyBridgeStreamMap[M];
|
|
108
|
+
};
|
|
66
109
|
};
|
|
67
110
|
type TipsyResponseMessage<M extends keyof TipsyBridgeResponseMap> = {
|
|
68
111
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
69
112
|
type: "tipsy:response";
|
|
70
113
|
requestId: string;
|
|
71
|
-
payload:
|
|
114
|
+
payload: {
|
|
115
|
+
method: M;
|
|
116
|
+
result: TipsyBridgeResponseMap[M];
|
|
117
|
+
};
|
|
72
118
|
};
|
|
73
119
|
type TipsyErrorMessage = {
|
|
74
120
|
protocol: typeof TIPSY_BRIDGE_PROTOCOL;
|
|
@@ -81,13 +127,14 @@ type TipsyAbortMessage = {
|
|
|
81
127
|
type: "tipsy:abort";
|
|
82
128
|
requestId: string;
|
|
83
129
|
};
|
|
84
|
-
type TipsyBridgeMessage = TipsyInitMessage | TipsyInitAckMessage | TipsyRequestMessage<keyof TipsyBridgeRequestMap> | TipsyStreamMessage | TipsyResponseMessage<keyof TipsyBridgeResponseMap> | TipsyErrorMessage | TipsyAbortMessage;
|
|
85
|
-
type TipsyRequestController = {
|
|
130
|
+
type TipsyBridgeMessage = TipsyInitMessage | TipsyInitAckMessage | TipsyRequestMessage<keyof TipsyBridgeRequestMap> | TipsyStreamMessage<keyof TipsyBridgeStreamMap> | TipsyResponseMessage<keyof TipsyBridgeResponseMap> | TipsyErrorMessage | TipsyAbortMessage;
|
|
131
|
+
type TipsyRequestController<M extends keyof TipsyBridgeRequestMap> = {
|
|
86
132
|
signal?: AbortSignal;
|
|
133
|
+
onEvent?: (event: TipsyBridgeStreamMap[M]) => void;
|
|
87
134
|
};
|
|
88
|
-
type
|
|
89
|
-
|
|
90
|
-
|
|
135
|
+
type TipsyRespondController<T = unknown> = {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
onEvent?: (event: TipsyRespondStreamEvent<T>) => void;
|
|
91
138
|
};
|
|
92
139
|
declare class TipsyBridgeClientError extends Error {
|
|
93
140
|
code: TipsyBridgeErrorCode;
|
|
@@ -107,12 +154,12 @@ type TipsyStudioClient = {
|
|
|
107
154
|
isReady: () => boolean;
|
|
108
155
|
subscribe: (listener: (isReady: boolean) => void) => () => void;
|
|
109
156
|
waitForReady: (signal?: AbortSignal) => Promise<void>;
|
|
110
|
-
call: <M extends keyof TipsyBridgeRequestMap>(method: M,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
157
|
+
call: <M extends keyof TipsyBridgeRequestMap>(method: M, params: TipsyBridgeRequestMap[M], controller?: TipsyRequestController<M>) => Promise<TipsyBridgeResponseMap[M]>;
|
|
158
|
+
respond<T = string>(request: TipsyRespondNonStreamRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondEnvelope<T>>;
|
|
159
|
+
respond<T = string>(request: TipsyRespondStreamRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondResult<T>>;
|
|
160
|
+
respond<T = string>(request: TipsyRespondRequest, controller?: TipsyRespondController<T>): Promise<TipsyRespondEnvelope<T> | TipsyRespondResult<T>>;
|
|
114
161
|
destroy: () => void;
|
|
115
162
|
};
|
|
116
163
|
declare function createTipsyStudioClient(options?: TipsyStudioClientOptions): TipsyStudioClient;
|
|
117
164
|
|
|
118
|
-
export {
|
|
165
|
+
export { RESPOND_METHOD, TIPSY_BRIDGE_PROTOCOL, TIPSY_INIT_RETRY_MS, type TipsyAbortMessage, TipsyBridgeClientError, type TipsyBridgeError, type TipsyBridgeErrorCode, type TipsyBridgeMessage, type TipsyBridgeRequestMap, type TipsyBridgeResponseMap, type TipsyBridgeStreamMap, type TipsyJsonSchemaResponseFormat, type TipsyMessage, type TipsyRequestController, type TipsyRequestMessage, type TipsyRespondController, type TipsyRespondEnvelope, type TipsyRespondMetaEvent, type TipsyRespondNonStreamRequest, type TipsyRespondRequest, type TipsyRespondResponseFormat, type TipsyRespondResult, type TipsyRespondStreamEvent, type TipsyRespondStreamRequest, type TipsyRole, type TipsyStudioClient, type TipsyStudioClientOptions, type TipsyTextResponseFormat, type TipsyUsage, createRequestId, createTipsyStudioClient, getParentOriginFromReferrer, isBridgeMessage, normalizeTargetOrigin };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { RESPOND_METHOD, TIPSY_BRIDGE_PROTOCOL, TIPSY_INIT_RETRY_MS, TipsyBridgeClientError, createRequestId, createTipsyStudioClient, getParentOriginFromReferrer, isBridgeMessage, normalizeTargetOrigin } from './chunk-NLCN4YRK.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/react.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var react = require('react');
|
|
|
7
7
|
// src/bridge.ts
|
|
8
8
|
var TIPSY_BRIDGE_PROTOCOL = "tipsy-bridge-v1";
|
|
9
9
|
var TIPSY_INIT_RETRY_MS = 500;
|
|
10
|
-
var
|
|
10
|
+
var RESPOND_METHOD = "sdk.respond";
|
|
11
11
|
var TipsyBridgeClientError = class extends Error {
|
|
12
12
|
constructor(error) {
|
|
13
13
|
super(error.message);
|
|
@@ -136,21 +136,20 @@ function createTipsyStudioClient(options = {}) {
|
|
|
136
136
|
}
|
|
137
137
|
if (event.data.type === "tipsy:stream") {
|
|
138
138
|
const pending = pendingRequests.get(event.data.requestId);
|
|
139
|
-
if (!pending || pending.method !==
|
|
139
|
+
if (!pending || pending.method !== event.data.payload.method) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
pending.
|
|
142
|
+
pending.onEvent?.(event.data.payload.event);
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
if (event.data.type === "tipsy:response") {
|
|
146
146
|
const pending = pendingRequests.get(event.data.requestId);
|
|
147
|
-
if (!pending) {
|
|
147
|
+
if (!pending || pending.method !== event.data.payload.method) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
pendingRequests.delete(event.data.requestId);
|
|
151
151
|
pending.cleanupAbortListener?.();
|
|
152
|
-
pending.
|
|
153
|
-
pending.resolve(event.data.payload);
|
|
152
|
+
pending.resolve(event.data.payload.result);
|
|
154
153
|
}
|
|
155
154
|
};
|
|
156
155
|
const ensureConnected = () => {
|
|
@@ -225,6 +224,12 @@ function createTipsyStudioClient(options = {}) {
|
|
|
225
224
|
message: "Tipsy bridge is not ready."
|
|
226
225
|
});
|
|
227
226
|
};
|
|
227
|
+
function respond(request, controller) {
|
|
228
|
+
return client.call(RESPOND_METHOD, request, {
|
|
229
|
+
signal: controller?.signal,
|
|
230
|
+
onEvent: controller?.onEvent
|
|
231
|
+
});
|
|
232
|
+
}
|
|
228
233
|
const client = {
|
|
229
234
|
isReady: () => isReady,
|
|
230
235
|
subscribe(listener) {
|
|
@@ -238,7 +243,7 @@ function createTipsyStudioClient(options = {}) {
|
|
|
238
243
|
async waitForReady(signal) {
|
|
239
244
|
await waitForReady(signal);
|
|
240
245
|
},
|
|
241
|
-
async call(method,
|
|
246
|
+
async call(method, params, controller) {
|
|
242
247
|
if (isDestroyed) {
|
|
243
248
|
throw new TipsyBridgeClientError({
|
|
244
249
|
code: "NETWORK_ERROR",
|
|
@@ -253,8 +258,7 @@ function createTipsyStudioClient(options = {}) {
|
|
|
253
258
|
method,
|
|
254
259
|
resolve: (value) => resolve(value),
|
|
255
260
|
reject,
|
|
256
|
-
|
|
257
|
-
onComplete: method === CHAT_COMPLETIONS_METHOD ? controller?.onComplete : void 0
|
|
261
|
+
onEvent: controller?.onEvent
|
|
258
262
|
};
|
|
259
263
|
pendingRequests.set(requestId, pending);
|
|
260
264
|
const abortSignal = controller?.signal;
|
|
@@ -284,16 +288,12 @@ function createTipsyStudioClient(options = {}) {
|
|
|
284
288
|
type: "tipsy:request",
|
|
285
289
|
requestId,
|
|
286
290
|
method,
|
|
287
|
-
|
|
291
|
+
params
|
|
288
292
|
});
|
|
289
293
|
}
|
|
290
294
|
);
|
|
291
295
|
},
|
|
292
|
-
|
|
293
|
-
completions(input, controller) {
|
|
294
|
-
return client.call(CHAT_COMPLETIONS_METHOD, input, controller);
|
|
295
|
-
}
|
|
296
|
-
},
|
|
296
|
+
respond,
|
|
297
297
|
destroy() {
|
|
298
298
|
if (isDestroyed) {
|
|
299
299
|
return;
|
|
@@ -348,20 +348,26 @@ function TipsyStudioProvider({
|
|
|
348
348
|
};
|
|
349
349
|
}, [targetOrigin]);
|
|
350
350
|
const contextValue = react.useMemo(() => {
|
|
351
|
+
const notReadyError = new TipsyBridgeClientError({
|
|
352
|
+
code: "NETWORK_ERROR",
|
|
353
|
+
message: "Tipsy bridge is not ready."
|
|
354
|
+
});
|
|
355
|
+
const respond = ((request, controller) => {
|
|
356
|
+
if (!client) {
|
|
357
|
+
return Promise.reject(notReadyError);
|
|
358
|
+
}
|
|
359
|
+
return client.respond(request, controller);
|
|
360
|
+
});
|
|
351
361
|
return {
|
|
352
362
|
isReady,
|
|
353
363
|
targetOrigin: resolvedTargetOrigin,
|
|
354
|
-
call(method,
|
|
364
|
+
call(method, params, controller) {
|
|
355
365
|
if (!client) {
|
|
356
|
-
return Promise.reject(
|
|
357
|
-
new TipsyBridgeClientError({
|
|
358
|
-
code: "NETWORK_ERROR",
|
|
359
|
-
message: "Tipsy bridge is not ready."
|
|
360
|
-
})
|
|
361
|
-
);
|
|
366
|
+
return Promise.reject(notReadyError);
|
|
362
367
|
}
|
|
363
|
-
return client.call(method,
|
|
364
|
-
}
|
|
368
|
+
return client.call(method, params, controller);
|
|
369
|
+
},
|
|
370
|
+
respond
|
|
365
371
|
};
|
|
366
372
|
}, [client, isReady, resolvedTargetOrigin]);
|
|
367
373
|
return react.createElement(
|
|
@@ -377,23 +383,17 @@ function useTipsyStudio() {
|
|
|
377
383
|
}
|
|
378
384
|
return context;
|
|
379
385
|
}
|
|
380
|
-
function useTipsyChat() {
|
|
381
|
-
const studio = useTipsyStudio();
|
|
382
|
-
return react.useMemo(() => {
|
|
383
|
-
return {
|
|
384
|
-
completions(input, controller) {
|
|
385
|
-
return studio.call(CHAT_COMPLETIONS_METHOD, input, controller);
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
}, [studio]);
|
|
389
|
-
}
|
|
390
386
|
|
|
391
|
-
exports.
|
|
387
|
+
exports.RESPOND_METHOD = RESPOND_METHOD;
|
|
392
388
|
exports.TIPSY_BRIDGE_PROTOCOL = TIPSY_BRIDGE_PROTOCOL;
|
|
389
|
+
exports.TIPSY_INIT_RETRY_MS = TIPSY_INIT_RETRY_MS;
|
|
393
390
|
exports.TipsyBridgeClientError = TipsyBridgeClientError;
|
|
394
391
|
exports.TipsyStudioProvider = TipsyStudioProvider;
|
|
392
|
+
exports.createRequestId = createRequestId;
|
|
395
393
|
exports.createTipsyStudioClient = createTipsyStudioClient;
|
|
396
|
-
exports.
|
|
394
|
+
exports.getParentOriginFromReferrer = getParentOriginFromReferrer;
|
|
395
|
+
exports.isBridgeMessage = isBridgeMessage;
|
|
396
|
+
exports.normalizeTargetOrigin = normalizeTargetOrigin;
|
|
397
397
|
exports.useTipsyStudio = useTipsyStudio;
|
|
398
398
|
//# sourceMappingURL=react.cjs.map
|
|
399
399
|
//# sourceMappingURL=react.cjs.map
|