@honcho-ai/core 1.0.0

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.
Files changed (277) hide show
  1. package/CHANGELOG.md +344 -0
  2. package/LICENSE +201 -0
  3. package/README.md +322 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +83 -0
  45. package/_shims/index.js +17 -0
  46. package/_shims/index.mjs +11 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +255 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +922 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +890 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +47 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +113 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +97 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +134 -0
  87. package/index.d.ts +134 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +141 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +98 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +103 -0
  94. package/pagination.d.ts +30 -0
  95. package/pagination.d.ts.map +1 -0
  96. package/pagination.js +39 -0
  97. package/pagination.js.map +1 -0
  98. package/pagination.mjs +35 -0
  99. package/pagination.mjs.map +1 -0
  100. package/resource.d.ts +6 -0
  101. package/resource.d.ts.map +1 -0
  102. package/resource.js +11 -0
  103. package/resource.js.map +1 -0
  104. package/resource.mjs +7 -0
  105. package/resource.mjs.map +1 -0
  106. package/resources/index.d.ts +3 -0
  107. package/resources/index.d.ts.map +1 -0
  108. package/resources/index.js +10 -0
  109. package/resources/index.js.map +1 -0
  110. package/resources/index.mjs +4 -0
  111. package/resources/index.mjs.map +1 -0
  112. package/resources/keys.d.ts +29 -0
  113. package/resources/keys.d.ts.map +1 -0
  114. package/resources/keys.js +20 -0
  115. package/resources/keys.js.map +1 -0
  116. package/resources/keys.mjs +16 -0
  117. package/resources/keys.mjs.map +1 -0
  118. package/resources/workspaces/index.d.ts +4 -0
  119. package/resources/workspaces/index.d.ts.map +1 -0
  120. package/resources/workspaces/index.js +14 -0
  121. package/resources/workspaces/index.js.map +1 -0
  122. package/resources/workspaces/index.mjs +5 -0
  123. package/resources/workspaces/index.mjs.map +1 -0
  124. package/resources/workspaces/peers/index.d.ts +4 -0
  125. package/resources/workspaces/peers/index.d.ts.map +1 -0
  126. package/resources/workspaces/peers/index.js +12 -0
  127. package/resources/workspaces/peers/index.js.map +1 -0
  128. package/resources/workspaces/peers/index.mjs +5 -0
  129. package/resources/workspaces/peers/index.mjs.map +1 -0
  130. package/resources/workspaces/peers/messages.d.ts +35 -0
  131. package/resources/workspaces/peers/messages.d.ts.map +1 -0
  132. package/resources/workspaces/peers/messages.js +25 -0
  133. package/resources/workspaces/peers/messages.js.map +1 -0
  134. package/resources/workspaces/peers/messages.mjs +21 -0
  135. package/resources/workspaces/peers/messages.mjs.map +1 -0
  136. package/resources/workspaces/peers/peers.d.ts +120 -0
  137. package/resources/workspaces/peers/peers.d.ts.map +1 -0
  138. package/resources/workspaces/peers/peers.js +108 -0
  139. package/resources/workspaces/peers/peers.js.map +1 -0
  140. package/resources/workspaces/peers/peers.mjs +80 -0
  141. package/resources/workspaces/peers/peers.mjs.map +1 -0
  142. package/resources/workspaces/peers/sessions.d.ts +27 -0
  143. package/resources/workspaces/peers/sessions.d.ts.map +1 -0
  144. package/resources/workspaces/peers/sessions.js +24 -0
  145. package/resources/workspaces/peers/sessions.js.map +1 -0
  146. package/resources/workspaces/peers/sessions.mjs +20 -0
  147. package/resources/workspaces/peers/sessions.mjs.map +1 -0
  148. package/resources/workspaces/peers.d.ts +2 -0
  149. package/resources/workspaces/peers.d.ts.map +1 -0
  150. package/resources/workspaces/peers.js +19 -0
  151. package/resources/workspaces/peers.js.map +1 -0
  152. package/resources/workspaces/peers.mjs +3 -0
  153. package/resources/workspaces/peers.mjs.map +1 -0
  154. package/resources/workspaces/sessions/index.d.ts +4 -0
  155. package/resources/workspaces/sessions/index.d.ts.map +1 -0
  156. package/resources/workspaces/sessions/index.js +13 -0
  157. package/resources/workspaces/sessions/index.js.map +1 -0
  158. package/resources/workspaces/sessions/index.mjs +5 -0
  159. package/resources/workspaces/sessions/index.mjs.map +1 -0
  160. package/resources/workspaces/sessions/messages.d.ts +60 -0
  161. package/resources/workspaces/sessions/messages.d.ts.map +1 -0
  162. package/resources/workspaces/sessions/messages.js +46 -0
  163. package/resources/workspaces/sessions/messages.js.map +1 -0
  164. package/resources/workspaces/sessions/messages.mjs +41 -0
  165. package/resources/workspaces/sessions/messages.mjs.map +1 -0
  166. package/resources/workspaces/sessions/peers.d.ts +96 -0
  167. package/resources/workspaces/sessions/peers.d.ts.map +1 -0
  168. package/resources/workspaces/sessions/peers.js +63 -0
  169. package/resources/workspaces/sessions/peers.js.map +1 -0
  170. package/resources/workspaces/sessions/peers.mjs +59 -0
  171. package/resources/workspaces/sessions/peers.mjs.map +1 -0
  172. package/resources/workspaces/sessions/sessions.d.ts +129 -0
  173. package/resources/workspaces/sessions/sessions.d.ts.map +1 -0
  174. package/resources/workspaces/sessions/sessions.js +110 -0
  175. package/resources/workspaces/sessions/sessions.js.map +1 -0
  176. package/resources/workspaces/sessions/sessions.mjs +82 -0
  177. package/resources/workspaces/sessions/sessions.mjs.map +1 -0
  178. package/resources/workspaces/sessions.d.ts +2 -0
  179. package/resources/workspaces/sessions.d.ts.map +1 -0
  180. package/resources/workspaces/sessions.js +19 -0
  181. package/resources/workspaces/sessions.js.map +1 -0
  182. package/resources/workspaces/sessions.mjs +3 -0
  183. package/resources/workspaces/sessions.mjs.map +1 -0
  184. package/resources/workspaces/workspaces.d.ts +69 -0
  185. package/resources/workspaces/workspaces.d.ts.map +1 -0
  186. package/resources/workspaces/workspaces.js +92 -0
  187. package/resources/workspaces/workspaces.js.map +1 -0
  188. package/resources/workspaces/workspaces.mjs +64 -0
  189. package/resources/workspaces/workspaces.mjs.map +1 -0
  190. package/resources/workspaces.d.ts +2 -0
  191. package/resources/workspaces.d.ts.map +1 -0
  192. package/resources/workspaces.js +19 -0
  193. package/resources/workspaces.js.map +1 -0
  194. package/resources/workspaces.mjs +3 -0
  195. package/resources/workspaces.mjs.map +1 -0
  196. package/resources.d.ts +2 -0
  197. package/resources.d.ts.map +1 -0
  198. package/resources.js +18 -0
  199. package/resources.js.map +1 -0
  200. package/resources.mjs +2 -0
  201. package/resources.mjs.map +1 -0
  202. package/shims/node.d.ts +30 -0
  203. package/shims/node.d.ts.map +1 -0
  204. package/shims/node.js +31 -0
  205. package/shims/node.js.map +1 -0
  206. package/shims/node.mjs +5 -0
  207. package/shims/node.mjs.map +1 -0
  208. package/shims/web.d.ts +26 -0
  209. package/shims/web.d.ts.map +1 -0
  210. package/shims/web.js +31 -0
  211. package/shims/web.js.map +1 -0
  212. package/shims/web.mjs +5 -0
  213. package/shims/web.mjs.map +1 -0
  214. package/src/_shims/MultipartBody.ts +9 -0
  215. package/src/_shims/README.md +46 -0
  216. package/src/_shims/auto/runtime-bun.ts +4 -0
  217. package/src/_shims/auto/runtime-node.ts +4 -0
  218. package/src/_shims/auto/runtime.ts +4 -0
  219. package/src/_shims/auto/types-node.ts +4 -0
  220. package/src/_shims/auto/types.d.ts +101 -0
  221. package/src/_shims/auto/types.js +3 -0
  222. package/src/_shims/auto/types.mjs +3 -0
  223. package/src/_shims/bun-runtime.ts +14 -0
  224. package/src/_shims/index.d.ts +83 -0
  225. package/src/_shims/index.js +17 -0
  226. package/src/_shims/index.mjs +11 -0
  227. package/src/_shims/manual-types.d.ts +12 -0
  228. package/src/_shims/manual-types.js +3 -0
  229. package/src/_shims/manual-types.mjs +3 -0
  230. package/src/_shims/node-runtime.ts +81 -0
  231. package/src/_shims/node-types.d.ts +42 -0
  232. package/src/_shims/node-types.js +3 -0
  233. package/src/_shims/node-types.mjs +3 -0
  234. package/src/_shims/registry.ts +67 -0
  235. package/src/_shims/web-runtime.ts +103 -0
  236. package/src/_shims/web-types.d.ts +83 -0
  237. package/src/_shims/web-types.js +3 -0
  238. package/src/_shims/web-types.mjs +3 -0
  239. package/src/core.ts +1234 -0
  240. package/src/error.ts +130 -0
  241. package/src/index.ts +246 -0
  242. package/src/lib/.keep +4 -0
  243. package/src/pagination.ts +73 -0
  244. package/src/resource.ts +11 -0
  245. package/src/resources/index.ts +12 -0
  246. package/src/resources/keys.ts +51 -0
  247. package/src/resources/workspaces/index.ts +39 -0
  248. package/src/resources/workspaces/peers/index.ts +24 -0
  249. package/src/resources/workspaces/peers/messages.ts +81 -0
  250. package/src/resources/workspaces/peers/peers.ts +245 -0
  251. package/src/resources/workspaces/peers/sessions.ts +60 -0
  252. package/src/resources/workspaces/peers.ts +3 -0
  253. package/src/resources/workspaces/sessions/index.ts +35 -0
  254. package/src/resources/workspaces/sessions/messages.ts +149 -0
  255. package/src/resources/workspaces/sessions/peers.ts +200 -0
  256. package/src/resources/workspaces/sessions/sessions.ts +308 -0
  257. package/src/resources/workspaces/sessions.ts +3 -0
  258. package/src/resources/workspaces/workspaces.ts +194 -0
  259. package/src/resources/workspaces.ts +3 -0
  260. package/src/resources.ts +1 -0
  261. package/src/shims/node.ts +50 -0
  262. package/src/shims/web.ts +50 -0
  263. package/src/tsconfig.json +11 -0
  264. package/src/uploads.ts +255 -0
  265. package/src/version.ts +1 -0
  266. package/uploads.d.ts +75 -0
  267. package/uploads.d.ts.map +1 -0
  268. package/uploads.js +171 -0
  269. package/uploads.js.map +1 -0
  270. package/uploads.mjs +158 -0
  271. package/uploads.mjs.map +1 -0
  272. package/version.d.ts +2 -0
  273. package/version.d.ts.map +1 -0
  274. package/version.js +5 -0
  275. package/version.js.map +1 -0
  276. package/version.mjs +2 -0
  277. package/version.mjs.map +1 -0
