@mitralab.io/sdk-core 0.1.0 → 0.2.0-beta.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,57 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.2.0-beta.0
6
+
7
+ This working tree prepares the `0.2.0-beta.0` package. Publication provenance remains
8
+ unreleased until the final source commit and registry artifact exist.
9
+
10
+ - Map all 120 tools exposed by the MCP alpha catalog to direct, split, alias, or
11
+ composition-based typed Core capabilities in a versioned parity artifact.
12
+ - Add Code Studio app, file, build, deploy, version, and rollback operations.
13
+ - Include the producer-supported app icon in create inputs and document Code
14
+ Studio deploy and version pagination defaults.
15
+ - Add schema, custom query, import, full Data Source, Function administration,
16
+ agent, workflow, integration resource/template, Copilot, Messenger, member,
17
+ and app context operations.
18
+ - Add synchronous and asynchronous anonymous public Function execution through
19
+ a dedicated optional transport with no authenticated-transport fallback.
20
+ - Add structural page and nullable response helpers while preserving the
21
+ dependency-free injected transport architecture.
22
+ - Preserve producer `createdAt: null` values in `FunctionExecution`,
23
+ `FunctionDefinition`, and Custom Query summary and definition responses.
24
+ - Preserve producer `createdAt: null` values in `AgentTask` responses, which the
25
+ Copilot rename mutation returns without the field.
26
+ - Preserve full Function batch replacement over PUT while mapping the MCP
27
+ `bulkUpdateFunctions` patch semantics to a separate PATCH operation.
28
+ - Add embedded cron fields to single-Function create and patch inputs and
29
+ validate those fields in detail and list responses. Dedicated bulk input
30
+ types exclude the schedule fields discarded by the producer's bulk paths.
31
+ - Keep scheduling on the composed Function contract and omit the duplicate
32
+ schedule lifecycle facade and single-Function full-replacement PUT.
33
+ - Map MCP Function execution lookup to the nested administration route that
34
+ requires both Function and execution identifiers.
35
+ - Separate producer summary and detail DTOs for apps, integration templates,
36
+ template configs, and integration resources, and validate their complete
37
+ response shapes together with app versions and Workflow executions.
38
+ - Apply newest-first Code Studio deploy and version sorting by default while
39
+ preserving an explicit caller sort.
40
+ - Execute integration template configs by app-scoped alias with the same proxy
41
+ request and response contract used for config identifiers.
42
+ - Keep resource execution on `integration.executeResource()` and omit the
43
+ duplicate authoring-module method. Document `integrationAdmin.list()` as the
44
+ direct app-scoped integration listing contract.
45
+ - Forward optional Virtual Table and connection settings when creating Custom
46
+ Queries.
47
+ - Forward each Agent session's transport preference to the concrete event
48
+ source without coupling Core to HTTP or WebSocket.
49
+ - Match stable producer pagination while preserving Integration's legacy flat
50
+ page shape, and return the complete Data Manager records envelope.
51
+ - Align IAM current-user, Data Source, Import, Integration connection, Custom
52
+ Query execution, and Messenger notification DTOs with their alpha producers.
53
+ - Build app context only from capabilities authorized to an app-scoped token;
54
+ member access remains an explicit IAM operation requiring `MEMBER_READ`.
55
+
5
56
  ## 0.1.0
6
57
 
7
58
  - Add environment-neutral transport and error interfaces.
package/README.md CHANGED
@@ -7,7 +7,9 @@ Most application and Server Function code should install a concrete SDK instead:
7
7
  - `@mitralab.io/platform-sdk` for browser applications
8
8
  - `@mitralab.io/functions-sdk` for Mitra Server Functions
9
9
 
10
- The core package exists so both SDKs build entity, custom query, Function, integration, and current-user requests from one contract.
10
+ The core package exists so concrete SDKs build direct backend requests from one
11
+ contract. It exposes the API values returned by each service. It does not expose
12
+ MCP envelopes, `CallToolResult`, or MCP-formatted text.
11
13
 
12
14
  The versioned contract corpus in `contracts/` is the canonical source for the
13
15
  MCP, JavaScript, and Python capability matrix. Its manifest identifies the
@@ -23,7 +25,17 @@ The package contains:
23
25
  - common types and data transfer objects
24
26
  - safe path segment encoding
25
27
  - structural response validation
