@proteos/sdk 0.18.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.
Files changed (94) hide show
  1. package/LICENSE +40 -0
  2. package/dist/chunk-7RGN4E22.cjs +1185 -0
  3. package/dist/chunk-7RGN4E22.cjs.map +1 -0
  4. package/dist/chunk-XJP5WCRZ.js +1125 -0
  5. package/dist/chunk-XJP5WCRZ.js.map +1 -0
  6. package/dist/index.cjs +2384 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +5225 -0
  9. package/dist/index.d.ts +5225 -0
  10. package/dist/index.js +2146 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/meta/index.cjs +204 -0
  13. package/dist/meta/index.cjs.map +1 -0
  14. package/dist/meta/index.d.cts +2 -0
  15. package/dist/meta/index.d.ts +2 -0
  16. package/dist/meta/index.js +3 -0
  17. package/dist/meta/index.js.map +1 -0
  18. package/dist/types-BNsjfU8N.d.cts +3299 -0
  19. package/dist/types-BNsjfU8N.d.ts +3299 -0
  20. package/package.json +86 -0
  21. package/src/agent/agents.ts +53 -0
  22. package/src/agent/index.ts +134 -0
  23. package/src/agent/mcp-servers.ts +102 -0
  24. package/src/agent/prompts.ts +80 -0
  25. package/src/agent/session-types.ts +397 -0
  26. package/src/agent/sessions.ts +197 -0
  27. package/src/agent/skills.ts +89 -0
  28. package/src/agent/tools.ts +53 -0
  29. package/src/agent/types.ts +362 -0
  30. package/src/auth/index.ts +111 -0
  31. package/src/auth/me.ts +46 -0
  32. package/src/auth/organizations.ts +128 -0
  33. package/src/auth/platform-entities.ts +78 -0
  34. package/src/auth/roles.ts +213 -0
  35. package/src/auth/types.ts +294 -0
  36. package/src/auth/users.ts +226 -0
  37. package/src/client.ts +441 -0
  38. package/src/connector/index.ts +120 -0
  39. package/src/connector/types.ts +150 -0
  40. package/src/conversation/index.ts +297 -0
  41. package/src/conversation/types.ts +590 -0
  42. package/src/conversation/voice.ts +123 -0
  43. package/src/data/index.ts +53 -0
  44. package/src/data/queries.ts +66 -0
  45. package/src/data/records.ts +122 -0
  46. package/src/data/types.ts +89 -0
  47. package/src/errors.ts +148 -0
  48. package/src/events/index.ts +172 -0
  49. package/src/events/types.ts +77 -0
  50. package/src/functions/actions.ts +95 -0
  51. package/src/functions/index.ts +32 -0
  52. package/src/functions/types.ts +71 -0
  53. package/src/http/index.ts +2 -0
  54. package/src/http/query-params.ts +106 -0
  55. package/src/index.ts +598 -0
  56. package/src/iterator.ts +183 -0
  57. package/src/knowledge/graph.ts +35 -0
  58. package/src/knowledge/index.ts +104 -0
  59. package/src/knowledge/labels.ts +70 -0
  60. package/src/knowledge/links.ts +65 -0
  61. package/src/knowledge/nodes.ts +198 -0
  62. package/src/knowledge/record-links.ts +66 -0
  63. package/src/knowledge/types.ts +569 -0
  64. package/src/meta/apps.ts +107 -0
  65. package/src/meta/components.ts +124 -0
  66. package/src/meta/currency/index.ts +202 -0
  67. package/src/meta/entities.ts +193 -0
  68. package/src/meta/filters.ts +76 -0
  69. package/src/meta/index.ts +227 -0
  70. package/src/meta/layout/common-props.ts +93 -0
  71. package/src/meta/layout/control-registry.json +70 -0
  72. package/src/meta/layout/control-registry.ts +92 -0
  73. package/src/meta/layout/elements.ts +203 -0
  74. package/src/meta/layout/index.ts +41 -0
  75. package/src/meta/layout/page-layout.ts +35 -0
  76. package/src/meta/layout/size-value.ts +27 -0
  77. package/src/meta/list-views.ts +109 -0
  78. package/src/meta/lists.ts +104 -0
  79. package/src/meta/menu-configurations.ts +128 -0
  80. package/src/meta/modules.ts +159 -0
  81. package/src/meta/pages.ts +106 -0
  82. package/src/meta/types.ts +1115 -0
  83. package/src/meta/variables.ts +98 -0
  84. package/src/storage/files.ts +183 -0
  85. package/src/storage/index.ts +33 -0
  86. package/src/storage/types.ts +70 -0
  87. package/src/types/common.ts +143 -0
  88. package/src/types/index.ts +28 -0
  89. package/src/types/options.ts +95 -0
  90. package/src/workflow/executions.ts +99 -0
  91. package/src/workflow/index.ts +109 -0
  92. package/src/workflow/node-types.ts +50 -0
  93. package/src/workflow/types.ts +658 -0
  94. package/src/workflow/workflows.ts +152 -0