package/src/error.ts ADDED
@@ -0,0 +1,130 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError, Headers } from "./core.js";
4
+
5
+ export class HonchoError extends Error {}
6
+
7
+ export class APIError<
8
+ TStatus extends number | undefined = number | undefined,
9
+ THeaders extends Headers | undefined = Headers | undefined,
10
+ TError extends Object | undefined = Object | undefined,
11
+ > extends HonchoError {
12
+ /** HTTP status for the response that caused the error */
13
+ readonly status: TStatus;
14
+ /** HTTP headers for the response that caused the error */
15
+ readonly headers: THeaders;
16
+ /** JSON body of the response that caused the error */
17
+ readonly error: TError;
18
+
19
+ constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
20
+ super(`${APIError.makeMessage(status, error, message)}`);
21
+ this.status = status;
22
+ this.headers = headers;
23
+ this.error = error;
24
+ }
25
+
26
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
27
+ const msg =
28
+ error?.message ?
29
+ typeof error.message === 'string' ?
30
+ error.message
31
+ : JSON.stringify(error.message)
32
+ : error ? JSON.stringify(error)
33
+ : message;
34
+
35
+ if (status && msg) {
36
+ return `${status} ${msg}`;
37
+ }
38
+ if (status) {
39
+ return `${status} status code (no body)`;
40
+ }
41
+ if (msg) {
42
+ return msg;
43
+ }
44
+ return '(no status code or body)';
45
+ }
46
+
47
+ static generate(
48
+ status: number | undefined,
49
+ errorResponse: Object | undefined,
50
+ message: string | undefined,
51
+ headers: Headers | undefined,
52
+ ): APIError {
53
+ if (!status || !headers) {
54
+ return new APIConnectionError({ message, cause: castToError(errorResponse) });
55
+ }
56
+
57
+ const error = errorResponse as Record<string, any>;
58
+
59
+ if (status === 400) {
60
+ return new BadRequestError(status, error, message, headers);
61
+ }
62
+
63
+ if (status === 401) {
64
+ return new AuthenticationError(status, error, message, headers);
65
+ }
66
+
67
+ if (status === 403) {
68
+ return new PermissionDeniedError(status, error, message, headers);
69
+ }
70
+
71
+ if (status === 404) {
72
+ return new NotFoundError(status, error, message, headers);
73
+ }
74
+
75
+ if (status === 409) {
76
+ return new ConflictError(status, error, message, headers);
77
+ }
78
+
79
+ if (status === 422) {
80
+ return new UnprocessableEntityError(status, error, message, headers);
81
+ }
82
+
83
+ if (status === 429) {
84
+ return new RateLimitError(status, error, message, headers);
85
+ }
86
+
87
+ if (status >= 500) {
88
+ return new InternalServerError(status, error, message, headers);
89
+ }
90
+
91
+ return new APIError(status, error, message, headers);
92
+ }
93
+ }
94
+
95
+ export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError<undefined, undefined, undefined> {
102
+ constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
103
+ super(undefined, undefined, message || 'Connection error.', undefined);
104
+ // in some environments the 'cause' property is already declared
105
+ // @ts-ignore
106
+ if (cause) this.cause = cause;
107
+ }
108
+ }
109
+
110
+ export class APIConnectionTimeoutError extends APIConnectionError {
111
+ constructor({ message }: { message?: string } = {}) {
112
+ super({ message: message ?? 'Request timed out.' });
113
+ }
114
+ }
115
+
116
+ export class BadRequestError extends APIError<400, Headers> {}
117
+
118
+ export class AuthenticationError extends APIError<401, Headers> {}
119
+
120
+ export class PermissionDeniedError extends APIError<403, Headers> {}
121
+
122
+ export class NotFoundError extends APIError<404, Headers> {}
123
+
124
+ export class ConflictError extends APIError<409, Headers> {}
125
+
126
+ export class UnprocessableEntityError extends APIError<422, Headers> {}
127
+
128
+ export class RateLimitError extends APIError<429, Headers> {}
129
+
130
+ export class InternalServerError extends APIError<number, Headers> {}
package/src/index.ts ADDED
@@ -0,0 +1,246 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { type Agent } from "./_shims/index.js";
4
+ import * as Core from "./core.js";
5
+ import * as Errors from "./error.js";
6
+ import * as Pagination from "./pagination.js";
7
+ import { type PageParams, PageResponse } from "./pagination.js";
8
+ import * as Uploads from "./uploads.js";
9
+ import * as API from "./resources/index.js";
10
+ import { KeyCreateParams, KeyCreateResponse, Keys } from "./resources/keys.js";
11
+ import {
12
+ Workspace,
13
+ WorkspaceGetOrCreateParams,
14
+ WorkspaceListParams,
15
+ WorkspaceSearchParams,
16
+ WorkspaceUpdateParams,
17
+ Workspaces,
18
+ WorkspacesPage,
19
+ } from "./resources/workspaces/workspaces.js";
20
+
21
+ const environments = {
22
+ demo: 'https://demo.honcho.dev',
23
+ local: 'http://localhost:8000',
24
+ production: 'https://api.honcho.dev',
25
+ };
26
+ type Environment = keyof typeof environments;
27
+
28
+ export interface ClientOptions {
29
+ /**
30
+ * Defaults to process.env['HONCHO_API_KEY'].
31
+ */
32
+ apiKey?: string | null | undefined;
33
+
34
+ /**
35
+ * Specifies the environment to use for the API.
36
+ *
37
+ * Each environment maps to a different base URL:
38
+ * - `demo` corresponds to `https://demo.honcho.dev`
39
+ * - `local` corresponds to `http://localhost:8000`
40
+ * - `production` corresponds to `https://api.honcho.dev`
41
+ */
42
+ environment?: Environment | undefined;
43
+
44
+ /**
45
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
46
+ *
47
+ * Defaults to process.env['HONCHO_BASE_URL'].
48
+ */
49
+ baseURL?: string | null | undefined;
50
+
51
+ /**
52
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
53
+ * from the server before timing out a single request.
54
+ *
55
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
56
+ * much longer than this timeout before the promise succeeds or fails.
57
+ */
58
+ timeout?: number | undefined;
59
+
60
+ /**
61
+ * An HTTP agent used to manage HTTP(S) connections.
62
+ *
63
+ * If not provided, an agent will be constructed by default in the Node.js environment,
64
+ * otherwise no agent is used.
65
+ */
66
+ httpAgent?: Agent | undefined;
67
+
68
+ /**
69
+ * Specify a custom `fetch` function implementation.
70
+ *
71
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
72
+ * defined globally.
73
+ */
74
+ fetch?: Core.Fetch | undefined;
75
+
76
+ /**
77
+ * The maximum number of times that the client will retry a request in case of a
78
+ * temporary failure, like a network error or a 5XX error from the server.
79
+ *
80
+ * @default 2
81
+ */
82
+ maxRetries?: number | undefined;
83
+
84
+ /**
85
+ * Default headers to include with every request to the API.
86
+ *
87
+ * These can be removed in individual requests by explicitly setting the
88
+ * header to `undefined` or `null` in request options.
89
+ */
90
+ defaultHeaders?: Core.Headers | undefined;
91
+
92
+ /**
93
+ * Default query parameters to include with every request to the API.
94
+ *
95
+ * These can be removed in individual requests by explicitly setting the
96
+ * param to `undefined` in request options.
97
+ */
98
+ defaultQuery?: Core.DefaultQuery | undefined;
99
+ }
100
+
101
+ /**
102
+ * API Client for interfacing with the Honcho API.
103
+ */
104
+ export class Honcho extends Core.APIClient {
105
+ apiKey: string | null;
106
+
107
+ private _options: ClientOptions;
108
+
109
+ /**
110
+ * API Client for interfacing with the Honcho API.
111
+ *
112
+ * @param {string | null | undefined} [opts.apiKey=process.env['HONCHO_API_KEY'] ?? null]
113
+ * @param {Environment} [opts.environment=demo] - Specifies the environment URL to use for the API.
114
+ * @param {string} [opts.baseURL=process.env['HONCHO_BASE_URL'] ?? https://demo.honcho.dev] - Override the default base URL for the API.
115
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
116
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
117
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
118
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
119
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
120
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
121
+ */
122
+ constructor({
123
+ baseURL = Core.readEnv('HONCHO_BASE_URL'),
124
+ apiKey = Core.readEnv('HONCHO_API_KEY') ?? null,
125
+ ...opts
126
+ }: ClientOptions = {}) {
127
+ const options: ClientOptions = {
128
+ apiKey,
129
+ ...opts,
130
+ baseURL,
131
+ environment: opts.environment ?? 'demo',
132
+ };
133
+
134
+ if (baseURL && opts.environment) {
135
+ throw new Errors.HonchoError(
136
+ 'Ambiguous URL; The `baseURL` option (or HONCHO_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
137
+ );
138
+ }
139
+
140
+ super({
141
+ baseURL: options.baseURL || environments[options.environment || 'demo'],
142
+ baseURLOverridden: baseURL ? baseURL !== environments[options.environment || 'demo'] : false,
143
+ timeout: options.timeout ?? 60000 /* 1 minute */,
144
+ httpAgent: options.httpAgent,
145
+ maxRetries: options.maxRetries,
146
+ fetch: options.fetch,
147
+ });
148
+
149
+ this._options = options;
150
+
151
+ this.apiKey = apiKey;
152
+ }
153
+
154
+ workspaces: API.Workspaces = new API.Workspaces(this);
155
+ keys: API.Keys = new API.Keys(this);
156
+
157
+ /**
158
+ * Check whether the base URL is set to its default.
159
+ */
160
+ #baseURLOverridden(): boolean {
161
+ return this.baseURL !== environments[this._options.environment || 'demo'];
162
+ }
163
+
164
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
165
+ return this._options.defaultQuery;
166
+ }
167
+
168
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
169
+ return {
170
+ ...super.defaultHeaders(opts),
171
+ ...this._options.defaultHeaders,
172
+ };
173
+ }
174
+
175
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
176
+ if (this.apiKey == null) {
177
+ return {};
178
+ }
179
+ return { Authorization: `Bearer ${this.apiKey}` };
180
+ }
181
+
182
+ static Honcho = this;
183
+ static DEFAULT_TIMEOUT = 60000; // 1 minute
184
+
185
+ static HonchoError = Errors.HonchoError;
186
+ static APIError = Errors.APIError;
187
+ static APIConnectionError = Errors.APIConnectionError;
188
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
189
+ static APIUserAbortError = Errors.APIUserAbortError;
190
+ static NotFoundError = Errors.NotFoundError;
191
+ static ConflictError = Errors.ConflictError;
192
+ static RateLimitError = Errors.RateLimitError;
193
+ static BadRequestError = Errors.BadRequestError;
194
+ static AuthenticationError = Errors.AuthenticationError;
195
+ static InternalServerError = Errors.InternalServerError;
196
+ static PermissionDeniedError = Errors.PermissionDeniedError;
197
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
198
+
199
+ static toFile = Uploads.toFile;
200
+ static fileFromPath = Uploads.fileFromPath;
201
+ }
202
+
203
+ Honcho.Workspaces = Workspaces;
204
+ Honcho.WorkspacesPage = WorkspacesPage;
205
+ Honcho.Keys = Keys;
206
+ export declare namespace Honcho {
207
+ export type RequestOptions = Core.RequestOptions;
208
+
209
+ export import Page = Pagination.Page;
210
+ export { type PageParams as PageParams, type PageResponse as PageResponse };
211
+
212
+ export {
213
+ Workspaces as Workspaces,
214
+ type Workspace as Workspace,
215
+ WorkspacesPage as WorkspacesPage,
216
+ type WorkspaceUpdateParams as WorkspaceUpdateParams,
217
+ type WorkspaceListParams as WorkspaceListParams,
218
+ type WorkspaceGetOrCreateParams as WorkspaceGetOrCreateParams,
219
+ type WorkspaceSearchParams as WorkspaceSearchParams,
220
+ };
221
+
222
+ export {
223
+ Keys as Keys,
224
+ type KeyCreateResponse as KeyCreateResponse,
225
+ type KeyCreateParams as KeyCreateParams,
226
+ };
227
+ }
228
+
229
+ export { toFile, fileFromPath } from "./uploads.js";
230
+ export {
231
+ HonchoError,
232
+ APIError,
233
+ APIConnectionError,
234
+ APIConnectionTimeoutError,
235
+ APIUserAbortError,
236
+ NotFoundError,
237
+ ConflictError,
238
+ RateLimitError,
239
+ BadRequestError,
240
+ AuthenticationError,
241
+ InternalServerError,
242
+ PermissionDeniedError,
243
+ UnprocessableEntityError,
244
+ } from "./error.js";
245
+
246
+ export default Honcho;
package/src/lib/.keep ADDED
@@ -0,0 +1,4 @@
1
+ File generated from our OpenAPI spec by Stainless.
2
+
3
+ This directory can be used to store custom files to expand the SDK.
4
+ It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
@@ -0,0 +1,73 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from "./core.js";
4
+
5
+ export interface PageResponse<Item> {
6
+ total: number;
7
+
8
+ items: Array<Item>;
9
+
10
+ page: number;
11
+
12
+ size: number;
13
+
14
+ pages: number;
15
+ }
16
+
17
+ export interface PageParams {
18
+ /**
19
+ * The page number
20
+ */
21
+ page?: number;
22
+
23
+ /**
24
+ * The number of items in a page
25
+ */
26
+ size?: number;
27
+ }
28
+
29
+ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {
30
+ total: number;
31
+
32
+ items: Array<Item>;
33
+
34
+ page: number;
35
+
36
+ size: number;
37
+
38
+ pages: number;
39
+
40
+ constructor(client: APIClient, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {
41
+ super(client, response, body, options);
42
+
43
+ this.total = body.total || 0;
44
+ this.items = body.items || [];
45
+ this.page = body.page || 0;
46
+ this.size = body.size || 0;
47
+ this.pages = body.pages || 0;
48
+ }
49
+
50
+ getPaginatedItems(): Item[] {
51
+ return this.items ?? [];
52
+ }
53
+
54
+ // @deprecated Please use `nextPageInfo()` instead
55
+ nextPageParams(): Partial<PageParams> | null {
56
+ const info = this.nextPageInfo();
57
+ if (!info) return null;
58
+ if ('params' in info) return info.params;
59
+ const params = Object.fromEntries(info.url.searchParams);
60
+ if (!Object.keys(params).length) return null;
61
+ return params;
62
+ }
63
+
64
+ nextPageInfo(): PageInfo | null {
65
+ const currentPage = this.page;
66
+
67
+ if (currentPage >= this.pages) {
68
+ return null;
69
+ }
70
+
71
+ return { params: { page: currentPage + 1 } };
72
+ }
73
+ }
@@ -0,0 +1,11 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { Honcho } from "./index.js";
4
+
5
+ export abstract class APIResource {
6
+ protected _client: Honcho;
7
+
8
+ constructor(client: Honcho) {
9
+ this._client = client;
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Keys, type KeyCreateResponse, type KeyCreateParams } from "./keys.js";
4
+ export {
5
+ WorkspacesPage,
6
+ Workspaces,
7
+ type Workspace,
8
+ type WorkspaceUpdateParams,
9
+ type WorkspaceListParams,
10
+ type WorkspaceGetOrCreateParams,
11
+ type WorkspaceSearchParams,
12
+ } from "./workspaces/workspaces.js";
@@ -0,0 +1,51 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../resource.js";
4
+ import { isRequestOptions } from "../core.js";
5
+ import * as Core from "../core.js";
6
+
7
+ export class Keys extends APIResource {
8
+ /**
9
+ * Create a new Key
10
+ */
11
+ create(params?: KeyCreateParams, options?: Core.RequestOptions): Core.APIPromise<unknown>;
12
+ create(options?: Core.RequestOptions): Core.APIPromise<unknown>;
13
+ create(
14
+ params: KeyCreateParams | Core.RequestOptions = {},
15
+ options?: Core.RequestOptions,
16
+ ): Core.APIPromise<unknown> {
17
+ if (isRequestOptions(params)) {
18
+ return this.create({}, params);
19
+ }
20
+ const { expires_at, peer_id, session_id, workspace_id } = params;
21
+ return this._client.post('/v1/keys', {
22
+ query: { expires_at, peer_id, session_id, workspace_id },
23
+ ...options,
24
+ });
25
+ }
26
+ }
27
+
28
+ export type KeyCreateResponse = unknown;
29
+
30
+ export interface KeyCreateParams {
31
+ expires_at?: string | null;
32
+
33
+ /**
34
+ * ID of the peer to scope the key to
35
+ */
36
+ peer_id?: string | null;
37
+
38
+ /**
39
+ * ID of the session to scope the key to
40
+ */
41
+ session_id?: string | null;
42
+
43
+ /**
44
+ * ID of the workspace to scope the key to
45
+ */
46
+ workspace_id?: string | null;
47
+ }
48
+
49
+ export declare namespace Keys {
50
+ export { type KeyCreateResponse as KeyCreateResponse, type KeyCreateParams as KeyCreateParams };
51
+ }
@@ -0,0 +1,39 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export {
4
+ PeersPage,
5
+ Peers,
6
+ type PageSession,
7
+ type Peer,
8
+ type SessionGet,
9
+ type PeerChatResponse,
10
+ type PeerWorkingRepresentationResponse,
11
+ type PeerUpdateParams,
12
+ type PeerListParams,
13
+ type PeerChatParams,
14
+ type PeerGetOrCreateParams,
15
+ type PeerSearchParams,
16
+ type PeerWorkingRepresentationParams,
17
+ } from "./peers/index.js";
18
+ export {
19
+ SessionsPage,
20
+ Sessions,
21
+ type Session,
22
+ type SessionDeleteResponse,
23
+ type SessionGetContextResponse,
24
+ type SessionUpdateParams,
25
+ type SessionListParams,
26
+ type SessionCloneParams,
27
+ type SessionGetContextParams,
28
+ type SessionGetOrCreateParams,
29
+ type SessionSearchParams,
30
+ } from "./sessions/index.js";
31
+ export {
32
+ WorkspacesPage,
33
+ Workspaces,
34
+ type Workspace,
35
+ type WorkspaceUpdateParams,
36
+ type WorkspaceListParams,
37
+ type WorkspaceGetOrCreateParams,
38
+ type WorkspaceSearchParams,
39
+ } from "./workspaces.js";
@@ -0,0 +1,24 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export {
4
+ Messages,
5
+ type MessageCreateResponse,
6
+ type MessageCreateParams,
7
+ type MessageListParams,
8
+ } from "./messages.js";
9
+ export {
10
+ PeersPage,
11
+ Peers,
12
+ type PageSession,
13
+ type Peer,
14
+ type SessionGet,
15
+ type PeerChatResponse,
16
+ type PeerWorkingRepresentationResponse,
17
+ type PeerUpdateParams,
18
+ type PeerListParams,
19
+ type PeerChatParams,
20
+ type PeerGetOrCreateParams,
21
+ type PeerSearchParams,
22
+ type PeerWorkingRepresentationParams,
23
+ } from "./peers.js";
24
+ export { Sessions, type SessionListParams } from "./sessions.js";
@@ -0,0 +1,81 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../../resource.js";
4
+ import { isRequestOptions } from "../../../core.js";
5
+ import * as Core from "../../../core.js";
6
+ import * as SessionsMessagesAPI from "../sessions/messages.js";
7
+ import { MessagesPage } from "../sessions/messages.js";
8
+ import { type PageParams } from "../../../pagination.js";
9
+
10
+ export class Messages extends APIResource {
11
+ /**
12
+ * Create messages for a peer
13
+ */
14
+ create(
15
+ workspaceId: string,
16
+ peerId: string,
17
+ body: MessageCreateParams,
18
+ options?: Core.RequestOptions,
19
+ ): Core.APIPromise<MessageCreateResponse> {
20
+ return this._client.post(`/v1/workspaces/${workspaceId}/peers/${peerId}/messages`, { body, ...options });
21
+ }
22
+
23
+ /**
24
+ * Get all messages for a peer
25
+ */
26
+ list(
27
+ workspaceId: string,
28
+ peerId: string,
29
+ params?: MessageListParams,
30
+ options?: Core.RequestOptions,
31
+ ): Core.PagePromise<MessagesPage, SessionsMessagesAPI.Message>;
32
+ list(
33
+ workspaceId: string,
34
+ peerId: string,
35
+ options?: Core.RequestOptions,
36
+ ): Core.PagePromise<MessagesPage, SessionsMessagesAPI.Message>;
37
+ list(
38
+ workspaceId: string,
39
+ peerId: string,
40
+ params: MessageListParams | Core.RequestOptions = {},
41
+ options?: Core.RequestOptions,
42
+ ): Core.PagePromise<MessagesPage, SessionsMessagesAPI.Message> {
43
+ if (isRequestOptions(params)) {
44
+ return this.list(workspaceId, peerId, {}, params);
45
+ }
46
+ const { page, reverse, size, ...body } = params;
47
+ return this._client.getAPIList(
48
+ `/v1/workspaces/${workspaceId}/peers/${peerId}/messages/list`,
49
+ MessagesPage,
50
+ { query: { page, reverse, size }, body, method: 'post', ...options },
51
+ );
52
+ }
53
+ }
54
+
55
+ export type MessageCreateResponse = Array<SessionsMessagesAPI.Message>;
56
+
57
+ export interface MessageCreateParams {
58
+ messages: Array<SessionsMessagesAPI.MessageCreate>;
59
+ }
60
+
61
+ export interface MessageListParams extends PageParams {
62
+ /**
63
+ * Query param: Whether to reverse the order of results
64
+ */
65
+ reverse?: boolean | null;
66
+
67
+ /**
68
+ * Body param:
69
+ */
70
+ filter?: Record<string, unknown> | null;
71
+ }
72
+
73
+ export declare namespace Messages {
74
+ export {
75
+ type MessageCreateResponse as MessageCreateResponse,
76
+ type MessageCreateParams as MessageCreateParams,
77
+ type MessageListParams as MessageListParams,
78
+ };
79
+ }
80
+
81
+ export { MessagesPage };