@hasura/promptql 0.0.1
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/LICENSE +201 -0
- package/README.md +116 -0
- package/dist/client.d.ts +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.iife.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +114 -0
- package/dist/index.umd.js +1 -0
- package/dist/promptql.d.ts +441 -0
- package/dist/types.d.ts +144 -0
- package/dist/utils.d.ts +10 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# PromptQL NodeJS SDK
|
|
2
|
+
|
|
3
|
+
A Node.js SDK for [PromptQL API](https://hasura.io/docs/promptql/promptql-apis/overview/).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Run the following command:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @hasura/promptql
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Get started
|
|
14
|
+
|
|
15
|
+
### Prerequisite
|
|
16
|
+
|
|
17
|
+
- If you are new with PromptQL, follow [the quickstart guide of PromptQL](https://hasura.io/docs/promptql/quickstart/) to create a project.
|
|
18
|
+
- Create a PromptQL API Key in project settings tab on [https://console.hasura.io](https://console.hasura.io).
|
|
19
|
+
- Your Project API endpoint and security headers.
|
|
20
|
+
|
|
21
|
+
### Use PromptQL SDK
|
|
22
|
+
|
|
23
|
+
Create the PromptQL client with required configurations:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createPromptQLClient } from '@hasura/promptql';
|
|
27
|
+
|
|
28
|
+
const client = createPromptQLClient({
|
|
29
|
+
apiKey: '<your-promptql-api-key>',
|
|
30
|
+
ddn: {
|
|
31
|
+
url: '<your-project-endpoint>',
|
|
32
|
+
headers: {
|
|
33
|
+
'Authorization': '<credential>'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
// You can define a lazy function for the ddn options.
|
|
37
|
+
//
|
|
38
|
+
// ddn: () => {{
|
|
39
|
+
// url: '<your-project-endpoint>',
|
|
40
|
+
// headers: {
|
|
41
|
+
// 'Authorization': '<credential>'
|
|
42
|
+
// }
|
|
43
|
+
// }}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const runQuery = (text: string) => {
|
|
47
|
+
return client.query({
|
|
48
|
+
artifacts: [],
|
|
49
|
+
interactions: [
|
|
50
|
+
{
|
|
51
|
+
user_message: {
|
|
52
|
+
text,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
ddn: {
|
|
57
|
+
// you can override the default ddn config,
|
|
58
|
+
// for example, dynamic auth credentials
|
|
59
|
+
headers: {}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return response.
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
runQuery('what can you do?').then((response) => {
|
|
67
|
+
console.log(response)
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Reference
|
|
72
|
+
|
|
73
|
+
### Natural Language
|
|
74
|
+
|
|
75
|
+
The [Natural Language Query API](https://hasura.io/docs/promptql/promptql-apis/natural-language-api/) allows you to interact with PromptQL directly, sending messages and receiving responses.
|
|
76
|
+
|
|
77
|
+
#### Non-Streaming
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
function query(body: PromptQLQueryRequest, queryOptions?: FetchOptions) => Promise<QueryResponse>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Streaming
|
|
84
|
+
|
|
85
|
+
The streaming response sends chunks of data in Server-Sent Events (SSE) format.
|
|
86
|
+
If the callback isn't set the client returns the raw response and you need to handle the response manually.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
function queryStream: (body: PromptQLQueryRequest, callback?: (data: QueryResponseChunk) => void | Promise<void>, queryOptions?: FetchOptions) Promise<Response>;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
client
|
|
96
|
+
.queryStream({
|
|
97
|
+
artifacts: [],
|
|
98
|
+
interactions: [
|
|
99
|
+
user_message: {
|
|
100
|
+
text: 'what can you do?',
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
async (chunk) => {
|
|
105
|
+
console.error(chunk);
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Execute Program
|
|
111
|
+
|
|
112
|
+
Execute a PromptQL program with your data.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
function executeProgram: (body: PromptQLExecuteRequest, executeOptions?: FetchOptions) Promise<PromptQlExecutionResult>;
|
|
116
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PromptQLClient, PromptQLClientConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Description placeholder
|
|
4
|
+
*
|
|
5
|
+
* @param {PromptQLClientConfig} options
|
|
6
|
+
* @returns {{ client: any; query: (body: any, queryOptions?: Omit<FetchOptions<operations>, "body">) => Promise<QueryResponse>; executeProgram: (body: any, executeOptions?: Omit<FetchOptions<operations>, "body">) => Promise<...>; }}
|
|
7
|
+
*/
|
|
8
|
+
export declare const createPromptQLClient: (options: PromptQLClientConfig) => PromptQLClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var promptql=function(i){"use strict";var E=Object.defineProperty;var k=(i,r,s)=>r in i?E(i,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[r]=s;var _=(i,r,s)=>k(i,typeof r!="symbol"?r+"":r,s);class r extends Error{constructor(h,w){super(w||h.map(f=>f.msg).join(". "));_(this,"detail",[]);this.detail=h}}const s="data: ",v=async t=>(await $(t),t.json()),$=async t=>{if(t.status>500){const c=t.body?await t.text():t.statusText;throw new r([],c)}if(t.status>400){const c=t.body?await t.json():null;throw c!=null&&c.detail?new r(c.detail):new r([{loc:[],msg:t.statusText,type:"unknown"}])}},j=t=>{const c=t.baseUrl?t.baseUrl[t.baseUrl.length-1]==="/"?t.baseUrl:`${t.baseUrl}/`:"https://api.promptql.pro.hasura.io/",h={...t.headers??{},Authorization:`Bearer ${t.apiKey}`},w=t.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,f=t.llm??{provider:"hasura"},C=async e=>{const a=typeof t.ddn=="function"?await t.ddn():t.ddn;return{url:(e==null?void 0:e.url)||(a.url.endsWith("/v1/sql")?a.url:`${a.url}/v1/sql`),headers:{...(a==null?void 0:a.headers)??{},...(e==null?void 0:e.headers)??{}}}},T=async(e,a,n)=>{const l=await C(e.ddn);return fetch(`${c}query`,{...n,method:"POST",headers:{...h,...n==null?void 0:n.headers,"Content-Type":"application/json"},body:JSON.stringify({llm:f,...e,version:"v1",ddn:l,timezone:e.timezone||w,stream:a})})};return{query:(e,a)=>T(e,!1,a).then(v),queryStream:async(e,a,n)=>{var S;const l=await T(e,!0,n);if(typeof a!="function"||!l.body)return l;const x=l.body.getReader(),z=new TextDecoder("utf-8");let o="";const P=async u=>{if(!u&&!o)return;let d=o+u;o="",d.startsWith(s)&&(d=u.substring(s.length)),d.split(s).forEach(async(y,U)=>{const m=y.trim();if(m[m.length-1]!=="}"){o+=U>0?`data: ${y}`:y;return}let b;try{b=JSON.parse(m)}catch{o+=U>0?`data: ${m}`:m}b&&await a(b)})};for(;!((S=n==null?void 0:n.signal)!=null&&S.aborted);){const{value:u,done:d}=await x.read();if(d)break;const g=z.decode(u);g&&await P(g)}return o&&await P(""),l},executeProgram:async(e,a)=>{const n=await C(e.ddn);return await fetch(`${c}execute_program`,{...a,body:JSON.stringify({...e,ai_primitives_llm:e.ai_primitives_llm??f,ddn:n})}).then(v)}}};return i.PromptQLError=r,i.createPromptQLClient=j,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var $=Object.defineProperty;var j=(t,e,s)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var x=(t,e,s)=>j(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class m extends Error{constructor(s,h){super(h||s.map(d=>d.msg).join(". "));x(this,"detail",[]);this.detail=s}}const y="data: ",S=async t=>(await z(t),t.json()),z=async t=>{if(t.status>500){const e=t.body?await t.text():t.statusText;throw new m([],e)}if(t.status>400){const e=t.body?await t.json():null;throw e!=null&&e.detail?new m(e.detail):new m([{loc:[],msg:t.statusText,type:"unknown"}])}},E=t=>{const e=t.baseUrl?t.baseUrl[t.baseUrl.length-1]==="/"?t.baseUrl:`${t.baseUrl}/`:"https://api.promptql.pro.hasura.io/",s={...t.headers??{},Authorization:`Bearer ${t.apiKey}`},h=t.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,d=t.llm??{provider:"hasura"},b=async a=>{const r=typeof t.ddn=="function"?await t.ddn():t.ddn;return{url:(a==null?void 0:a.url)||(r.url.endsWith("/v1/sql")?r.url:`${r.url}/v1/sql`),headers:{...(r==null?void 0:r.headers)??{},...(a==null?void 0:a.headers)??{}}}},v=async(a,r,n)=>{const i=await b(a.ddn);return fetch(`${e}query`,{...n,method:"POST",headers:{...s,...n==null?void 0:n.headers,"Content-Type":"application/json"},body:JSON.stringify({llm:d,...a,version:"v1",ddn:i,timezone:a.timezone||h,stream:r})})};return{query:(a,r)=>v(a,!1,r).then(S),queryStream:async(a,r,n)=>{var T;const i=await v(a,!0,n);if(typeof r!="function"||!i.body)return i;const U=i.body.getReader(),_=new TextDecoder("utf-8");let c="";const C=async l=>{if(!l&&!c)return;let o=c+l;c="",o.startsWith(y)&&(o=l.substring(y.length)),o.split(y).forEach(async(w,P)=>{const u=w.trim();if(u[u.length-1]!=="}"){c+=P>0?`data: ${w}`:w;return}let g;try{g=JSON.parse(u)}catch{c+=P>0?`data: ${u}`:u}g&&await r(g)})};for(;!((T=n==null?void 0:n.signal)!=null&&T.aborted);){const{value:l,done:o}=await U.read();if(o)break;const f=_.decode(l);f&&await C(f)}return c&&await C(""),i},executeProgram:async(a,r)=>{const n=await b(a.ddn);return await fetch(`${e}execute_program`,{...r,body:JSON.stringify({...a,ai_primitives_llm:a.ai_primitives_llm??d,ddn:n})}).then(S)}}};exports.PromptQLError=m;exports.createPromptQLClient=E;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var z = (t, e, s) => e in t ? S(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var U = (t, e, s) => z(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
class g extends Error {
|
|
5
|
+
constructor(s, h) {
|
|
6
|
+
super(h || s.map((u) => u.msg).join(". "));
|
|
7
|
+
U(this, "detail", []);
|
|
8
|
+
this.detail = s;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const y = "data: ", _ = async (t) => (await j(t), t.json()), j = async (t) => {
|
|
12
|
+
if (t.status > 500) {
|
|
13
|
+
const e = t.body ? await t.text() : t.statusText;
|
|
14
|
+
throw new g([], e);
|
|
15
|
+
}
|
|
16
|
+
if (t.status > 400) {
|
|
17
|
+
const e = t.body ? await t.json() : null;
|
|
18
|
+
throw e != null && e.detail ? new g(e.detail) : new g([
|
|
19
|
+
{
|
|
20
|
+
loc: [],
|
|
21
|
+
msg: t.statusText,
|
|
22
|
+
type: "unknown"
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
}, R = (t) => {
|
|
27
|
+
const e = t.baseUrl ? t.baseUrl[t.baseUrl.length - 1] === "/" ? t.baseUrl : `${t.baseUrl}/` : "https://api.promptql.pro.hasura.io/", s = {
|
|
28
|
+
...t.headers ?? {},
|
|
29
|
+
Authorization: `Bearer ${t.apiKey}`
|
|
30
|
+
}, h = t.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone, u = t.llm ?? {
|
|
31
|
+
provider: "hasura"
|
|
32
|
+
}, b = async (a) => {
|
|
33
|
+
const r = typeof t.ddn == "function" ? await t.ddn() : t.ddn;
|
|
34
|
+
return {
|
|
35
|
+
url: (a == null ? void 0 : a.url) || (r.url.endsWith("/v1/sql") ? r.url : `${r.url}/v1/sql`),
|
|
36
|
+
headers: {
|
|
37
|
+
...(r == null ? void 0 : r.headers) ?? {},
|
|
38
|
+
...(a == null ? void 0 : a.headers) ?? {}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, v = async (a, r, n) => {
|
|
42
|
+
const c = await b(a.ddn);
|
|
43
|
+
return fetch(`${e}query`, {
|
|
44
|
+
...n,
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
...s,
|
|
48
|
+
...n == null ? void 0 : n.headers,
|
|
49
|
+
"Content-Type": "application/json"
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
llm: u,
|
|
53
|
+
...a,
|
|
54
|
+
version: "v1",
|
|
55
|
+
ddn: c,
|
|
56
|
+
timezone: a.timezone || h,
|
|
57
|
+
stream: r
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
query: (a, r) => v(a, !1, r).then(_),
|
|
63
|
+
queryStream: async (a, r, n) => {
|
|
64
|
+
var x;
|
|
65
|
+
const c = await v(a, !0, n);
|
|
66
|
+
if (typeof r != "function" || !c.body)
|
|
67
|
+
return c;
|
|
68
|
+
const $ = c.body.getReader(), P = new TextDecoder("utf-8");
|
|
69
|
+
let i = "";
|
|
70
|
+
const C = async (l) => {
|
|
71
|
+
if (!l && !i)
|
|
72
|
+
return;
|
|
73
|
+
let o = i + l;
|
|
74
|
+
i = "", o.startsWith(y) && (o = l.substring(y.length)), o.split(y).forEach(async (f, T) => {
|
|
75
|
+
const d = f.trim();
|
|
76
|
+
if (d[d.length - 1] !== "}") {
|
|
77
|
+
i += T > 0 ? `data: ${f}` : f;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let w;
|
|
81
|
+
try {
|
|
82
|
+
w = JSON.parse(d);
|
|
83
|
+
} catch {
|
|
84
|
+
i += T > 0 ? `data: ${d}` : d;
|
|
85
|
+
}
|
|
86
|
+
w && await r(w);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
for (; !((x = n == null ? void 0 : n.signal) != null && x.aborted); ) {
|
|
90
|
+
const { value: l, done: o } = await $.read();
|
|
91
|
+
if (o)
|
|
92
|
+
break;
|
|
93
|
+
const m = P.decode(l);
|
|
94
|
+
m && await C(m);
|
|
95
|
+
}
|
|
96
|
+
return i && await C(""), c;
|
|
97
|
+
},
|
|
98
|
+
executeProgram: async (a, r) => {
|
|
99
|
+
const n = await b(a.ddn);
|
|
100
|
+
return await fetch(`${e}execute_program`, {
|
|
101
|
+
...r,
|
|
102
|
+
body: JSON.stringify({
|
|
103
|
+
...a,
|
|
104
|
+
ai_primitives_llm: a.ai_primitives_llm ?? u,
|
|
105
|
+
ddn: n
|
|
106
|
+
})
|
|
107
|
+
}).then(_);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
g as PromptQLError,
|
|
113
|
+
R as createPromptQLClient
|
|
114
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.promptql={}))})(this,function(n){"use strict";var z=Object.defineProperty;var E=(n,a,o)=>a in n?z(n,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[a]=o;var p=(n,a,o)=>E(n,typeof a!="symbol"?a+"":a,o);class a extends Error{constructor(m,w){super(w||m.map(h=>h.msg).join(". "));p(this,"detail",[]);this.detail=m}}const o="data: ",T=async e=>(await U(e),e.json()),U=async e=>{if(e.status>500){const s=e.body?await e.text():e.statusText;throw new a([],s)}if(e.status>400){const s=e.body?await e.json():null;throw s!=null&&s.detail?new a(s.detail):new a([{loc:[],msg:e.statusText,type:"unknown"}])}},_=e=>{const s=e.baseUrl?e.baseUrl[e.baseUrl.length-1]==="/"?e.baseUrl:`${e.baseUrl}/`:"https://api.promptql.pro.hasura.io/",m={...e.headers??{},Authorization:`Bearer ${e.apiKey}`},w=e.timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,h=e.llm??{provider:"hasura"},v=async t=>{const r=typeof e.ddn=="function"?await e.ddn():e.ddn;return{url:(t==null?void 0:t.url)||(r.url.endsWith("/v1/sql")?r.url:`${r.url}/v1/sql`),headers:{...(r==null?void 0:r.headers)??{},...(t==null?void 0:t.headers)??{}}}},C=async(t,r,i)=>{const c=await v(t.ddn);return fetch(`${s}query`,{...i,method:"POST",headers:{...m,...i==null?void 0:i.headers,"Content-Type":"application/json"},body:JSON.stringify({llm:h,...t,version:"v1",ddn:c,timezone:t.timezone||w,stream:r})})};return{query:(t,r)=>C(t,!1,r).then(T),queryStream:async(t,r,i)=>{var P;const c=await C(t,!0,i);if(typeof r!="function"||!c.body)return c;const $=c.body.getReader(),j=new TextDecoder("utf-8");let l="";const x=async d=>{if(!d&&!l)return;let u=l+d;l="",u.startsWith(o)&&(u=d.substring(o.length)),u.split(o).forEach(async(y,S)=>{const f=y.trim();if(f[f.length-1]!=="}"){l+=S>0?`data: ${y}`:y;return}let b;try{b=JSON.parse(f)}catch{l+=S>0?`data: ${f}`:f}b&&await r(b)})};for(;!((P=i==null?void 0:i.signal)!=null&&P.aborted);){const{value:d,done:u}=await $.read();if(u)break;const g=j.decode(d);g&&await x(g)}return l&&await x(""),c},executeProgram:async(t,r)=>{const i=await v(t.ddn);return await fetch(`${s}execute_program`,{...r,body:JSON.stringify({...t,ai_primitives_llm:t.ai_primitives_llm??h,ddn:i})}).then(T)}}};n.PromptQLError=a,n.createPromptQLClient=_,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by openapi-typescript.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type paths = {
|
|
7
|
+
"/execute_program": {
|
|
8
|
+
parameters: {
|
|
9
|
+
query?: never;
|
|
10
|
+
header?: never;
|
|
11
|
+
path?: never;
|
|
12
|
+
cookie?: never;
|
|
13
|
+
};
|
|
14
|
+
get?: never;
|
|
15
|
+
put?: never;
|
|
16
|
+
/** Execute Program */
|
|
17
|
+
post: operations["execute_program_execute_program_post"];
|
|
18
|
+
delete?: never;
|
|
19
|
+
options?: never;
|
|
20
|
+
head?: never;
|
|
21
|
+
patch?: never;
|
|
22
|
+
trace?: never;
|
|
23
|
+
};
|
|
24
|
+
"/query": {
|
|
25
|
+
parameters: {
|
|
26
|
+
query?: never;
|
|
27
|
+
header?: never;
|
|
28
|
+
path?: never;
|
|
29
|
+
cookie?: never;
|
|
30
|
+
};
|
|
31
|
+
get?: never;
|
|
32
|
+
put?: never;
|
|
33
|
+
/** Query */
|
|
34
|
+
post: operations["query_query_post"];
|
|
35
|
+
delete?: never;
|
|
36
|
+
options?: never;
|
|
37
|
+
head?: never;
|
|
38
|
+
patch?: never;
|
|
39
|
+
trace?: never;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export type webhooks = Record<string, never>;
|
|
43
|
+
export type components = {
|
|
44
|
+
schemas: {
|
|
45
|
+
/** ApiAnthropicConfig */
|
|
46
|
+
ApiAnthropicConfig: {
|
|
47
|
+
/**
|
|
48
|
+
* @description discriminator enum property added by openapi-typescript
|
|
49
|
+
* @enum {string}
|
|
50
|
+
*/
|
|
51
|
+
provider: "anthropic";
|
|
52
|
+
/** Model */
|
|
53
|
+
model?: string | null;
|
|
54
|
+
/** Base Url */
|
|
55
|
+
base_url?: string | null;
|
|
56
|
+
/** Api Key */
|
|
57
|
+
api_key: string;
|
|
58
|
+
};
|
|
59
|
+
/** ApiOpenAIConfig */
|
|
60
|
+
ApiOpenAIConfig: {
|
|
61
|
+
/**
|
|
62
|
+
* @description discriminator enum property added by openapi-typescript
|
|
63
|
+
* @enum {string}
|
|
64
|
+
*/
|
|
65
|
+
provider: "openai";
|
|
66
|
+
/** Model */
|
|
67
|
+
model?: string | null;
|
|
68
|
+
/** Base Url */
|
|
69
|
+
base_url?: string | null;
|
|
70
|
+
/** Api Key */
|
|
71
|
+
api_key: string;
|
|
72
|
+
};
|
|
73
|
+
/** AssistantAction */
|
|
74
|
+
AssistantAction: {
|
|
75
|
+
/** Message */
|
|
76
|
+
message?: string | null;
|
|
77
|
+
/** Plan */
|
|
78
|
+
plan?: string | null;
|
|
79
|
+
/** Code */
|
|
80
|
+
code?: string | null;
|
|
81
|
+
/** Code Output */
|
|
82
|
+
code_output?: string | null;
|
|
83
|
+
/** Code Error */
|
|
84
|
+
code_error?: string | null;
|
|
85
|
+
};
|
|
86
|
+
/** DdnConfig */
|
|
87
|
+
DdnConfig: {
|
|
88
|
+
/**
|
|
89
|
+
* Url
|
|
90
|
+
* @description URL of the /sql endpoint on Hasura DDN
|
|
91
|
+
*/
|
|
92
|
+
url: string;
|
|
93
|
+
/**
|
|
94
|
+
* Headers
|
|
95
|
+
* @description HTTP headers that should be forwarded to DDN
|
|
96
|
+
*/
|
|
97
|
+
headers?: {
|
|
98
|
+
[key: string]: string;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/** ExecuteRequest */
|
|
102
|
+
ExecuteRequest: {
|
|
103
|
+
/** Code */
|
|
104
|
+
code: string;
|
|
105
|
+
/**
|
|
106
|
+
* Promptql Api Key
|
|
107
|
+
* @deprecated
|
|
108
|
+
*/
|
|
109
|
+
promptql_api_key?: string | null;
|
|
110
|
+
/** Ai Primitives Llm */
|
|
111
|
+
ai_primitives_llm: (components["schemas"]["HasuraLlmConfig"] | components["schemas"]["ApiOpenAIConfig"] | components["schemas"]["ApiAnthropicConfig"]) | null;
|
|
112
|
+
ddn: components["schemas"]["DdnConfig"] | null;
|
|
113
|
+
/** Artifacts */
|
|
114
|
+
artifacts: (components["schemas"]["TextArtifact"] | components["schemas"]["TableArtifact"] | components["schemas"]["VisualizationArtifact"])[];
|
|
115
|
+
};
|
|
116
|
+
/** HTTPValidationError */
|
|
117
|
+
HTTPValidationError: {
|
|
118
|
+
/** Detail */
|
|
119
|
+
detail?: components["schemas"]["ValidationError"][];
|
|
120
|
+
};
|
|
121
|
+
/** HasuraLlmConfig */
|
|
122
|
+
HasuraLlmConfig: {
|
|
123
|
+
/**
|
|
124
|
+
* @description discriminator enum property added by openapi-typescript
|
|
125
|
+
* @enum {string}
|
|
126
|
+
*/
|
|
127
|
+
provider: "hasura";
|
|
128
|
+
};
|
|
129
|
+
/** Interaction */
|
|
130
|
+
Interaction: {
|
|
131
|
+
user_message: components["schemas"]["UserMessage"];
|
|
132
|
+
/** Assistant Actions */
|
|
133
|
+
assistant_actions?: components["schemas"]["AssistantAction"][];
|
|
134
|
+
};
|
|
135
|
+
/** LlmUsage */
|
|
136
|
+
LlmUsage: {
|
|
137
|
+
/**
|
|
138
|
+
* Provider
|
|
139
|
+
* @default unknown
|
|
140
|
+
*/
|
|
141
|
+
provider: string;
|
|
142
|
+
/**
|
|
143
|
+
* Model
|
|
144
|
+
* @default unknown
|
|
145
|
+
*/
|
|
146
|
+
model: string;
|
|
147
|
+
/**
|
|
148
|
+
* Input Tokens
|
|
149
|
+
* @default 0
|
|
150
|
+
*/
|
|
151
|
+
input_tokens: number;
|
|
152
|
+
/**
|
|
153
|
+
* Output Tokens
|
|
154
|
+
* @default 0
|
|
155
|
+
*/
|
|
156
|
+
output_tokens: number;
|
|
157
|
+
};
|
|
158
|
+
/** PromptQlExecutionResult */
|
|
159
|
+
PromptQlExecutionResult: {
|
|
160
|
+
/** Output */
|
|
161
|
+
output: string;
|
|
162
|
+
/** Error */
|
|
163
|
+
error: string | null;
|
|
164
|
+
/** Accessed Artifact Ids */
|
|
165
|
+
accessed_artifact_ids: string[];
|
|
166
|
+
/** Modified Artifacts */
|
|
167
|
+
modified_artifacts: (components["schemas"]["TextArtifact"] | components["schemas"]["TableArtifact"] | components["schemas"]["VisualizationArtifact"])[];
|
|
168
|
+
/** Llm Usages */
|
|
169
|
+
llm_usages: components["schemas"]["LlmUsage"][];
|
|
170
|
+
};
|
|
171
|
+
/** QueryRequest */
|
|
172
|
+
QueryRequest: {
|
|
173
|
+
/**
|
|
174
|
+
* Version
|
|
175
|
+
* @constant
|
|
176
|
+
*/
|
|
177
|
+
version: "v1";
|
|
178
|
+
/**
|
|
179
|
+
* Promptql Api Key
|
|
180
|
+
* @deprecated
|
|
181
|
+
*/
|
|
182
|
+
promptql_api_key?: string | null;
|
|
183
|
+
/** Llm */
|
|
184
|
+
llm?: components["schemas"]["HasuraLlmConfig"] | components["schemas"]["ApiOpenAIConfig"] | components["schemas"]["ApiAnthropicConfig"];
|
|
185
|
+
/** Ai Primitives Llm */
|
|
186
|
+
ai_primitives_llm?: (components["schemas"]["HasuraLlmConfig"] | components["schemas"]["ApiOpenAIConfig"] | components["schemas"]["ApiAnthropicConfig"]) | null;
|
|
187
|
+
ddn: components["schemas"]["DdnConfig"];
|
|
188
|
+
/** Artifacts */
|
|
189
|
+
artifacts?: (components["schemas"]["TextArtifact"] | components["schemas"]["TableArtifact"] | components["schemas"]["VisualizationArtifact"])[];
|
|
190
|
+
/** System Instructions */
|
|
191
|
+
system_instructions?: string | null;
|
|
192
|
+
/**
|
|
193
|
+
* Timezone
|
|
194
|
+
* @description An IANA timezone used to interpret queries that implicitly require timezones
|
|
195
|
+
*/
|
|
196
|
+
timezone: string;
|
|
197
|
+
/** Interactions */
|
|
198
|
+
interactions: components["schemas"]["Interaction"][];
|
|
199
|
+
/** Stream */
|
|
200
|
+
stream: boolean;
|
|
201
|
+
};
|
|
202
|
+
/** QueryResponse */
|
|
203
|
+
QueryResponse: {
|
|
204
|
+
/** Assistant Actions */
|
|
205
|
+
assistant_actions: components["schemas"]["AssistantAction"][];
|
|
206
|
+
/**
|
|
207
|
+
* Modified Artifacts
|
|
208
|
+
* @description List of artifacts created or updated in this request. May contain duplicate artifact identifiers.
|
|
209
|
+
*/
|
|
210
|
+
modified_artifacts: (components["schemas"]["TextArtifact"] | components["schemas"]["TableArtifact"] | components["schemas"]["VisualizationArtifact"])[];
|
|
211
|
+
};
|
|
212
|
+
/** TableArtifact */
|
|
213
|
+
TableArtifact: {
|
|
214
|
+
/** Identifier */
|
|
215
|
+
identifier: string;
|
|
216
|
+
/** Title */
|
|
217
|
+
title: string;
|
|
218
|
+
/**
|
|
219
|
+
* @description discriminator enum property added by openapi-typescript
|
|
220
|
+
* @enum {string}
|
|
221
|
+
*/
|
|
222
|
+
artifact_type: "table";
|
|
223
|
+
/**
|
|
224
|
+
* Data
|
|
225
|
+
* @description Table data as a list of objects, with the object keys being column names
|
|
226
|
+
*/
|
|
227
|
+
data: {
|
|
228
|
+
[key: string]: unknown;
|
|
229
|
+
}[];
|
|
230
|
+
};
|
|
231
|
+
/** TextArtifact */
|
|
232
|
+
TextArtifact: {
|
|
233
|
+
/** Identifier */
|
|
234
|
+
identifier: string;
|
|
235
|
+
/** Title */
|
|
236
|
+
title: string;
|
|
237
|
+
/**
|
|
238
|
+
* @description discriminator enum property added by openapi-typescript
|
|
239
|
+
* @enum {string}
|
|
240
|
+
*/
|
|
241
|
+
artifact_type: "text";
|
|
242
|
+
/** Data */
|
|
243
|
+
data: string;
|
|
244
|
+
};
|
|
245
|
+
/** UserMessage */
|
|
246
|
+
UserMessage: {
|
|
247
|
+
/** Text */
|
|
248
|
+
text: string;
|
|
249
|
+
};
|
|
250
|
+
/** ValidationError */
|
|
251
|
+
ValidationError: {
|
|
252
|
+
/** Location */
|
|
253
|
+
loc: (string | number)[];
|
|
254
|
+
/** Message */
|
|
255
|
+
msg: string;
|
|
256
|
+
/** Error Type */
|
|
257
|
+
type: string;
|
|
258
|
+
};
|
|
259
|
+
/** VisualizationArtifact */
|
|
260
|
+
VisualizationArtifact: {
|
|
261
|
+
/** Identifier */
|
|
262
|
+
identifier: string;
|
|
263
|
+
/** Title */
|
|
264
|
+
title: string;
|
|
265
|
+
/**
|
|
266
|
+
* @description discriminator enum property added by openapi-typescript
|
|
267
|
+
* @enum {string}
|
|
268
|
+
*/
|
|
269
|
+
artifact_type: "visualization";
|
|
270
|
+
/** @description Visualization data containing HTML and visualization data */
|
|
271
|
+
data: components["schemas"]["VisualizationArtifactData"];
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* VisualizationArtifactData
|
|
275
|
+
* @description Data structure for visualization artifacts containing HTML and associated data.
|
|
276
|
+
*
|
|
277
|
+
* Attributes:
|
|
278
|
+
* html: The HTML markup for rendering the visualization
|
|
279
|
+
* visualization_data: The underlying data used to generate the visualization
|
|
280
|
+
*/
|
|
281
|
+
VisualizationArtifactData: {
|
|
282
|
+
/** Html */
|
|
283
|
+
html: string;
|
|
284
|
+
/** Visualization Data */
|
|
285
|
+
visualization_data: unknown;
|
|
286
|
+
};
|
|
287
|
+
QueryResponseChunk: components["schemas"]["AssistantActionChunk"] | components["schemas"]["ArtifactUpdateChunk"] | components["schemas"]["ErrorChunk"];
|
|
288
|
+
/** ArtifactUpdateChunk */
|
|
289
|
+
ArtifactUpdateChunk: {
|
|
290
|
+
/**
|
|
291
|
+
* @description discriminator enum property added by openapi-typescript
|
|
292
|
+
* @enum {string}
|
|
293
|
+
*/
|
|
294
|
+
type: "artifact_update_chunk";
|
|
295
|
+
/** Artifact */
|
|
296
|
+
artifact: components["schemas"]["TextArtifact"] | components["schemas"]["TableArtifact"] | components["schemas"]["VisualizationArtifact"];
|
|
297
|
+
};
|
|
298
|
+
/** AssistantActionChunk */
|
|
299
|
+
AssistantActionChunk: {
|
|
300
|
+
/**
|
|
301
|
+
* Message
|
|
302
|
+
* @default null
|
|
303
|
+
*/
|
|
304
|
+
message: string | null;
|
|
305
|
+
/**
|
|
306
|
+
* Plan
|
|
307
|
+
* @default null
|
|
308
|
+
*/
|
|
309
|
+
plan: string | null;
|
|
310
|
+
/**
|
|
311
|
+
* Code
|
|
312
|
+
* @default null
|
|
313
|
+
*/
|
|
314
|
+
code: string | null;
|
|
315
|
+
/**
|
|
316
|
+
* Code Output
|
|
317
|
+
* @default null
|
|
318
|
+
*/
|
|
319
|
+
code_output: string | null;
|
|
320
|
+
/**
|
|
321
|
+
* Code Error
|
|
322
|
+
* @default null
|
|
323
|
+
*/
|
|
324
|
+
code_error: string | null;
|
|
325
|
+
/**
|
|
326
|
+
* @description discriminator enum property added by openapi-typescript
|
|
327
|
+
* @enum {string}
|
|
328
|
+
*/
|
|
329
|
+
type: "assistant_action_chunk";
|
|
330
|
+
/** Index */
|
|
331
|
+
index: number;
|
|
332
|
+
};
|
|
333
|
+
/** ErrorChunk */
|
|
334
|
+
ErrorChunk: {
|
|
335
|
+
/**
|
|
336
|
+
* @description discriminator enum property added by openapi-typescript
|
|
337
|
+
* @enum {string}
|
|
338
|
+
*/
|
|
339
|
+
type: "error_chunk";
|
|
340
|
+
/** Error */
|
|
341
|
+
error: string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
responses: never;
|
|
345
|
+
parameters: never;
|
|
346
|
+
requestBodies: never;
|
|
347
|
+
headers: never;
|
|
348
|
+
pathItems: never;
|
|
349
|
+
};
|
|
350
|
+
export type ApiAnthropicConfig = components['schemas']['ApiAnthropicConfig'];
|
|
351
|
+
export type ApiOpenAiConfig = components['schemas']['ApiOpenAIConfig'];
|
|
352
|
+
export type AssistantAction = components['schemas']['AssistantAction'];
|
|
353
|
+
export type DdnConfig = components['schemas']['DdnConfig'];
|
|
354
|
+
export type ExecuteRequest = components['schemas']['ExecuteRequest'];
|
|
355
|
+
export type HttpValidationError = components['schemas']['HTTPValidationError'];
|
|
356
|
+
export type HasuraLlmConfig = components['schemas']['HasuraLlmConfig'];
|
|
357
|
+
export type Interaction = components['schemas']['Interaction'];
|
|
358
|
+
export type LlmUsage = components['schemas']['LlmUsage'];
|
|
359
|
+
export type PromptQlExecutionResult = components['schemas']['PromptQlExecutionResult'];
|
|
360
|
+
export type QueryRequest = components['schemas']['QueryRequest'];
|
|
361
|
+
export type QueryResponse = components['schemas']['QueryResponse'];
|
|
362
|
+
export type TableArtifact = components['schemas']['TableArtifact'];
|
|
363
|
+
export type TextArtifact = components['schemas']['TextArtifact'];
|
|
364
|
+
export type UserMessage = components['schemas']['UserMessage'];
|
|
365
|
+
export type ValidationError = components['schemas']['ValidationError'];
|
|
366
|
+
export type VisualizationArtifact = components['schemas']['VisualizationArtifact'];
|
|
367
|
+
export type VisualizationArtifactData = components['schemas']['VisualizationArtifactData'];
|
|
368
|
+
export type QueryResponseChunk = components['schemas']['QueryResponseChunk'];
|
|
369
|
+
export type ArtifactUpdateChunk = components['schemas']['ArtifactUpdateChunk'];
|
|
370
|
+
export type AssistantActionChunk = components['schemas']['AssistantActionChunk'];
|
|
371
|
+
export type ErrorChunk = components['schemas']['ErrorChunk'];
|
|
372
|
+
export type $defs = Record<string, never>;
|
|
373
|
+
export interface operations {
|
|
374
|
+
execute_program_execute_program_post: {
|
|
375
|
+
parameters: {
|
|
376
|
+
query?: never;
|
|
377
|
+
header?: never;
|
|
378
|
+
path?: never;
|
|
379
|
+
cookie?: never;
|
|
380
|
+
};
|
|
381
|
+
requestBody: {
|
|
382
|
+
content: {
|
|
383
|
+
"application/json": components["schemas"]["ExecuteRequest"];
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
responses: {
|
|
387
|
+
/** @description Successful Response */
|
|
388
|
+
200: {
|
|
389
|
+
headers: {
|
|
390
|
+
[name: string]: unknown;
|
|
391
|
+
};
|
|
392
|
+
content: {
|
|
393
|
+
"application/json": components["schemas"]["PromptQlExecutionResult"];
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
/** @description Validation Error */
|
|
397
|
+
422: {
|
|
398
|
+
headers: {
|
|
399
|
+
[name: string]: unknown;
|
|
400
|
+
};
|
|
401
|
+
content: {
|
|
402
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
query_query_post: {
|
|
408
|
+
parameters: {
|
|
409
|
+
query?: never;
|
|
410
|
+
header?: never;
|
|
411
|
+
path?: never;
|
|
412
|
+
cookie?: never;
|
|
413
|
+
};
|
|
414
|
+
requestBody: {
|
|
415
|
+
content: {
|
|
416
|
+
"application/json": components["schemas"]["QueryRequest"];
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
responses: {
|
|
420
|
+
/** @description Either a JSON response (QueryResponse object) or a stream of Server-Sent Events (SSE) (QueryResponseChunk objects) depending on whether the 'stream' parameter was set */
|
|
421
|
+
200: {
|
|
422
|
+
headers: {
|
|
423
|
+
[name: string]: unknown;
|
|
424
|
+
};
|
|
425
|
+
content: {
|
|
426
|
+
"application/json": components["schemas"]["QueryResponse"];
|
|
427
|
+
"text/event-stream": components["schemas"]["QueryResponseChunk"];
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
/** @description Validation Error */
|
|
431
|
+
422: {
|
|
432
|
+
headers: {
|
|
433
|
+
[name: string]: unknown;
|
|
434
|
+
};
|
|
435
|
+
content: {
|
|
436
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IncomingHttpHeaders } from 'node:http';
|
|
2
|
+
import { ApiAnthropicConfig, ApiOpenAiConfig, DdnConfig, ExecuteRequest, HasuraLlmConfig, PromptQlExecutionResult, QueryRequest, QueryResponse, QueryResponseChunk, TableArtifact, TextArtifact, ValidationError, VisualizationArtifact } from './promptql';
|
|
3
|
+
/**
|
|
4
|
+
* PromptQL client config contains common settings to connect the PromptQL API.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @typedef {PromptQLClientOptions}
|
|
8
|
+
*/
|
|
9
|
+
export type PromptQLClientConfig = {
|
|
10
|
+
/**
|
|
11
|
+
* PromptQL API key created from project settings.
|
|
12
|
+
*
|
|
13
|
+
* @type {string}
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* DDN configuration including URL and headers.
|
|
18
|
+
*
|
|
19
|
+
* @type {(DdnConfig | (() => DdnConfig | Promise<DdnConfig>))}
|
|
20
|
+
*/
|
|
21
|
+
ddn: DdnConfig | (() => DdnConfig | Promise<DdnConfig>);
|
|
22
|
+
/**
|
|
23
|
+
* The optional base URL of PromptQL API. The default value is the endpoint to the public DDN.
|
|
24
|
+
*
|
|
25
|
+
* @type {?string}
|
|
26
|
+
*/
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Custom headers to be injected into requests.
|
|
30
|
+
*
|
|
31
|
+
* @type {?IncomingHttpHeaders}
|
|
32
|
+
*/
|
|
33
|
+
headers?: IncomingHttpHeaders;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for the main LLM provider.
|
|
36
|
+
*
|
|
37
|
+
* @type {?(HasuraLlmConfig | ApiOpenAiConfig | ApiAnthropicConfig)}
|
|
38
|
+
*/
|
|
39
|
+
llm?: HasuraLlmConfig | ApiOpenAiConfig | ApiAnthropicConfig;
|
|
40
|
+
/**
|
|
41
|
+
* An [IANA timezone](https://data.iana.org/time-zones/tzdb-2021a/zone1970.tab) for interpreting time-based queries. Default is the system timezone.
|
|
42
|
+
*
|
|
43
|
+
* @type {?string}
|
|
44
|
+
*/
|
|
45
|
+
timezone?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A simple http client wrapper for [PromptQL API](https://hasura.io/docs/promptql/promptql-apis/overview/).
|
|
49
|
+
*
|
|
50
|
+
* @export
|
|
51
|
+
* @typedef {PromptQLClient}
|
|
52
|
+
*/
|
|
53
|
+
export type PromptQLClient = {
|
|
54
|
+
/**
|
|
55
|
+
* The [Natural Language Query API](https://hasura.io/docs/promptql/promptql-apis/natural-language-api/) allows you to interact with PromptQL directly, sending messages and receiving responses.
|
|
56
|
+
* The response is non-streaming.
|
|
57
|
+
*
|
|
58
|
+
* @param {PromptQLQueryRequest} body
|
|
59
|
+
* @param {?FetchOptions} [queryOptions]
|
|
60
|
+
* @returns {Promise<QueryResponse>}
|
|
61
|
+
*/
|
|
62
|
+
query: (body: PromptQLQueryRequest, queryOptions?: FetchOptions) => Promise<QueryResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* The streaming response sends chunks of data in Server-Sent Events (SSE) format.
|
|
65
|
+
* If the callback isn't set the client returns the raw response and you need to handle the response manually.
|
|
66
|
+
*
|
|
67
|
+
* @param {PromptQLQueryRequest} body
|
|
68
|
+
* @param {?(data: QueryResponseChunk) => void} callback
|
|
69
|
+
* @param {?FetchOptions} [queryOptions]
|
|
70
|
+
* @returns {Promise<Response>}
|
|
71
|
+
*/
|
|
72
|
+
queryStream: (body: PromptQLQueryRequest, callback?: (data: QueryResponseChunk) => void | Promise<void>, queryOptions?: FetchOptions) => Promise<Response>;
|
|
73
|
+
/**
|
|
74
|
+
* Execute a PromptQL program with your data.
|
|
75
|
+
*
|
|
76
|
+
* @async
|
|
77
|
+
* @param {PromptQLExecuteRequest} body
|
|
78
|
+
* @param {?FetchOptions} [executeOptions]
|
|
79
|
+
* @returns {Promise<PromptQlExecutionResult>}
|
|
80
|
+
*/
|
|
81
|
+
executeProgram: (body: PromptQLExecuteRequest, executeOptions?: FetchOptions) => Promise<PromptQlExecutionResult>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* PromptQL artifacts are stores of data and can be referenced from PromptQL programs. PromptQL programs can create artifacts.
|
|
85
|
+
*
|
|
86
|
+
* @export
|
|
87
|
+
* @typedef {Artifact}
|
|
88
|
+
*/
|
|
89
|
+
export type Artifact = TextArtifact | TableArtifact | VisualizationArtifact;
|
|
90
|
+
/**
|
|
91
|
+
* The request body to the [Natural Language Query API](https://hasura.io/docs/promptql/promptql-apis/natural-language-api/).
|
|
92
|
+
*
|
|
93
|
+
* @export
|
|
94
|
+
* @typedef {PromptQLQueryRequest}
|
|
95
|
+
*/
|
|
96
|
+
export type PromptQLQueryRequest = Omit<QueryRequest, 'timezone' | 'ddn' | 'version' | 'stream'> & {
|
|
97
|
+
/**
|
|
98
|
+
* An [IANA timezone](https://data.iana.org/time-zones/tzdb-2021a/zone1970.tab) for interpreting time-based queries. Default is the timezone from the client config.
|
|
99
|
+
*
|
|
100
|
+
* @type {?string}
|
|
101
|
+
*/
|
|
102
|
+
readonly timezone?: string;
|
|
103
|
+
/**
|
|
104
|
+
* DDN configuration including URL and headers. Used to override the default client settings.
|
|
105
|
+
*
|
|
106
|
+
* @readonly
|
|
107
|
+
* @type {?Partial<DdnConfig>}
|
|
108
|
+
*/
|
|
109
|
+
readonly ddn?: Partial<DdnConfig>;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Optional fetch options to the PromptQL API.
|
|
113
|
+
*
|
|
114
|
+
* @export
|
|
115
|
+
* @typedef {FetchOptions}
|
|
116
|
+
*/
|
|
117
|
+
export type FetchOptions = Omit<RequestInit, 'method' | 'body'>;
|
|
118
|
+
/**
|
|
119
|
+
* The request body to the [Execute Program API](https://hasura.io/docs/promptql/promptql-apis/execute-program-api/).
|
|
120
|
+
*
|
|
121
|
+
* @export
|
|
122
|
+
* @typedef {PromptQLExecuteRequest}
|
|
123
|
+
*/
|
|
124
|
+
export type PromptQLExecuteRequest = Omit<ExecuteRequest, 'ddn' | 'version'> & {
|
|
125
|
+
/**
|
|
126
|
+
* DDN configuration including URL and headers. Used to override the default client settings.
|
|
127
|
+
*
|
|
128
|
+
* @readonly
|
|
129
|
+
* @type {?Partial<DdnConfig>}
|
|
130
|
+
*/
|
|
131
|
+
readonly ddn?: Partial<DdnConfig>;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A general GraphQL error that is retrieved from the PromptQL server.
|
|
135
|
+
*
|
|
136
|
+
* @export
|
|
137
|
+
* @class PromptQLError
|
|
138
|
+
* @typedef {PromptQLError}
|
|
139
|
+
* @extends {Error}
|
|
140
|
+
*/
|
|
141
|
+
export declare class PromptQLError extends Error {
|
|
142
|
+
detail: ValidationError[];
|
|
143
|
+
constructor(detail: ValidationError[], message?: string);
|
|
144
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DATA_CHUNK_PREFIX = "data: ";
|
|
2
|
+
/**
|
|
3
|
+
* Decode the response as JSON.
|
|
4
|
+
*
|
|
5
|
+
* @async
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {Response} response
|
|
8
|
+
* @returns {Promise<T>}
|
|
9
|
+
*/
|
|
10
|
+
export declare const decodeResponseJson: <T>(response: Response) => Promise<T>;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hasura/promptql",
|
|
3
|
+
"description": "A Node.js SDK allows you to interact with PromptQL API",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"author": "Hasura",
|
|
13
|
+
"homepage": "https://promptql.hasura.io",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/hasura/promptql-nodejs-sdk.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/hasura/promptql-nodejs-sdk/issues"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"promptql",
|
|
23
|
+
"api",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"copy-files": "cp ./src/promptql.d.ts ./dist/promptql.d.ts",
|
|
28
|
+
"build": "tsc && vite build && npm run copy-files",
|
|
29
|
+
"release": "npm run test && changelogen --release --push && npm publish",
|
|
30
|
+
"lint": "biome check",
|
|
31
|
+
"lint:fix": "biome check --write",
|
|
32
|
+
"format": "biome format --write",
|
|
33
|
+
"test": "vitest --run",
|
|
34
|
+
"test:coverage": "vitest --coverage",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
36
|
+
"openapi:ts": "openapi-typescript https://api.promptql.pro.hasura.io/openapi.json --export-type --root-types-no-schema-prefix --root-types -o ./src/promptql.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/**/*"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"openapi-typescript": "^7.6.1",
|
|
44
|
+
"@types/node": "^22.14.1",
|
|
45
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
46
|
+
"@biomejs/biome": "1.9.4",
|
|
47
|
+
"changelogen": "^0.6.1",
|
|
48
|
+
"typescript": "^5.8.3",
|
|
49
|
+
"vite": "^6.2.6",
|
|
50
|
+
"vite-plugin-dts": "^4.5.3",
|
|
51
|
+
"vitest": "^3.1.1"
|
|
52
|
+
}
|
|
53
|
+
}
|