@@ -0,0 +1,98 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import { PageIterator } from '../iterator.js'
3
+ import type { ListResult } from '../types/common.js'
4
+ import type {
5
+ CreateVariableRequest,
6
+ ListVariablesOptions,
7
+ UpdateVariableRequest,
8
+ Variable,
9
+ } from './types.js'
10
+
11
+ const VARIABLES_BASE_PATH = '/meta/v1/variables'
12
+
13
+ /**
14
+ * Service for managing configuration and secret variables.
15
+ * Variables store key-value pairs scoped to modules.
16
+ */
17
+ export interface VariableService {
18
+ /**
19
+ * Lists variables with optional filtering.
20
+ *
21
+ * @param options - Filter and pagination options
22
+ * @returns Async iterator over variables
23
+ */
24
+ list(options?: ListVariablesOptions): PageIterator<Variable, ListVariablesOptions>
25
+
26
+ /**
27
+ * Fetches a single page of variables.
28
+ * Useful for paginated UI frameworks (e.g. React Query's useInfiniteQuery).
29
+ */
30
+ listPage(options?: ListVariablesOptions): Promise<ListResult<Variable>>
31
+
32
+ /**
33
+ * Gets a single variable by ID.
34
+ *
35
+ * @param id - Variable ID
36
+ * @returns The variable
37
+ * @throws {ProteosError} If variable not found (404)
38
+ */
39
+ get(id: string): Promise<Variable>
40
+
41
+ /**
42
+ * Creates a new variable.
43
+ *
44
+ * @param request - Variable creation request
45
+ * @returns The created variable
46
+ * @throws {ProteosError} If validation fails (400) or conflict (409)
47
+ */
48
+ create(request: CreateVariableRequest): Promise<Variable>
49
+
50
+ /**
51
+ * Updates an existing variable.
52
+ *
53
+ * @param id - Variable ID
54
+ * @param request - Fields to update
55
+ * @returns The updated variable
56
+ * @throws {ProteosError} If variable not found (404) or validation fails (400)
57
+ */
58
+ update(id: string, request: UpdateVariableRequest): Promise<Variable>
59
+
60
+ /**
61
+ * Deletes a variable.
62
+ *
63
+ * @param id - Variable ID
64
+ * @throws {ProteosError} If variable not found (404)
65
+ */
66
+ delete(id: string): Promise<void>
67
+ }
68
+
69
+ /**
70
+ * Implementation of VariableService.
71
+ */
72
+ export class VariableServiceImpl implements VariableService {
73
+ constructor(private readonly client: ProteosClient) {}
74
+
75
+ list(options: ListVariablesOptions = {}): PageIterator<Variable, ListVariablesOptions> {
76
+ return new PageIterator((opts) => this.listPage(opts), options)
77
+ }
78
+
79
+ async listPage(options: ListVariablesOptions = {}): Promise<ListResult<Variable>> {
80
+ return this.client.requestWithQuery<ListResult<Variable>>('GET', VARIABLES_BASE_PATH, options)
81
+ }
82
+
83
+ async get(id: string): Promise<Variable> {
84
+ return this.client.request<Variable>('GET', `${VARIABLES_BASE_PATH}/${id}`)
85
+ }
86
+
87
+ async create(request: CreateVariableRequest): Promise<Variable> {
88
+ return this.client.request<Variable>('POST', VARIABLES_BASE_PATH, request)
89
+ }
90
+
91
+ async update(id: string, request: UpdateVariableRequest): Promise<Variable> {
92
+ return this.client.request<Variable>('PATCH', `${VARIABLES_BASE_PATH}/${id}`, request)
93
+ }
94
+
95
+ async delete(id: string): Promise<void> {
96
+ await this.client.request<void>('DELETE', `${VARIABLES_BASE_PATH}/${id}`)
97
+ }
98
+ }
@@ -0,0 +1,183 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import type { CreateFileMetadata, FileVersionContent, StorageFile } from './types.js'
3
+
4
+ const FILES_BASE_PATH = '/storage/v1/files'
5
+
6
+ /**
7
+ * Service for storing and retrieving files via the storage-service.
8
+ *
9
+ * The storage-service is one-blob-per-id (no directories); each `upload` creates
10
+ * a brand-new file. A `file`-typed record attribute stores only the resulting
11
+ * `{ id, name }` (a `FileRef`); size and content type are resolved on read via
12
+ * {@link FileService.get}.
13
+ */
14
+ export interface FileService {
15
+ /**
16
+ * Uploads bytes and creates a new file. Returns the created file (including
17
+ * `current_version.size_in_bytes` and `content_type`). The caller derives the
18
+ * `FileRef { id, name }` it stores on the record from the result.
19
+ *
20
+ * `name` defaults to the `File`'s own name; `contentType` to its MIME type.
21
+ */
22
+ upload(file: File, options?: { name?: string; contentType?: string }): Promise<StorageFile>
23
+
24
+ /**
25
+ * Creates a file's metadata only (no bytes) — the first step of the upload-URL
26
+ * flow for large files. The returned file is not yet persisted; mint an upload URL
27
+ * with {@link FileService.createUploadUrl} and PUT the bytes to it.
28
+ */
29
+ create(metadata: CreateFileMetadata): Promise<StorageFile>
30
+
31
+ /**
32
+ * Mints a short-lived upload URL for a file. The bytes are PUT directly to this URL
33
+ * (raw body, no auth) — keeping large files off the SDK/MCP path. Single-use, ~3 min.
34
+ */
35
+ createUploadUrl(id: string): Promise<{ url: string; expires_at: string }>
36
+
37
+ /**
38
+ * Triggers content extraction for the file's current version. Asynchronous: returns
39
+ * a `processing` row (or cached `ready` content); poll {@link FileService.getContent}
40
+ * for the terminal status.
41
+ */
42
+ parse(id: string, options?: { parser?: string; force?: boolean }): Promise<FileVersionContent>
43
+
44
+ /**
45
+ * Fetches the parsed content of the file's current version.
46
+ * @throws {ProteosError} If the file has never been parsed (404).
47
+ */
48
+ getContent(id: string): Promise<FileVersionContent>
49
+
50
+ /**
51
+ * Fetches a file's metadata by id (name, content type, current version size).
52
+ * @throws {ProteosError} If the file is not found (404).
53
+ */
54
+ get(id: string): Promise<StorageFile>
55
+
56
+ /**
57
+ * Mints a short-lived public download URL for a file (the token in the URL is
58
+ * the sole credential — no auth header needed). Default: single-use, ≈5 min
59
+ * TTL, suitable for click-to-download. `allowsMultiUse` mints a token that
60
+ * survives repeated GETs (≈1 h TTL) for consumers that probe the URL before
61
+ * downloading.
62
+ */
63
+ createDownloadUrl(
64
+ id: string,
65
+ options?: { allowsMultiUse?: boolean },
66
+ ): Promise<{ url: string; expires_at: string }>
67
+
68
+ /**
69
+ * Downloads the file's current version as a Blob (authenticated). Prefer
70
+ * {@link FileService.createDownloadUrl} for browser click-to-download.
71
+ */
72
+ download(id: string): Promise<Blob>
73
+ }
74
+
75
+ /**
76
+ * Implementation of FileService.
77
+ */
78
+ export class FileServiceImpl implements FileService {
79
+ constructor(private readonly client: ProteosClient) {}
80
+
81
+ async upload(
82
+ file: File,
83
+ options?: { name?: string; contentType?: string },
84
+ ): Promise<StorageFile> {
85
+ const metadata: CreateFileMetadata = {
86
+ name: options?.name ?? file.name,
87
+ content_type: options?.contentType ?? file.type ?? 'application/octet-stream',
88
+ }
89
+
90
+ // The storage-service reads multipart parts in order: `metadata` (JSON)
91
+ // first, then `file` (bytes). FormData preserves append order, so the
92
+ // metadata Blob MUST be appended before the file.
93
+ const formData = new FormData()
94
+ formData.append('metadata', new Blob([JSON.stringify(metadata)], { type: 'application/json' }))
95
+ formData.append('file', file, metadata.name)
96
+
97
+ const response = await this.client.requestMultipart<{ data: StorageFile }>(
98
+ 'POST',
99
+ FILES_BASE_PATH,
100
+ formData,
101
+ )
102
+ return response.data
103
+ }
104
+
105
+ async create(metadata: CreateFileMetadata): Promise<StorageFile> {
106
+ const formData = new FormData()
107
+ formData.append(
108
+ 'metadata',
109
+ new Blob(
110
+ [
111
+ JSON.stringify({
112
+ name: metadata.name,
113
+ content_type: metadata.content_type ?? 'application/octet-stream',
114
+ }),
115
+ ],
116
+ { type: 'application/json' },
117
+ ),
118
+ )
119
+ const response = await this.client.requestMultipart<{ data: StorageFile }>(
120
+ 'POST',
121
+ FILES_BASE_PATH,
122
+ formData,
123
+ )
124
+ return response.data
125
+ }
126
+
127
+ async createUploadUrl(id: string): Promise<{ url: string; expires_at: string }> {
128
+ const response = await this.client.request<{ data: { url: string; expires_at: string } }>(
129
+ 'POST',
130
+ `${FILES_BASE_PATH}/${id}/generate-upload-url`,
131
+ )
132
+ return response.data
133
+ }
134
+
135
+ async parse(
136
+ id: string,
137
+ options?: { parser?: string; force?: boolean },
138
+ ): Promise<FileVersionContent> {
139
+ const response = await this.client.request<{ data: FileVersionContent }>(
140
+ 'POST',
141
+ `${FILES_BASE_PATH}/${id}/parse`,
142
+ options ?? {},
143
+ )
144
+ return response.data
145
+ }
146
+
147
+ async getContent(id: string): Promise<FileVersionContent> {
148
+ const response = await this.client.request<{ data: FileVersionContent }>(
149
+ 'GET',
150
+ `${FILES_BASE_PATH}/${id}/content`,
151
+ )
152
+ return response.data
153
+ }
154
+
155
+ async get(id: string): Promise<StorageFile> {
156
+ const response = await this.client.request<{ data: StorageFile }>(
157
+ 'GET',
158
+ `${FILES_BASE_PATH}/${id}`,
159
+ )
160
+ return response.data
161
+ }
162
+
163
+ async createDownloadUrl(
164
+ id: string,
165
+ options?: { allowsMultiUse?: boolean },
166
+ ): Promise<{ url: string; expires_at: string }> {
167
+ const body =
168
+ options?.allowsMultiUse !== undefined
169
+ ? { allows_multi_use: options.allowsMultiUse }
170
+ : undefined
171
+ const response = await this.client.request<{ data: { url: string; expires_at: string } }>(
172
+ 'POST',
173
+ `${FILES_BASE_PATH}/${id}/generate-download-url`,
174
+ body,
175
+ )
176
+ return response.data
177
+ }
178
+
179
+ async download(id: string): Promise<Blob> {
180
+ const { response } = await this.client.requestRaw('GET', `${FILES_BASE_PATH}/${id}/download`)
181
+ return await response.blob()
182
+ }
183
+ }
@@ -0,0 +1,33 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import { type FileService, FileServiceImpl } from './files.js'
3
+
4
+ /**
5
+ * Facade for the storage-service (file upload / download / metadata).
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * const client = new ProteosClient({ baseUrl, tokenProvider });
10
+ * const storage = new StorageClient(client);
11
+ * const file = await storage.files.upload(picked); // -> { id, name, ... }
12
+ * const { url } = await storage.files.createDownloadUrl(file.id);
13
+ * ```
14
+ */
15
+ export class StorageClient {
16
+ readonly files: FileService
17
+
18
+ constructor(client: ProteosClient) {
19
+ this.files = new FileServiceImpl(client)
20
+ }
21
+ }
22
+
23
+ // Re-export service interface
24
+ export type { FileService } from './files.js'
25
+
26
+ // Re-export types
27
+ export type {
28
+ CreateFileMetadata,
29
+ FileVersionContent,
30
+ ParseStatus,
31
+ StorageFile,
32
+ StorageFileVersion,
33
+ } from './types.js'
@@ -0,0 +1,70 @@
1
+ /**
2
+ * A version of a stored file. Each file has one or more versions; the file's
3
+ * `current_version` points at the latest. Size is carried here, not on the
4
+ * file. Mirrors the Go `storagemodel.Version`.
5
+ */
6
+ export interface StorageFileVersion {
7
+ id: string
8
+ number: number
9
+ file_id: string
10
+ size_in_bytes: number
11
+ hash: string
12
+ created_at: string
13
+ last_accessed_at: string
14
+ }
15
+
16
+ /**
17
+ * A stored file in the storage-service. The blob bytes live behind `id`; the
18
+ * size and content type are resolved here (size via `current_version`). Mirrors
19
+ * the Go `storagemodel.File`.
20
+ */
21
+ export interface StorageFile {
22
+ id: string
23
+ org_id?: string | null
24
+ name: string
25
+ content_type: string
26
+ current_version: StorageFileVersion | null
27
+ is_deleted: boolean
28
+ is_persisted: boolean
29
+ is_locked: boolean
30
+ created_at: string
31
+ updated_at: string
32
+ }
33
+
34
+ /**
35
+ * Metadata sent alongside the bytes when creating a file. The storage-service
36
+ * reads this as the ordered `metadata` multipart part (before the `file` part).
37
+ */
38
+ export interface CreateFileMetadata {
39
+ name: string
40
+ content_type?: string
41
+ }
42
+
43
+ /**
44
+ * Lifecycle of a version's parsed content. A parse is asynchronous: the row is
45
+ * created `processing`, then flips to `ready` (with content) or `failed` (with an
46
+ * error). Poll {@link FileService.getContent} for the terminal status.
47
+ */
48
+ export type ParseStatus = 'pending' | 'processing' | 'ready' | 'failed'
49
+
50
+ /**
51
+ * The parsed/extracted content of a file version — the cache produced by
52
+ * {@link FileService.parse} and read via {@link FileService.getContent}. This is the
53
+ * extracted text/markdown, NOT the raw bytes (use {@link FileService.download} for
54
+ * those). Mirrors the Go `storagemodel.FileVersionContent`.
55
+ */
56
+ export interface FileVersionContent {
57
+ id: string
58
+ version_id: string
59
+ file_id: string
60
+ org_id?: string | null
61
+ format: string // markdown | text
62
+ content: string
63
+ parser?: string // model | document_ai | agent
64
+ model?: string
65
+ status: ParseStatus
66
+ error?: string | null
67
+ parsed_at?: string | null
68
+ created_at: string
69
+ updated_at: string
70
+ }
@@ -0,0 +1,143 @@
1
+ import { z } from 'zod'
2
+
3
+ /**
4
+ * Pagination metadata from list responses.
5
+ * Field names match the backend wire format exactly.
6
+ */
7
+ export interface ResponseMeta {
8
+ /** Current page number (0-indexed across all services). */
9
+ page: number
10
+ /** Number of items per page */
11
+ page_size: number
12
+ /** Total number of items across all pages */
13
+ items_total: number
14
+ /** Total number of pages */
15
+ pages_total: number
16
+ }
17
+
18
+ /**
19
+ * Zod schema for ResponseMeta validation.
20
+ */
21
+ export const ResponseMetaSchema = z.object({
22
+ page: z.number(),
23
+ page_size: z.number(),
24
+ items_total: z.number(),
25
+ pages_total: z.number(),
26
+ })
27
+
28
+ /**
29
+ * Generic paginated response wrapper.
30
+ */
31
+ export interface ListResult<T> {
32
+ meta: ResponseMeta
33
+ data: T[]
34
+ }
35
+
36
+ /**
37
+ * Creates a Zod schema for ListResult with a given item schema.
38
+ */
39
+ export function createListResultSchema<T>(itemSchema: z.ZodType<T>) {
40
+ return z.object({
41
+ meta: ResponseMetaSchema,
42
+ data: z.array(itemSchema),
43
+ })
44
+ }
45
+
46
+ /**
47
+ * Base list options with pagination and sorting.
48
+ */
49
+ export interface ListOptions {
50
+ /** Page number (0-indexed). First page is 0. */
51
+ page?: number
52
+ /** Number of items per page (default: 100) */
53
+ page_size?: number
54
+ /** Field to sort by */
55
+ sort_by?: string
56
+ /** Sort direction */
57
+ sort_direction?: 'asc' | 'desc'
58
+ }
59
+
60
+ /**
61
+ * Common timestamp fields for entities.
62
+ */
63
+ export interface Timestamps {
64
+ /** ISO 8601 timestamp when the entity was created */
65
+ created_at: string
66
+ /** ISO 8601 timestamp when the entity was last updated */
67
+ updated_at: string
68
+ }
69
+
70
+ /**
71
+ * The kind of user a {@link UserRef} points at. `person` is a human; `agent`
72
+ * is an AI actor; `api` is a non-interactive client (reserved). The `"platform"`
73
+ * sentinel id (system/bootstrap writes) carries `person`.
74
+ */
75
+ export type UserType = 'person' | 'agent' | 'api'
76
+
77
+ /**
78
+ * A reference to a platform user — the value stored by every `user` attribute
79
+ * (including `created_by`/`updated_by`). `id` is the platform user id (or the
80
+ * `"platform"` sentinel for system writes); `type` is the user kind. The people
81
+ * picker resolves and filters on `id`.
82
+ */
83
+ export interface UserRef {
84
+ type: UserType
85
+ id: string
86
+ }
87
+
88
+ /**
89
+ * Zod schema for a UserRef value.
90
+ */
91
+ export const UserRefSchema = z.object({
92
+ type: z.enum(['person', 'agent', 'api']),
93
+ id: z.string(),
94
+ })
95
+
96
+ /**
97
+ * Sentinel id stored in created_by/updated_by for writes that didn't originate
98
+ * from a real user (bootstrap / system). Mirrors the backend's
99
+ * `common.PlatformUserId`.
100
+ */
101
+ export const PLATFORM_USER_ID = 'platform'
102
+
103
+ /**
104
+ * A reference to a stored file — the value stored by every `file` attribute.
105
+ * `id` is the storage-service file id; `name` is the denormalised filename the
106
+ * record carries so it has a human label without a storage round-trip. Size and
107
+ * content type are resolved from the storage-service by `id` on read. Mirrors
108
+ * the backend's `common.FileRef`.
109
+ */
110
+ export interface FileRef {
111
+ id: string
112
+ name: string
113
+ }
114
+
115
+ /**
116
+ * Zod schema for a FileRef value.
117
+ */
118
+ export const FileRefSchema = z.object({
119
+ id: z.string(),
120
+ name: z.string(),
121
+ })
122
+
123
+ /**
124
+ * Common audit fields for entities. `created_by`/`updated_by` hold a
125
+ * {@link UserRef} for the user who made the change (the `"platform"` sentinel
126
+ * id for system writes).
127
+ */
128
+ export interface AuditFields extends Timestamps {
129
+ /** Who created the entity (the "platform" sentinel id for system writes). */
130
+ created_by: UserRef
131
+ /** Who last updated the entity (the "platform" sentinel id for system writes). */
132
+ updated_by: UserRef
133
+ }
134
+
135
+ /**
136
+ * Zod schema for audit fields validation.
137
+ */
138
+ export const AuditFieldsSchema = z.object({
139
+ created_at: z.string(),
140
+ updated_at: z.string(),
141
+ created_by: UserRefSchema,
142
+ updated_by: UserRefSchema,
143
+ })
@@ -0,0 +1,28 @@
1
+ export type {
2
+ AuditFields,
3
+ FileRef,
4
+ ListOptions,
5
+ ListResult,
6
+ ResponseMeta,
7
+ Timestamps,
8
+ UserRef,
9
+ UserType,
10
+ } from './common.js'
11
+
12
+ export {
13
+ AuditFieldsSchema,
14
+ createListResultSchema,
15
+ FileRefSchema,
16
+ PLATFORM_USER_ID,
17
+ ResponseMetaSchema,
18
+ UserRefSchema,
19
+ } from './common.js'
20
+
21
+ export type {
22
+ ClientOptions,
23
+ RequestOptions,
24
+ ResolvedClientOptions,
25
+ TokenProvider,
26
+ } from './options.js'
27
+
28
+ export { DEFAULT_OPTIONS, resolveOptions } from './options.js'
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Token provider function for dynamic authentication.
3
+ * Can return a token synchronously or asynchronously.
4
+ */
5
+ export type TokenProvider = () => string | Promise<string>
6
+
7
+ /**
8
+ * Configuration options for the ProteosClient.
9
+ */
10
+ export interface ClientOptions {
11
+ /**
12
+ * Base URL for API requests.
13
+ * Example: 'https://api.proteos.ai'
14
+ */
15
+ baseUrl: string
16
+
17
+ /**
18
+ * Static bearer token for authentication.
19
+ * Use this for simple authentication scenarios.
20
+ */
21
+ token?: string
22
+
23
+ /**
24
+ * Dynamic token provider function.
25
+ * Called before each request to get the current token.
26
+ * Takes precedence over static token if both are provided.
27
+ * Useful for token refresh scenarios.
28
+ */
29
+ tokenProvider?: TokenProvider
30
+
31
+ /**
32
+ * Request timeout in milliseconds.
33
+ * Default: 30000 (30 seconds)
34
+ */
35
+ timeout?: number
36
+
37
+ /**
38
+ * Custom fetch implementation.
39
+ * Useful for testing or environments without native fetch.
40
+ * Default: global fetch
41
+ */
42
+ fetch?: typeof fetch
43
+
44
+ /**
45
+ * Custom headers to include in all requests.
46
+ * Authorization header is set automatically from token/tokenProvider.
47
+ */
48
+ headers?: Record<string, string>
49
+ }
50
+
51
+ /**
52
+ * Internal resolved options with defaults applied.
53
+ */
54
+ export interface ResolvedClientOptions {
55
+ baseUrl: string
56
+ token?: string
57
+ tokenProvider?: TokenProvider
58
+ timeout: number
59
+ fetch: typeof fetch
60
+ headers: Record<string, string>
61
+ }
62
+
63
+ /**
64
+ * Default client options.
65
+ */
66
+ export const DEFAULT_OPTIONS = {
67
+ timeout: 30000,
68
+ headers: {},
69
+ } as const
70
+
71
+ /**
72
+ * Resolves client options by applying defaults.
73
+ */
74
+ export function resolveOptions(options: ClientOptions): ResolvedClientOptions {
75
+ return {
76
+ baseUrl: options.baseUrl.replace(/\/$/, ''), // Remove trailing slash
77
+ ...(options.token !== undefined ? { token: options.token } : {}),
78
+ ...(options.tokenProvider !== undefined ? { tokenProvider: options.tokenProvider } : {}),
79
+ timeout: options.timeout ?? DEFAULT_OPTIONS.timeout,
80
+ fetch: (options.fetch ?? globalThis.fetch).bind(globalThis),
81
+ headers: { ...DEFAULT_OPTIONS.headers, ...options.headers },
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Options for individual requests.
87
+ */
88
+ export interface RequestOptions {
89
+ /** Request timeout in milliseconds (overrides client default) */
90
+ timeout?: number
91
+ /** Additional headers for this request */
92
+ headers?: Record<string, string>
93
+ /** AbortSignal for request cancellation */
94
+ signal?: AbortSignal
95
+ }