26
- - `auth.me`, entities, queries, Functions, and integration modules
28
+ - authentication and app members
29
+ - Code Studio apps, files, builds, deploys, versions, and rollback
30
+ - schema, records, custom queries, SQL, imports, and Data Sources
31
+ - Functions, versions, publishing, rollback, executions, visibility, and secrets
32
+ - Function scheduling composed into single-Function create, patch, get, and list
33
+ - business agents and workflows
34
+ - integration configs, resources, templates, tests, proxying, and executions
35
+ - Copilot tasks, messages, credentials, models, and app connections
36
+ - a transport-agnostic Agent task live-session state machine with bounded queue and `sendAndWait`
37
+ - Messenger notifications and composed safe app context
38
+ - anonymous public Function execution
27
39
  - a minimal transport interface injected by each concrete SDK
28
40
 
29
41
  The package does not contain:
@@ -35,6 +47,36 @@ The package does not contain:
35
47
 
36
48
  Those concerns stay in the concrete SDK because browser sessions and Server Function runtime credentials have different security and failure semantics.
37
49
 
50
+ ## Agent task live sessions
51
+
52
+ Core owns the state machine but never opens a network connection. A concrete SDK implements
53
+ `AgentTaskEventSource`, then composes it with the REST task module:
54
+
55
+ ```typescript
56
+ import {
57
+ createAgentTaskSessionManager,
58
+ withAgentTaskSessions,
59
+ type AgentTaskEventSource,
60
+ type SdkCore,
61
+ } from "@mitralab.io/sdk-core"
62
+
63
+ declare const eventSource: AgentTaskEventSource
64
+ declare const core: SdkCore
65
+
66
+ const sessions = createAgentTaskSessionManager({ tasks: core.agentTasks, eventSource })
67
+ const agentTasks = withAgentTaskSessions(core.agentTasks, sessions)
68
+ const session = agentTasks.session({ taskId: "task-id", transport: "http" })
69
+ const result = await session.sendAndWait("Summarize the app", { timeoutMs: 120_000 })
70
+ ```
71
+
72
+ The event source must complete `open()` after its streaming handshake, so Core opens the channel
73
+ before posting the prompt. Core forwards the session's `auto`, `websocket`, or `http` transport
74
+ preference to `open()`; the concrete adapter selects or rejects it. HTTP/SSE has no replay cursor.
75
+ During an active turn Core performs one
76
+ reconnection and reconciles persisted messages; live deltas across that gap are not guaranteed to
77
+ be lossless. Abort and timeout stop the local `sendAndWait` waiter but do not interrupt the remote
78
+ turn. Use `cancel()` when interruption is intended.
79
+
38
80
  ## Installation
39
81
 
40
82
  ```bash
@@ -54,28 +96,161 @@ declare const iam: Transport
54
96
  declare const dataManager: Transport
55
97
  declare const functions: Transport
56
98
  declare const integration: Transport
99
+ declare const codeStudio: Transport
100
+ declare const copilot: Transport
101
+ declare const messenger: Transport
102
+ declare const publicFunctions: Transport
57
103
 
58
- let dataSourceId: string | undefined
104
+ let appId: string | undefined
59
105
 
60
106
  const core = createSdkCore({
61
- transports: { auth: iam, dataManager, functions, integration },
62
- getDataSourceId: () => dataSourceId,
107
+ transports: {
108
+ auth: iam,
109
+ dataManager,
110
+ functions,
111
+ integration,
112
+ codeStudio,
113
+ copilot,
114
+ messenger,
115
+ publicFunctions,
116
+ },
117
+ getAppId: () => appId,
63
118
  functions: {
64
119
  executeInvocationType: "sync",
65
120
  emptyInput: "empty-object",
66
121
  },
67
122
  })
68
123
 
69
- const tasks = await core.entities.getTable("Task").list({ limit: 20 })
124
+ const { data: tasks } = await core.entities.getTable("Task").list({ limit: 20 })
125
+ const context = await core.context.getAppContext()
70
126
  ```
71
127
 
72
128
  The transport owns URL resolution, authentication, serialization, error parsing, redirects, retries, and timeouts. The core never reads or stores credentials.
73
129
 
