@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,77 @@
1
+ /**
2
+ * Types for the event-service (read/admin view over the Redis-Streams
3
+ * event bus). Field names mirror the Go JSON shapes in
4
+ * packages/go/model/events.
5
+ */
6
+
7
+ /** Whether a topic is a normal event stream or a dead-letter stream. */
8
+ export type TopicKind = 'event' | 'dead_letter'
9
+
10
+ /** A consumer group registered on a topic's stream. */
11
+ export interface ConsumerGroup {
12
+ name: string
13
+ consumers: number
14
+ pending: number
15
+ lag: number
16
+ }
17
+
18
+ /**
19
+ * A topic — a read-only projection of one Redis stream scoped to the caller's
20
+ * org. Discovered live from the bus; reflects only the retention window.
21
+ */
22
+ export interface Topic {
23
+ /** Logical topic name, e.g. "record.contact.events" or "...events.dlq". */
24
+ name: string
25
+ /** Friendly label from the catalog, or `name` when unknown. */
26
+ display_name: string
27
+ kind: TopicKind
28
+ /** For a dead-letter topic, the source topic its entries belong to. */
29
+ source_topic?: string
30
+ event_count: number
31
+ /** ISO timestamp of the newest entry, when the stream is non-empty. */
32
+ last_event_at?: string
33
+ consumer_groups: ConsumerGroup[]
34
+ }
35
+
36
+ /** A single event — a read-only projection of one Redis stream entry. */
37
+ export interface PlatformEvent {
38
+ /** Redis stream entry id ("<ms>-<seq>") — the cursor for paging / tailing. */
39
+ stream_id: string
40
+ /** Application event id (UUID) from the envelope. */
41
+ id: string
42
+ org_id: string
43
+ topic: string
44
+ type: string
45
+ key?: string
46
+ /** Event body — JSON in practice; surfaced verbatim. */
47
+ payload: unknown
48
+ headers?: Record<string, string>
49
+ dispatched_at: string
50
+ }
51
+
52
+ /** Options for reading the last-N events on a topic. */
53
+ export interface ListEventsOptions {
54
+ /** Max events to return (newest first). */
55
+ limit?: number
56
+ /** Stream-id cursor; returns entries strictly older than it. */
57
+ before?: string
58
+ }
59
+
60
+ /** Body for publishing a test event onto a topic. */
61
+ export interface PublishEventRequest {
62
+ type: string
63
+ key?: string
64
+ payload?: unknown
65
+ }
66
+
67
+ /** Outcome of redriving a dead-letter stream back to its source topic. */
68
+ export interface RedriveResult {
69
+ source_topic: string
70
+ redriven: number
71
+ }
72
+
73
+ /** Options for a live tail. */
74
+ export interface TailOptions {
75
+ /** Abort the tail (stop streaming and release the connection). */
76
+ signal?: AbortSignal
77
+ }
@@ -0,0 +1,95 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import { PageIterator } from '../iterator.js'
3
+ import type { ListResult } from '../types/common.js'
4
+ import type { Action, InvokeActionResponse, ListActionsOptions } from './types.js'
5
+
6
+ const ACTIONS_BASE_PATH = '/functions/v1/actions'
7
+
8
+ /**
9
+ * Service for managing deployed actions (function-service).
10
+ *
11
+ * Actions are user-invokable operations. `params` and `returns` follow the
12
+ * same `Attribute` schema language as entity attributes — the UI form
13
+ * renderer consumes them directly.
14
+ */
15
+ export interface ActionService {
16
+ /**
17
+ * Lists deployed actions as an async iterator.
18
+ */
19
+ list(options?: ListActionsOptions): PageIterator<Action, ListActionsOptions>
20
+
21
+ /**
22
+ * Fetches a single page of actions.
23
+ */
24
+ listPage(options?: ListActionsOptions): Promise<ListResult<Action>>
25
+
26
+ /**
27
+ * Gets a single action by slug. The returned `Action` carries the full
28
+ * `params` and `returns` schemas, suitable for driving an invocation form.
29
+ *
30
+ * @throws {ProteosError} If the action is not found (404).
31
+ */
32
+ get(slug: string): Promise<Action>
33
+
34
+ /**
35
+ * Invokes a global-scoped action. Returns the unwrapped `result`
36
+ * payload — the wire envelope `{ result }` is unwrapped by the SDK.
37
+ *
38
+ * @throws {ProteosError} On guest validation failures (400, `GUEST_ERROR`),
39
+ * timeouts (504, `TIMEOUT`), traps (500, `TRAP`), or other failure kinds.
40
+ */
41
+ invokeGlobal(slug: string, params: Record<string, unknown>): Promise<unknown>
42
+
43
+ /**
44
+ * Invokes an entity-scoped action against a specific record. Returns the
45
+ * unwrapped `result` payload.
46
+ */
47
+ invokeEntity(
48
+ entitySlug: string,
49
+ recordId: string,
50
+ slug: string,
51
+ params: Record<string, unknown>,
52
+ ): Promise<unknown>
53
+ }
54
+
55
+ /**
56
+ * Implementation of ActionService.
57
+ */
58
+ export class ActionServiceImpl implements ActionService {
59
+ constructor(private readonly client: ProteosClient) {}
60
+
61
+ list(options: ListActionsOptions = {}): PageIterator<Action, ListActionsOptions> {
62
+ return new PageIterator((opts) => this.listPage(opts), options)
63
+ }
64
+
65
+ async listPage(options: ListActionsOptions = {}): Promise<ListResult<Action>> {
66
+ return this.client.requestWithQuery<ListResult<Action>>('GET', ACTIONS_BASE_PATH, options)
67
+ }
68
+
69
+ async get(slug: string): Promise<Action> {
70
+ return this.client.request<Action>('GET', `${ACTIONS_BASE_PATH}/${slug}`)
71
+ }
72
+
73
+ async invokeGlobal(slug: string, params: Record<string, unknown>): Promise<unknown> {
74
+ const response = await this.client.request<InvokeActionResponse>(
75
+ 'POST',
76
+ `${ACTIONS_BASE_PATH}/${slug}/invoke`,
77
+ params,
78
+ )
79
+ return response.result
80
+ }
81
+
82
+ async invokeEntity(
83
+ entitySlug: string,
84
+ recordId: string,
85
+ slug: string,
86
+ params: Record<string, unknown>,
87
+ ): Promise<unknown> {
88
+ const response = await this.client.request<InvokeActionResponse>(
89
+ 'POST',
90
+ `/functions/v1/entities/${entitySlug}/records/${recordId}/actions/${slug}/invoke`,
91
+ params,
92
+ )
93
+ return response.result
94
+ }
95
+ }
@@ -0,0 +1,32 @@
1
+ import type { ProteosClient } from '../client.js'
2
+ import { type ActionService, ActionServiceImpl } from './actions.js'
3
+
4
+ /**
5
+ * Facade for the function-service (deployed actions + hooks).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const client = new ProteosClient({ baseUrl, tokenProvider });
10
+ * const functions = new FunctionsClient(client);
11
+ * const action = await functions.actions.get('mark-as-signed');
12
+ * const result = await functions.actions.invokeEntity(
13
+ * 'document', recordId, 'mark-as-signed', { signatureType: 'ELECTRONIC' },
14
+ * );
15
+ * ```
16
+ */
17
+ export class FunctionsClient {
18
+ readonly actions: ActionService
19
+
20
+ constructor(client: ProteosClient) {
21
+ this.actions = new ActionServiceImpl(client)
22
+ }
23
+ }
24
+
25
+ // Re-export service interfaces
26
+ export type { ActionService } from './actions.js'
27
+
28
+ // Re-export types
29
+ export type { Action, ActionScope, InvokeActionResponse, ListActionsOptions } from './types.js'
30
+
31
+ // Re-export Zod schemas
32
+ export { ActionSchema, ActionScopeSchema } from './types.js'
@@ -0,0 +1,71 @@
1
+ import { z } from 'zod'
2
+
3
+ import { type Attribute, AttributeSchema } from '../meta/types.js'
4
+ import { type AuditFields, AuditFieldsSchema } from '../types/common.js'
5
+
6
+ /**
7
+ * Scope of an action. `entity`-scoped actions are invoked against a
8
+ * specific record; `global` actions take no record context.
9
+ */
10
+ export type ActionScope = 'entity' | 'global'
11
+
12
+ export const ActionScopeSchema = z.enum(['entity', 'global'])
13
+
14
+ /**
15
+ * Deployable, user-invokable operation. Mirrors `functionsmodel.Action`
16
+ * in the Go SDK. `params` and `returns` reuse the same `Attribute` schema
17
+ * language as entity attributes — the renderer consumes them directly.
18
+ */
19
+ export interface Action extends AuditFields {
20
+ slug: string
21
+ org_id: string
22
+ module_slug: string
23
+ scope: ActionScope
24
+ /** Present only when `scope === 'entity'`. */
25
+ entity?: string
26
+ name: string
27
+ is_active: boolean
28
+ /**
29
+ * When true (global actions only), the action is invokable on the
30
+ * unauthenticated public endpoint
31
+ * `POST /functions/v1/public/orgs/{orgId}/actions/{slug}/invoke`.
32
+ */
33
+ is_public: boolean
34
+ file_id: string
35
+ params: Attribute[]
36
+ returns: Attribute[]
37
+ }
38
+
39
+ export const ActionSchema = AuditFieldsSchema.extend({
40
+ slug: z.string(),
41
+ org_id: z.string(),
42
+ module_slug: z.string(),
43
+ scope: ActionScopeSchema,
44
+ entity: z.string().optional(),
45
+ name: z.string(),
46
+ is_active: z.boolean(),
47
+ file_id: z.string(),
48
+ params: z.array(AttributeSchema),
49
+ returns: z.array(AttributeSchema),
50
+ })
51
+
52
+ /**
53
+ * Options for listing actions.
54
+ */
55
+ export interface ListActionsOptions {
56
+ page?: number
57
+ page_size?: number
58
+ sort?: string
59
+ scope?: ActionScope
60
+ module_slug?: string
61
+ entity?: string
62
+ is_active?: boolean
63
+ }
64
+
65
+ /**
66
+ * Wire envelope returned by the invoke endpoints. The SDK unwraps `result`
67
+ * before returning to callers; this type is exported for completeness.
68
+ */
69
+ export interface InvokeActionResponse {
70
+ result: unknown
71
+ }
@@ -0,0 +1,2 @@
1
+ export type { QueryObject, QueryValue } from './query-params.js'
2
+ export { buildUrl, toQueryParams, toQueryString } from './query-params.js'
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Value types that can be converted to query parameters.
3
+ */
4
+ export type QueryValue = string | number | boolean | null | undefined
5
+
6
+ /**
7
+ * Object that can be converted to query parameters.
8
+ * Supports nested objects (which are skipped during conversion).
9
+ */
10
+ export type QueryObject = Record<string, QueryValue | QueryValue[] | Record<string, unknown>>
11
+
12
+ /**
13
+ * Converts an object to URLSearchParams for use in query strings.
14
+ * Handles nested objects by flattening them (skips complex nested structures).
15
+ * Skips null and undefined values.
16
+ *
17
+ * @param obj - Object to convert
18
+ * @returns URLSearchParams instance
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * toQueryParams({ page: 1, name: 'test', is_active: true })
23
+ * // => URLSearchParams { page: '1', name: 'test', is_active: 'true' }
24
+ *
25
+ * toQueryParams({ filter: { slug: 'my-slug' } })
26
+ * // => URLSearchParams {} (nested objects are skipped)
27
+ * ```
28
+ */
29
+ export function toQueryParams(obj: object | undefined | null): URLSearchParams {
30
+ const params = new URLSearchParams()
31
+
32
+ if (!obj) {
33
+ return params
34
+ }
35
+
36
+ for (const [key, value] of Object.entries(obj)) {
37
+ appendQueryParam(params, key, value as QueryValue | QueryValue[] | Record<string, unknown>)
38
+ }
39
+
40
+ return params
41
+ }
42
+
43
+ /**
44
+ * Appends a single value to URLSearchParams.
45
+ */
46
+ function appendQueryParam(
47
+ params: URLSearchParams,
48
+ key: string,
49
+ value: QueryValue | QueryValue[] | Record<string, unknown>,
50
+ ): void {
51
+ // Skip null and undefined
52
+ if (value === null || value === undefined) {
53
+ return
54
+ }
55
+
56
+ // Handle arrays
57
+ if (Array.isArray(value)) {
58
+ for (const item of value) {
59
+ if (item !== null && item !== undefined) {
60
+ params.append(key, String(item))
61
+ }
62
+ }
63
+ return
64
+ }
65
+
66
+ // Skip nested objects (complex types)
67
+ if (typeof value === 'object') {
68
+ return
69
+ }
70
+
71
+ // Convert primitives to string
72
+ params.set(key, String(value))
73
+ }
74
+
75
+ /**
76
+ * Converts a URLSearchParams instance to a query string.
77
+ * Returns empty string if no parameters.
78
+ *
79
+ * @param params - URLSearchParams to convert
80
+ * @returns Query string (without leading '?')
81
+ */
82
+ export function toQueryString(params: URLSearchParams): string {
83
+ const str = params.toString()
84
+ return str
85
+ }
86
+
87
+ /**
88
+ * Builds a full URL with query parameters.
89
+ *
90
+ * @param baseUrl - Base URL (may already have query params)
91
+ * @param path - Path to append
92
+ * @param query - Query parameters to add
93
+ * @returns Full URL string
94
+ */
95
+ export function buildUrl(baseUrl: string, path: string, query?: object): string {
96
+ const url = new URL(path, baseUrl)
97
+
98
+ if (query) {
99
+ const params = toQueryParams(query)
100
+ params.forEach((value, key) => {
101
+ url.searchParams.append(key, value)
102
+ })
103
+ }
104
+
105
+ return url.toString()
106
+ }