74
- Custom query requests currently target the Data Manager `main` contract and
75
- send both `dataSourceId` and `parameters`. The recorded `alpha` contract accepts
76
- that body but ignores `dataSourceId`, resolving the data source from the
77
- authenticated app instead. The SDK does not retry this POST with another body
78
- because the first request can already execute.
130
+ List methods return the producer's summary DTO when it differs from the detail
131
+ response. Custom Query summaries omit `sql`, Workflow summaries omit
132
+ `definition`, and integration resource summaries contain only `id`, `name`,
133
+ `method`, and `endpoint`. App, integration template, and template config lists
134
+ likewise expose their producer summary DTOs, while their `get` methods return
135
+ the complete detail DTOs.
136
+
137
+ Record list and filter methods preserve the Data Manager envelope with `data`,
138
+ `limit`, `skip`, `total`, and `hasMore`. Spring list endpoints from Code Studio,
139
+ Functions, Data Manager, and Copilot use stable pagination metadata under
140
+ `page`. Integration still returns its legacy flat Spring page metadata, so its
141
+ list methods expose `totalElements` at the top level.
142
+
143
+ The complete DTOs preserve producer field names and nullability. This includes
144
+ Code Studio app routing, domains, color, plan, version, and timestamps;
145
+ Workflow execution scope, trigger, current step, context, and timestamps; and
146
+ Integration template login/request schemas, config metadata, and resource
147
+ parameter schemas. `apps.build()` returns the `AppDeploy` produced by the build
148
+ endpoint. `apps.publish()` continues to return the updated `AppDefinition`.
149
+
150
+ Code Studio deploys use the producer field names `deployUrl` and
151
+ `errorMessage`, together with `appId`, `appVersionId`, `logs`, `durationMs`,
152
+ `startedAt`, `finishedAt`, and `createdAt`. Integration execution history uses
153
+ `success` rather than a synthetic status and preserves nullable request,
154
+ response, error, source, and duration fields.
155
+
156
+ Integration configs can be executed by identifier with `integration.execute()`
157
+ or by their app-scoped alias with `integration.executeByAlias()`. Both methods
158
+ send the proxy request unchanged apart from the required `source: "SDK"` audit
159
+ field and validate the same proxy result.
160
+
161
+ `integrationAdmin.list()` is the native equivalent for listing configured
162
+ integrations. It calls `GET /api/v1/template-configs` and returns the producer's
163
+ paginated `TemplateConfigSummary` values. With an app-scoped token, the
164
+ Integration service filters the page to that app.
165
+
166
+ `auth`, `dataManager`, `functions`, and `integration` remain required for
167
+ backward compatibility. `codeStudio`, `copilot`, and `messenger` are optional;
168
+ calling their modules without the corresponding transport fails with a
169
+ configuration error before making a request.
170
+
171
+ `publicFunctions` is deliberately separate and never falls back to the
172
+ authenticated Functions transport. Its adapter must target the Functions public
173
+ base URL and must not attach `Authorization` or `X-App-Id`. It calls
174
+ `POST /public/v1/functions/{id}/execute` with `X-Invocation-Type: sync` or
175
+ `async`. Public async is fire-and-forget because the producer does not expose
176
+ anonymous polling. Callers that need a result use public sync execution, or the
177
+ authenticated `functions.executeAsync` and `functions.getExecution` methods.
178
+
179
+ ## App scope and permissions
180
+
181
+ Core accepts app identifiers but does not inspect tokens or implement service
182
+ authorization. A concrete app-scoped adapter must fix `appId` to its trusted
183
+ runtime value. It must not let caller input select another app. This is
184
+ especially important for Code Studio because its alpha endpoints do not enforce
185
+ an app claim in every path. `apps.list()` and `apps.create()` are tenant-wide and
186
+ are not available to app-scoped tokens.
187
+
188
+ `context.getAppContext()` always uses the trusted current app and deliberately
189
+ excludes app members. The Server Function token does not have `MEMBER_READ`, so
190
+ the composed context must not call IAM's member endpoint. `members` remains a
191
+ separate Core module for callers whose token has that permission. Function
192
+ secret operations still require their dedicated permissions. Agent tools that
193
+ resolve a business `agent_id` and the two tenant-wide app collection operations
194
+ are not applicable to an app-scoped token. Messenger delivery also depends on
195
+ a configured channel. These are service authorization constraints, not changes
196
+ to the remaining Core contracts.
197
+
198
+ Custom Query creation accepts optional `isVirtualTable` and `connectionId`
199
+ fields and forwards them unchanged to the Data Manager. Omitting
200
+ `isVirtualTable` preserves the producer default of `false`; `connectionId` only
201
+ selects an external connection for a Virtual Table.
202
+
203
+ Custom query execution targets the Data Manager alpha contract and sends only
204
+ `parameters`. Data Manager resolves the Data Source from the authenticated app,
205
+ so the concrete adapter must use the app-scoped JWT and must not accept a caller
206
+ selected Data Source for this operation.
207
+
208
+ ## MCP capability coverage
209
+
210
+ [`contracts/v0.2.0-beta.0/mcp-tool-parity.json`](contracts/v0.2.0-beta.0/mcp-tool-parity.json)
211
+ maps all 120 `@McpTool` methods from 18 alpha tool classes to the typed Core
212
+ surface. Multiplexed MCP tools map to separate SDK methods. Composition and alias
213
+ tools record equivalence instead of creating duplicate APIs. Git credentials are
214
+ excluded because they are an internal Sandbox endpoint, not an MCP capability.
215
+ The deprecated Functions bridge remains owned by `@mitralab.io/functions-sdk`.
216
+
217
+ The MCP `bulkUpdateFunctions` tool maps to `functionsAdmin.bulkPatch()` and
218
+ `PATCH /api/v1/functions/bulk`, preserving omitted fields. The separate
219
+ `functionsAdmin.bulkUpdate()` method remains a full replacement over PUT.
220
+ Single-Function create and patch inputs also expose `cronExpression`,
221
+ `cronInputJson`, and `cronEnabled` as one composed scheduling unit. On create,
222
+ omitting all three creates no schedule; supplying any of them requires a
223
+ non-blank `cronExpression`. The new schedule uses `UTC` and starts `ACTIVE`
224
+ unless `cronEnabled` is `false`. On patch, null or omitted schedule fields
225
+ preserve their stored values, an empty `cronInputJson` object clears the input,
226
+ and a blank `cronExpression` removes the schedule. A non-blank expression can
227
+ create a missing schedule in `UTC`; `cronEnabled` explicitly pauses or resumes
228
+ it. These composed writes require `SCHEDULE_WRITE` and `FUNCTION_EXECUTE` in
229
+ addition to the Function write permission.
230
+
231
+ Function detail and list responses return all three fields when the caller has
232
+ `SCHEDULE_READ`. Without it, all three are null without querying Scheduler. The
233
+ same all-null shape represents a Function that has no schedule, so these
234
+ responses alone cannot distinguish absence from missing read permission. All
235
+ Function bulk create, update, and patch inputs prohibit embedded schedule
236
+ fields; their dedicated types omit them. Compose scheduling only through the
237
+ single-Function create and patch methods.
238
+
239
+ The MCP `FunctionTools.getExecution` operation maps to
240
+ `functionsAdmin.getExecution(functionId, executionId)` and its nested Function
241
+ execution route. The runtime-only `functions.getExecution(executionId)` remains
242
+ available for callers of the separate global execution endpoint.
243
+
244
+ Core deliberately exposes no separate schedule facade. The MCP scheduling capability is composed
245
+ through the three cron fields on `functionsAdmin.create()` and `patch()`, with state returned by
246
+ `get()` and `list()`. This keeps one public Function contract instead of duplicating the Scheduler
247
+ producer lifecycle.
248
+
249
+ Legacy Git credentials and record operations selected by `jdbcConnectionConfigId` have no native
250
+ Core equivalent. Git credential minting is an internal Sandbox operation authenticated between
251
+ services, and the public Data Manager records API resolves the app Data Source from the token
252
+ without accepting a connection selector. Core does not synthesize either behavior through a BFF
253
+ or raw SQL.
79
254
 
80
255
  ## Error mapping
81
256
 
@@ -89,3 +264,20 @@ npm run check
89
264
  ```
90
265
 
91
266
  The build produces ESM, CommonJS, `.d.ts`, and `.d.cts` artifacts. Package smoke tests install the generated tarball into a clean consumer and validate both module systems and TypeScript resolution.
267
+
268
+ ## Release order
269
+
270
+ `0.2.0-beta.0` is the beta producer release for the concrete SDK adapters. Publish Core first:
271
+
272
+ 1. Merge the complete `0.2.0-beta.0` source and contract corpus to `main`.
273
+ 2. Run the Release workflow with version `0.2.0-beta.0`. It runs the full package check before
274
+ tagging and publishes the prerelease under npm's `beta` dist-tag.
275
+ 3. Confirm `npm view @mitralab.io/sdk-core@0.2.0-beta.0 version` returns `0.2.0-beta.0`.
276
+ 4. Regenerate each adapter lockfile from the npm registry and pin this repository commit in the
277
+ adapter's contract-source manifest before publishing that adapter.
278
+
279
+ Stable `X.Y.Z` releases use npm's default `latest` dist-tag. The workflow accepts only that stable
280
+ form or the prerelease form `X.Y.Z-beta.N`.
281
+
282
+ Do not publish an adapter against a local tarball or a `file:` dependency. Tarballs are only for
283
+ pre-release validation while the registry artifact does not exist.
@@ -10,22 +10,51 @@ change requires a new version directory. Consumers may vendor the exact bytes
10
10
  and pin their copy with a SHA-256 digest so their tests never depend on network
11
11
  access.
12
12
 
13
+ A released version directory is immutable. Adding operations means publishing a
14
+ new version and moving `current`, never editing bytes another consumer already
15
+ pinned. Every declared version keeps its digest verified, so a consumer that has
16
+ not migrated stays on the version it vendored.
17
+
18
+ ## Versions
19
+
20
+ - `0.1.0` covers the runtime surface: current user, entities, custom queries,
21
+ Function execution, and integration proxying.
22
+ - `0.2.0-beta.0` adds the builder tier: SQL batches and table listing, Data Source
23
+ batches, Function administration batches, integration template config
24
+ batches with connection tests and listing, and app members. Its `sources`
25
+ entries pin the producer revisions currently on `origin/alpha`.
26
+
27
+ The `0.2.0-beta.0/mcp-tool-parity.json` companion artifact maps every one of the 120
28
+ `@McpTool` methods on `mitra-mcp-server` `origin/alpha` to a typed Core method.
29
+ It labels multiplexed tools as split methods and composition or alias tools as
30
+ equivalences, so coverage does not require artificial duplicate APIs. The
31
+ manifest pins the companion artifact independently.
32
+
33
+ `0.2.0-beta.0/mcp-alpha-tools.json` is the offline source snapshot behind that matrix.
34
+ It records the MCP source paths, class names, complete method signatures, alpha
35
+ commit, and a digest over canonical lines containing each return type, method
36
+ name, and named parameter type. This makes request and response signature drift
37
+ fail the contract check even when a tool keeps the same name. Refresh and verify
38
+ it against a fetched MCP checkout with:
39
+
40
+ ```bash
41
+ npm run snapshot:mcp -- ../mitra-mcp-server origin/alpha
42
+ ```
43
+
13
44
  Core executes one success case for every operation plus Core-owned response
14
45
  validation cases. Functions JavaScript inherits those checks from Core and must
15
46
  consume every HTTP adapter case itself. Python does not depend on Core, so it
16
47
  must consume every success, response-validation, and HTTP adapter case. The
17
48
  consumer requirements in the fixture make those obligations machine-readable.
18
49
 
19
- ## Custom query transition
20
-
21
- The `customQueryTransition` section intentionally models two different server
22
- contracts:
50
+ The executable Function batch cases keep two different contracts: full
51
+ replacement through `bulkUpdate` and PUT, and partial preservation through
52
+ `bulkPatch` and PATCH. The MCP `bulkUpdateFunctions` tool maps only to the latter.
23
53
 
24
- - Data Manager `main` consumes `dataSourceId` and `parameters`.
25
- - Data Manager `alpha` accepts that same body, ignores `dataSourceId` during
26
- deserialization, and resolves the data source from the authenticated app.
54
+ ## Custom query execution
27
55
 
28
- The current SDK release still targets `main`, but its body is transport-compatible
29
- with the recorded `alpha` contract. The semantics differ because alpha ignores
30
- the supplied identifier. Do not add an automatic POST fallback because the first
31
- request can already execute and a retry could execute the query twice.
56
+ The `customQueryExecution` section records the Data Manager `origin/alpha`
57
+ contract used by this beta. The request body contains only `parameters`, and the
58
+ producer resolves the Data Source from the authenticated app. Concrete adapters
59
+ therefore supply the app-scoped JWT instead of accepting a caller-selected Data
60
+ Source identifier.
@@ -1,11 +1,20 @@
1
1
  {
2
2
  "contract": "SDK-PARITY-001",
3
- "current": "0.1.0",
3
+ "current": "0.2.0-beta.0",
4
4
  "versions": [
5
5
  {
6
6
  "version": "0.1.0",
7
7
  "path": "v0.1.0/sdk-parity.json",
8
8
  "sha256": "600be3688cea7cfef16a8cf347516e87949b8e4151efb2c4136a2345557dde70"
9
+ },
10
+ {
11
+ "version": "0.2.0-beta.0",
12
+ "path": "v0.2.0-beta.0/sdk-parity.json",
13
+ "sha256": "0f41764eedce0945b0b696b6f95af4d76c31a63df169b088b8a6f65d0aa841d4",
14
+ "mcpToolsPath": "v0.2.0-beta.0/mcp-tool-parity.json",
15
+ "mcpToolsSha256": "77a115d39e2ee195b4e33a86766a6fdd75e89a7a35b6102f6f38f0eeb8c9d587",
16
+ "mcpSourcePath": "v0.2.0-beta.0/mcp-alpha-tools.json",
17
+ "mcpSourceSha256": "480d27eed75f2604da07fadd10f236a0ca971cf6a3c003434a1fb62c4255178f"
9
18
  }
10
19
  ]
11
20
  }