@nsp-labs/agnostic-sdk 1.0.4 → 1.4.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/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { AgnosticRuntime, RuntimeAppAuthNamespace, RuntimeContextNamespace, RuntimeDataNamespace, RuntimeDataRecordsClient, RuntimeDataTableClient, RuntimeDataViewClient, RuntimeDataViewTableClient, RuntimeWorkflowRunsNamespace, RuntimeWorkflowsNamespace, createAgnosticRuntime, } from './lib/runtime-client';
1
+ export { AgnosticRuntime, RuntimeAppAuthNamespace, RuntimeContextNamespace, RuntimeDataNamespace, RuntimeDataRecordsClient, RuntimeDataTableClient, RuntimeDataViewClient, RuntimeDataViewTableClient, RuntimeAnonymousUploadsClient, RuntimeStorageBucketClient, RuntimeStorageNamespace, RuntimeWorkflowRunsNamespace, RuntimeWorkflowsNamespace, createAgnosticRuntime, } from './lib/runtime-client';
2
2
  export { normalizeApiUrl, resolveRuntimeContext } from './lib/context';
3
3
  export { AgnosticRuntimeError } from './lib/errors';
4
- export type { AgnosticRuntimeConfig, ResolvedRuntimeContext, RuntimeActorMetadata, RuntimeActorType, RuntimeAppAuthActor, RuntimeAppAuthCachePolicy, RuntimeAppAuthRequestLike, RuntimeAppAuthSession, RuntimeAppAuthSessionClaims, RuntimeAppAuthUserClaims, RuntimeAppAuthUserResult, RuntimeCreateRecordInput, RuntimeDataField, RuntimeDataViewState, RuntimeIdentityContext, RuntimeListRecordsOptions, RuntimeListWindowOptions, RuntimeRecord, RuntimeRecordMutation, RuntimeRecordsList, RuntimeRequestOptions, RuntimeRowData, RuntimeRowValue, RuntimeTableWindow, RuntimeUpdateRecordInput, RuntimeWorkflowRun, RuntimeWorkflowStepRun, RuntimeWorkflowWaitOptions, WorkflowRunStatus, } from './lib/types';
4
+ export { AGNOSTIC_RUNTIME_SDK_MANIFEST, type AgnosticRuntimeSdkManifest, } from './lib/manifest';
5
+ export type { AgnosticRuntimeConfig, RuntimeAggregateMetric, RuntimeAggregateOperation, RuntimeAggregateOrderBy, RuntimeAggregateRecordsInput, RuntimeAggregateRecordsResult, RuntimeAggregateRow, ResolvedRuntimeContext, RuntimeActorMetadata, RuntimeActorType, RuntimeAnonymousClaimFileHandle, RuntimeAnonymousClaimInput, RuntimeAnonymousClaimResult, RuntimeAppAuthActor, RuntimeAppAuthCachePolicy, RuntimeAppAuthRequestLike, RuntimeAppAuthSession, RuntimeAppAuthSessionClaims, RuntimeAppAuthUserClaims, RuntimeAppAuthUserResult, RuntimeCreateRecordInput, RuntimeCreateFileUploadInput, RuntimeDataField, RuntimeDataViewState, RuntimeIdentityContext, RuntimeFileAccessMode, RuntimeFileDownloadUrl, RuntimeFileObject, RuntimeFileObjectStatus, RuntimeFileUploadCompletion, RuntimeFileUploadGrant, RuntimeListRecordsOptions, RuntimeListWindowOptions, RuntimeRecord, RuntimeRecordMutation, RuntimeRecordsList, RuntimeRequestOptions, RuntimeRowData, RuntimeRowValue, RuntimeTableWindow, RuntimeUpdateRecordInput, RuntimeWorkflowRun, RuntimeWorkflowStepRun, RuntimeWorkflowWaitOptions, WorkflowRunStatus, } from './lib/types';
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgnosticRuntimeError = exports.resolveRuntimeContext = exports.normalizeApiUrl = exports.createAgnosticRuntime = exports.RuntimeWorkflowsNamespace = exports.RuntimeWorkflowRunsNamespace = exports.RuntimeDataViewTableClient = exports.RuntimeDataViewClient = exports.RuntimeDataTableClient = exports.RuntimeDataRecordsClient = exports.RuntimeDataNamespace = exports.RuntimeContextNamespace = exports.RuntimeAppAuthNamespace = exports.AgnosticRuntime = void 0;
3
+ exports.AGNOSTIC_RUNTIME_SDK_MANIFEST = exports.AgnosticRuntimeError = exports.resolveRuntimeContext = exports.normalizeApiUrl = exports.createAgnosticRuntime = exports.RuntimeWorkflowsNamespace = exports.RuntimeWorkflowRunsNamespace = exports.RuntimeStorageNamespace = exports.RuntimeStorageBucketClient = exports.RuntimeAnonymousUploadsClient = exports.RuntimeDataViewTableClient = exports.RuntimeDataViewClient = exports.RuntimeDataTableClient = exports.RuntimeDataRecordsClient = exports.RuntimeDataNamespace = exports.RuntimeContextNamespace = exports.RuntimeAppAuthNamespace = exports.AgnosticRuntime = void 0;
4
4
  var runtime_client_1 = require("./lib/runtime-client");
5
5
  Object.defineProperty(exports, "AgnosticRuntime", { enumerable: true, get: function () { return runtime_client_1.AgnosticRuntime; } });
6
6
  Object.defineProperty(exports, "RuntimeAppAuthNamespace", { enumerable: true, get: function () { return runtime_client_1.RuntimeAppAuthNamespace; } });
@@ -10,6 +10,9 @@ Object.defineProperty(exports, "RuntimeDataRecordsClient", { enumerable: true, g
10
10
  Object.defineProperty(exports, "RuntimeDataTableClient", { enumerable: true, get: function () { return runtime_client_1.RuntimeDataTableClient; } });
11
11
  Object.defineProperty(exports, "RuntimeDataViewClient", { enumerable: true, get: function () { return runtime_client_1.RuntimeDataViewClient; } });
12
12
  Object.defineProperty(exports, "RuntimeDataViewTableClient", { enumerable: true, get: function () { return runtime_client_1.RuntimeDataViewTableClient; } });
13
+ Object.defineProperty(exports, "RuntimeAnonymousUploadsClient", { enumerable: true, get: function () { return runtime_client_1.RuntimeAnonymousUploadsClient; } });
14
+ Object.defineProperty(exports, "RuntimeStorageBucketClient", { enumerable: true, get: function () { return runtime_client_1.RuntimeStorageBucketClient; } });
15
+ Object.defineProperty(exports, "RuntimeStorageNamespace", { enumerable: true, get: function () { return runtime_client_1.RuntimeStorageNamespace; } });
13
16
  Object.defineProperty(exports, "RuntimeWorkflowRunsNamespace", { enumerable: true, get: function () { return runtime_client_1.RuntimeWorkflowRunsNamespace; } });
14
17
  Object.defineProperty(exports, "RuntimeWorkflowsNamespace", { enumerable: true, get: function () { return runtime_client_1.RuntimeWorkflowsNamespace; } });
15
18
  Object.defineProperty(exports, "createAgnosticRuntime", { enumerable: true, get: function () { return runtime_client_1.createAgnosticRuntime; } });
@@ -18,4 +21,6 @@ Object.defineProperty(exports, "normalizeApiUrl", { enumerable: true, get: funct
18
21
  Object.defineProperty(exports, "resolveRuntimeContext", { enumerable: true, get: function () { return context_1.resolveRuntimeContext; } });
19
22
  var errors_1 = require("./lib/errors");
20
23
  Object.defineProperty(exports, "AgnosticRuntimeError", { enumerable: true, get: function () { return errors_1.AgnosticRuntimeError; } });
24
+ var manifest_1 = require("./lib/manifest");
25
+ Object.defineProperty(exports, "AGNOSTIC_RUNTIME_SDK_MANIFEST", { enumerable: true, get: function () { return manifest_1.AGNOSTIC_RUNTIME_SDK_MANIFEST; } });
21
26
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,41 @@
1
+ export declare const AGNOSTIC_RUNTIME_SDK_MANIFEST: Readonly<{
2
+ readonly promptSync: Readonly<{
3
+ source: "sdk_exported_manifest";
4
+ strategy: "inject_on_every_agent_codegen_context";
5
+ surfaceFingerprint: string;
6
+ driftPolicy: "fail_ci_on_public_surface_or_package_version_mismatch";
7
+ memorizedSdkKnowledgeAllowed: false;
8
+ }>;
9
+ readonly schema: "agnostic_runtime_sdk_manifest.v1";
10
+ readonly package: Readonly<{
11
+ name: "@nsp-labs/agnostic-sdk";
12
+ version: "1.4.0";
13
+ factory: "createAgnosticRuntime";
14
+ runtime: "server_only";
15
+ }>;
16
+ readonly context: Readonly<{
17
+ automatic: true;
18
+ environmentVariables: readonly string[];
19
+ secretEnvironmentVariables: readonly string[];
20
+ }>;
21
+ readonly rootMembers: readonly [...("data" | "auth" | "context" | "storage" | "workflows" | "workflowRuns")[], "getRuntimeContext"];
22
+ readonly clientMethods: readonly ["getRuntimeContext"];
23
+ readonly namespaces: Readonly<{
24
+ auth: readonly ("requireSession" | "getSession" | "requireScopes" | "getUser")[];
25
+ context: readonly "get"[];
26
+ data: readonly ("table(name).records.delete" | "table(name).records.list" | "table(name).records.aggregate" | "table(name).records.create" | "table(name).records.update" | "view(id).table.window")[];
27
+ storage: readonly ("bucket(name).get" | "bucket(name).delete" | "bucket(name).createUpload" | "bucket(name).completeUpload" | "bucket(name).createDownloadUrl" | "bucket(name).anonymousUploads.claim")[];
28
+ workflows: readonly ("start" | "getRun")[];
29
+ workflowRuns: readonly ("get" | "wait" | "listSteps")[];
30
+ }>;
31
+ readonly unsupportedNamespaces: readonly string[];
32
+ readonly boundaries: Readonly<{
33
+ controlPlaneProvisioning: "agent_product_tools";
34
+ runtimeAccess: "server_sdk";
35
+ browserAccess: "public_api_or_app_auth_session";
36
+ appAuthSelfService: "public_api_via_project_backend_bff";
37
+ browserPackageImportAllowed: false;
38
+ browserRuntimeTokenAllowed: false;
39
+ }>;
40
+ }>;
41
+ export type AgnosticRuntimeSdkManifest = typeof AGNOSTIC_RUNTIME_SDK_MANIFEST;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AGNOSTIC_RUNTIME_SDK_MANIFEST = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const AUTH_KEYS_LITERAL = [
6
+ 'requireSession',
7
+ 'getSession',
8
+ 'requireScopes',
9
+ 'getUser',
10
+ ];
11
+ const AUTH_KEYS = AUTH_KEYS_LITERAL;
12
+ const CONTEXT_KEYS_LITERAL = ['get'];
13
+ const CONTEXT_KEYS = CONTEXT_KEYS_LITERAL;
14
+ const DATA_NAMESPACE_KEYS_LITERAL = ['table', 'view'];
15
+ const DATA_NAMESPACE_KEYS = DATA_NAMESPACE_KEYS_LITERAL;
16
+ const DATA_TABLE_KEYS_LITERAL = ['records'];
17
+ const DATA_TABLE_KEYS = DATA_TABLE_KEYS_LITERAL;
18
+ const DATA_RECORD_KEYS_LITERAL = [
19
+ 'list',
20
+ 'aggregate',
21
+ 'create',
22
+ 'update',
23
+ 'delete',
24
+ ];
25
+ const DATA_RECORD_KEYS = DATA_RECORD_KEYS_LITERAL;
26
+ const DATA_VIEW_KEYS_LITERAL = ['table'];
27
+ const DATA_VIEW_KEYS = DATA_VIEW_KEYS_LITERAL;
28
+ const DATA_VIEW_TABLE_KEYS_LITERAL = ['window'];
29
+ const DATA_VIEW_TABLE_KEYS = DATA_VIEW_TABLE_KEYS_LITERAL;
30
+ const STORAGE_NAMESPACE_KEYS_LITERAL = ['bucket'];
31
+ const STORAGE_NAMESPACE_KEYS = STORAGE_NAMESPACE_KEYS_LITERAL;
32
+ const STORAGE_BUCKET_KEYS_LITERAL = [
33
+ 'anonymousUploads',
34
+ 'createUpload',
35
+ 'completeUpload',
36
+ 'get',
37
+ 'createDownloadUrl',
38
+ 'delete',
39
+ ];
40
+ const STORAGE_BUCKET_KEYS = STORAGE_BUCKET_KEYS_LITERAL;
41
+ const ANONYMOUS_UPLOAD_KEYS_LITERAL = ['claim'];
42
+ const ANONYMOUS_UPLOAD_KEYS = ANONYMOUS_UPLOAD_KEYS_LITERAL;
43
+ const WORKFLOW_KEYS_LITERAL = ['start', 'getRun'];
44
+ const WORKFLOW_KEYS = WORKFLOW_KEYS_LITERAL;
45
+ const WORKFLOW_RUN_KEYS_LITERAL = ['get', 'wait', 'listSteps'];
46
+ const WORKFLOW_RUN_KEYS = WORKFLOW_RUN_KEYS_LITERAL;
47
+ const CLIENT_METHODS = Object.freeze(['getRuntimeContext']);
48
+ const NAMESPACES = Object.freeze({
49
+ auth: Object.freeze([...AUTH_KEYS]),
50
+ context: Object.freeze([...CONTEXT_KEYS]),
51
+ data: Object.freeze([
52
+ ...DATA_RECORD_KEYS.map((method) => `${DATA_NAMESPACE_KEYS[0]}(name).${DATA_TABLE_KEYS[0]}.${method}`),
53
+ ...DATA_VIEW_TABLE_KEYS.map((method) => `${DATA_NAMESPACE_KEYS[1]}(id).${DATA_VIEW_KEYS[0]}.${method}`),
54
+ ]),
55
+ storage: Object.freeze([
56
+ ...STORAGE_BUCKET_KEYS.filter((method) => method !== 'anonymousUploads').map((method) => `${STORAGE_NAMESPACE_KEYS[0]}(name).${method}`),
57
+ ...ANONYMOUS_UPLOAD_KEYS.map((method) => `${STORAGE_NAMESPACE_KEYS[0]}(name).${STORAGE_BUCKET_KEYS[0]}.${method}`),
58
+ ]),
59
+ workflows: Object.freeze([...WORKFLOW_KEYS]),
60
+ workflowRuns: Object.freeze([...WORKFLOW_RUN_KEYS]),
61
+ });
62
+ const ROOT_MEMBERS_LITERAL = Object.freeze([
63
+ ...Object.keys(NAMESPACES),
64
+ ...CLIENT_METHODS,
65
+ ]);
66
+ const ROOT_MEMBERS = ROOT_MEMBERS_LITERAL;
67
+ const MANIFEST_CONTRACT = Object.freeze({
68
+ schema: 'agnostic_runtime_sdk_manifest.v1',
69
+ package: Object.freeze({
70
+ name: '@nsp-labs/agnostic-sdk',
71
+ version: '1.4.0',
72
+ factory: 'createAgnosticRuntime',
73
+ runtime: 'server_only',
74
+ }),
75
+ context: Object.freeze({
76
+ automatic: true,
77
+ environmentVariables: Object.freeze([
78
+ 'AGNOSTIC_API_URL',
79
+ 'AGNOSTIC_PROJECT_ID',
80
+ 'AGNOSTIC_ENVIRONMENT',
81
+ 'AGNOSTIC_RUNTIME_TOKEN',
82
+ ]),
83
+ secretEnvironmentVariables: Object.freeze(['AGNOSTIC_RUNTIME_TOKEN']),
84
+ }),
85
+ rootMembers: ROOT_MEMBERS,
86
+ clientMethods: CLIENT_METHODS,
87
+ namespaces: NAMESPACES,
88
+ unsupportedNamespaces: Object.freeze([
89
+ 'ai',
90
+ 'events',
91
+ 'gateway',
92
+ 'jobs',
93
+ 'realtime',
94
+ ]),
95
+ boundaries: Object.freeze({
96
+ controlPlaneProvisioning: 'agent_product_tools',
97
+ runtimeAccess: 'server_sdk',
98
+ browserAccess: 'public_api_or_app_auth_session',
99
+ appAuthSelfService: 'public_api_via_project_backend_bff',
100
+ browserPackageImportAllowed: false,
101
+ browserRuntimeTokenAllowed: false,
102
+ }),
103
+ });
104
+ const surfaceFingerprint = `sha256:${(0, node_crypto_1.createHash)('sha256')
105
+ .update(JSON.stringify(MANIFEST_CONTRACT))
106
+ .digest('hex')}`;
107
+ exports.AGNOSTIC_RUNTIME_SDK_MANIFEST = Object.freeze({
108
+ ...MANIFEST_CONTRACT,
109
+ promptSync: Object.freeze({
110
+ source: 'sdk_exported_manifest',
111
+ strategy: 'inject_on_every_agent_codegen_context',
112
+ surfaceFingerprint,
113
+ driftPolicy: 'fail_ci_on_public_surface_or_package_version_mismatch',
114
+ memorizedSdkKnowledgeAllowed: false,
115
+ }),
116
+ });
117
+ //# sourceMappingURL=manifest.js.map
@@ -1,9 +1,10 @@
1
1
  import { type RuntimeOpenApiClient } from './http-client';
2
- import type { AgnosticRuntimeConfig, ResolvedRuntimeContext, RuntimeAppAuthRequestLike, RuntimeAppAuthSession, RuntimeAppAuthUserResult, RuntimeCreateRecordInput, RuntimeIdentityContext, RuntimeListRecordsOptions, RuntimeListWindowOptions, RuntimeRecordMutation, RuntimeRecordsList, RuntimeRequestOptions, RuntimeRowData, RuntimeTableWindow, RuntimeUpdateRecordInput, RuntimeWorkflowRun, RuntimeWorkflowStepRun, RuntimeWorkflowWaitOptions } from './types';
2
+ import type { AgnosticRuntimeConfig, ResolvedRuntimeContext, RuntimeAppAuthRequestLike, RuntimeAppAuthSession, RuntimeAppAuthUserResult, RuntimeAnonymousClaimInput, RuntimeAnonymousClaimResult, RuntimeAggregateRecordsInput, RuntimeAggregateRecordsResult, RuntimeCreateFileUploadInput, RuntimeCreateRecordInput, RuntimeIdentityContext, RuntimeFileDownloadUrl, RuntimeFileObject, RuntimeFileUploadCompletion, RuntimeFileUploadGrant, RuntimeListRecordsOptions, RuntimeListWindowOptions, RuntimeRecordMutation, RuntimeRecordsList, RuntimeRequestOptions, RuntimeRowData, RuntimeTableWindow, RuntimeUpdateRecordInput, RuntimeWorkflowRun, RuntimeWorkflowStepRun, RuntimeWorkflowWaitOptions } from './types';
3
3
  export declare class AgnosticRuntime {
4
4
  readonly auth: RuntimeAppAuthNamespace;
5
5
  readonly context: RuntimeContextNamespace;
6
6
  readonly data: RuntimeDataNamespace;
7
+ readonly storage: RuntimeStorageNamespace;
7
8
  readonly workflows: RuntimeWorkflowsNamespace;
8
9
  readonly workflowRuns: RuntimeWorkflowRunsNamespace;
9
10
  private readonly openapi;
@@ -15,6 +16,8 @@ export declare class RuntimeAppAuthNamespace {
15
16
  private readonly openapi;
16
17
  constructor(openapi: RuntimeOpenApiClient);
17
18
  requireSession(request: RuntimeAppAuthRequestLike | string, options?: RuntimeRequestOptions): Promise<RuntimeAppAuthSession>;
19
+ getSession(request: RuntimeAppAuthRequestLike | string, options?: RuntimeRequestOptions): Promise<RuntimeAppAuthSession | null>;
20
+ requireScopes(request: RuntimeAppAuthRequestLike | string, scopes: readonly string[], options?: RuntimeRequestOptions): Promise<RuntimeAppAuthSession>;
18
21
  getUser(userId: string, options?: RuntimeRequestOptions): Promise<RuntimeAppAuthUserResult>;
19
22
  }
20
23
  export declare function createAgnosticRuntime(config?: AgnosticRuntimeConfig): AgnosticRuntime;
@@ -29,6 +32,28 @@ export declare class RuntimeDataNamespace {
29
32
  table(tableName: string): RuntimeDataTableClient;
30
33
  view(viewId: string): RuntimeDataViewClient;
31
34
  }
35
+ export declare class RuntimeStorageNamespace {
36
+ private readonly openapi;
37
+ constructor(openapi: RuntimeOpenApiClient);
38
+ bucket(bucketIdOrSlug: string): RuntimeStorageBucketClient;
39
+ }
40
+ export declare class RuntimeStorageBucketClient {
41
+ private readonly openapi;
42
+ private readonly bucketIdOrSlug;
43
+ readonly anonymousUploads: RuntimeAnonymousUploadsClient;
44
+ constructor(openapi: RuntimeOpenApiClient, bucketIdOrSlug: string);
45
+ createUpload(input: RuntimeCreateFileUploadInput, options?: RuntimeRequestOptions): Promise<RuntimeFileUploadGrant>;
46
+ completeUpload(uploadId: string, options?: RuntimeRequestOptions): Promise<RuntimeFileUploadCompletion>;
47
+ get(fileId: string, options?: RuntimeRequestOptions): Promise<RuntimeFileObject>;
48
+ createDownloadUrl(fileId: string, options?: RuntimeRequestOptions): Promise<RuntimeFileDownloadUrl>;
49
+ delete(fileId: string, options?: RuntimeRequestOptions): Promise<void>;
50
+ }
51
+ export declare class RuntimeAnonymousUploadsClient {
52
+ private readonly openapi;
53
+ private readonly bucketIdOrSlug;
54
+ constructor(openapi: RuntimeOpenApiClient, bucketIdOrSlug: string);
55
+ claim(input: RuntimeAnonymousClaimInput, options?: RuntimeRequestOptions): Promise<RuntimeAnonymousClaimResult>;
56
+ }
32
57
  export declare class RuntimeDataTableClient {
33
58
  private readonly tableName;
34
59
  readonly records: RuntimeDataRecordsClient;
@@ -39,6 +64,7 @@ export declare class RuntimeDataRecordsClient {
39
64
  private readonly tableName;
40
65
  constructor(openapi: RuntimeOpenApiClient, tableName: string);
41
66
  list(query?: RuntimeListRecordsOptions, options?: RuntimeRequestOptions): Promise<RuntimeRecordsList>;
67
+ aggregate(input: RuntimeAggregateRecordsInput, options?: RuntimeRequestOptions): Promise<RuntimeAggregateRecordsResult>;
42
68
  create(input: RuntimeCreateRecordInput | RuntimeRowData, options?: RuntimeRequestOptions): Promise<RuntimeRecordMutation>;
43
69
  update(recordId: string, input: RuntimeUpdateRecordInput | RuntimeRowData, options?: RuntimeRequestOptions): Promise<RuntimeRecordMutation>;
44
70
  delete(recordId: string, options?: RuntimeRequestOptions): Promise<RuntimeRecordMutation>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuntimeWorkflowRunsNamespace = exports.RuntimeWorkflowsNamespace = exports.RuntimeDataViewTableClient = exports.RuntimeDataViewClient = exports.RuntimeDataRecordsClient = exports.RuntimeDataTableClient = exports.RuntimeDataNamespace = exports.RuntimeContextNamespace = exports.RuntimeAppAuthNamespace = exports.AgnosticRuntime = void 0;
3
+ exports.RuntimeWorkflowRunsNamespace = exports.RuntimeWorkflowsNamespace = exports.RuntimeDataViewTableClient = exports.RuntimeDataViewClient = exports.RuntimeDataRecordsClient = exports.RuntimeDataTableClient = exports.RuntimeAnonymousUploadsClient = exports.RuntimeStorageBucketClient = exports.RuntimeStorageNamespace = exports.RuntimeDataNamespace = exports.RuntimeContextNamespace = exports.RuntimeAppAuthNamespace = exports.AgnosticRuntime = void 0;
4
4
  exports.createAgnosticRuntime = createAgnosticRuntime;
5
5
  const http_client_1 = require("./http-client");
6
6
  const context_1 = require("./context");
@@ -9,8 +9,14 @@ const APP_AUTH_VERIFY_SESSION_PATH = '/api/v1/runtime/app-auth/session/verify';
9
9
  const APP_AUTH_USER_PATH = '/api/v1/runtime/app-auth/users/{userId}';
10
10
  const AUTH_CONTEXT_PATH = '/api/v1/runtime/auth/context';
11
11
  const DATA_RECORDS_PATH = '/api/v1/runtime/data/tables/{tableName}/records';
12
+ const DATA_AGGREGATE_PATH = '/api/v1/runtime/data/tables/{tableName}/records/aggregate';
12
13
  const DATA_RECORD_PATH = '/api/v1/runtime/data/tables/{tableName}/records/{recordId}';
13
14
  const DATA_VIEW_WINDOW_PATH = '/api/v1/runtime/data/views/{viewId}/table/window';
15
+ const FILES_ANONYMOUS_CLAIM_PATH = '/api/v1/runtime/files/buckets/{bucketRef}/anonymous-upload-sessions/claim';
16
+ const FILES_UPLOADS_PATH = '/api/v1/runtime/files/buckets/{bucketRef}/uploads';
17
+ const FILES_UPLOAD_COMPLETE_PATH = '/api/v1/runtime/files/buckets/{bucketRef}/uploads/{uploadId}/complete';
18
+ const FILES_OBJECT_PATH = '/api/v1/runtime/files/buckets/{bucketRef}/objects/{fileId}';
19
+ const FILES_DOWNLOAD_PATH = '/api/v1/runtime/files/buckets/{bucketRef}/objects/{fileId}/download';
14
20
  const WORKFLOWS_START_PATH = '/api/v1/runtime/workflows/{workflowSlug}/runs';
15
21
  const WORKFLOW_RUN_PATH = '/api/v1/runtime/workflow-runs/{runId}';
16
22
  const WORKFLOW_RUN_STEPS_PATH = '/api/v1/runtime/workflow-runs/{runId}/steps';
@@ -32,6 +38,7 @@ class AgnosticRuntime {
32
38
  this.auth = new RuntimeAppAuthNamespace(this.openapi);
33
39
  this.context = new RuntimeContextNamespace(this.openapi);
34
40
  this.data = new RuntimeDataNamespace(this.openapi);
41
+ this.storage = new RuntimeStorageNamespace(this.openapi);
35
42
  this.workflowRuns = new RuntimeWorkflowRunsNamespace(this.openapi);
36
43
  this.workflows = new RuntimeWorkflowsNamespace(this.openapi, this.workflowRuns);
37
44
  }
@@ -58,11 +65,35 @@ class RuntimeAppAuthNamespace {
58
65
  },
59
66
  });
60
67
  }
61
- const result = await this.openapi.POST(APP_AUTH_VERIFY_SESSION_PATH, {
62
- body: { sessionToken },
63
- headers: (0, http_client_1.runtimeRequestHeaders)(options),
64
- });
65
- return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to verify App Auth session');
68
+ return verifyAppAuthSession(this.openapi, sessionToken, options);
69
+ }
70
+ async getSession(request, options) {
71
+ const sessionToken = typeof request === 'string'
72
+ ? normalizeSessionToken(request)
73
+ : extractAppSessionToken(request);
74
+ if (!sessionToken) {
75
+ return null;
76
+ }
77
+ return verifyAppAuthSession(this.openapi, sessionToken, options);
78
+ }
79
+ async requireScopes(request, scopes, options) {
80
+ const session = await this.requireSession(request, options);
81
+ const requiredScopes = Array.from(new Set(scopes.map((scope) => scope.trim()).filter(Boolean)));
82
+ const availableScopes = new Set(session.user.scopes);
83
+ const missingScopes = requiredScopes.filter((scope) => !availableScopes.has(scope));
84
+ if (missingScopes.length > 0) {
85
+ throw new errors_1.AgnosticRuntimeError({
86
+ status: 403,
87
+ code: 'app_auth_scope_missing',
88
+ message: 'App user is missing a required scope',
89
+ details: {
90
+ availableScopes: session.user.scopes,
91
+ missingScopes,
92
+ requiredScopes,
93
+ },
94
+ });
95
+ }
96
+ return session;
66
97
  }
67
98
  async getUser(userId, options) {
68
99
  const result = await this.openapi.GET(APP_AUTH_USER_PATH, {
@@ -78,6 +109,13 @@ exports.RuntimeAppAuthNamespace = RuntimeAppAuthNamespace;
78
109
  function createAgnosticRuntime(config = {}) {
79
110
  return new AgnosticRuntime(config);
80
111
  }
112
+ async function verifyAppAuthSession(openapi, sessionToken, options) {
113
+ const result = await openapi.POST(APP_AUTH_VERIFY_SESSION_PATH, {
114
+ body: { sessionToken },
115
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
116
+ });
117
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to verify App Auth session');
118
+ }
81
119
  class RuntimeContextNamespace {
82
120
  constructor(openapi) {
83
121
  this.openapi = openapi;
@@ -102,6 +140,76 @@ class RuntimeDataNamespace {
102
140
  }
103
141
  }
104
142
  exports.RuntimeDataNamespace = RuntimeDataNamespace;
143
+ class RuntimeStorageNamespace {
144
+ constructor(openapi) {
145
+ this.openapi = openapi;
146
+ }
147
+ bucket(bucketIdOrSlug) {
148
+ return new RuntimeStorageBucketClient(this.openapi, bucketIdOrSlug);
149
+ }
150
+ }
151
+ exports.RuntimeStorageNamespace = RuntimeStorageNamespace;
152
+ class RuntimeStorageBucketClient {
153
+ constructor(openapi, bucketIdOrSlug) {
154
+ this.openapi = openapi;
155
+ this.bucketIdOrSlug = bucketIdOrSlug;
156
+ this.anonymousUploads = new RuntimeAnonymousUploadsClient(openapi, bucketIdOrSlug);
157
+ }
158
+ async createUpload(input, options) {
159
+ const result = await this.openapi.POST(FILES_UPLOADS_PATH, {
160
+ body: input,
161
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
162
+ params: { path: { bucketRef: this.bucketIdOrSlug } },
163
+ });
164
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to create file upload');
165
+ }
166
+ async completeUpload(uploadId, options) {
167
+ const result = await this.openapi.POST(FILES_UPLOAD_COMPLETE_PATH, {
168
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
169
+ params: { path: { bucketRef: this.bucketIdOrSlug, uploadId } },
170
+ });
171
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to complete file upload');
172
+ }
173
+ async get(fileId, options) {
174
+ const result = await this.openapi.GET(FILES_OBJECT_PATH, {
175
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
176
+ params: { path: { bucketRef: this.bucketIdOrSlug, fileId } },
177
+ });
178
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to load file status');
179
+ }
180
+ async createDownloadUrl(fileId, options) {
181
+ const result = await this.openapi.POST(FILES_DOWNLOAD_PATH, {
182
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
183
+ params: { path: { bucketRef: this.bucketIdOrSlug, fileId } },
184
+ });
185
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to create file download URL');
186
+ }
187
+ async delete(fileId, options) {
188
+ const result = await this.openapi.DELETE(FILES_OBJECT_PATH, {
189
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
190
+ params: { path: { bucketRef: this.bucketIdOrSlug, fileId } },
191
+ });
192
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to delete file');
193
+ }
194
+ }
195
+ exports.RuntimeStorageBucketClient = RuntimeStorageBucketClient;
196
+ class RuntimeAnonymousUploadsClient {
197
+ constructor(openapi, bucketIdOrSlug) {
198
+ this.openapi = openapi;
199
+ this.bucketIdOrSlug = bucketIdOrSlug;
200
+ }
201
+ async claim(input, options) {
202
+ const result = await this.openapi.POST(FILES_ANONYMOUS_CLAIM_PATH, {
203
+ body: input,
204
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
205
+ params: {
206
+ path: { bucketRef: this.bucketIdOrSlug },
207
+ },
208
+ });
209
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to claim anonymous uploads');
210
+ }
211
+ }
212
+ exports.RuntimeAnonymousUploadsClient = RuntimeAnonymousUploadsClient;
105
213
  class RuntimeDataTableClient {
106
214
  constructor(openapi, tableName) {
107
215
  this.tableName = tableName;
@@ -124,6 +232,16 @@ class RuntimeDataRecordsClient {
124
232
  });
125
233
  return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to list data records');
126
234
  }
235
+ async aggregate(input, options) {
236
+ const result = await this.openapi.POST(DATA_AGGREGATE_PATH, {
237
+ body: input,
238
+ headers: (0, http_client_1.runtimeRequestHeaders)(options),
239
+ params: {
240
+ path: { tableName: this.tableName },
241
+ },
242
+ });
243
+ return (0, http_client_1.unwrapRuntimeResult)(result, 'Failed to aggregate data records');
244
+ }
127
245
  async create(input, options) {
128
246
  const result = await this.openapi.POST(DATA_RECORDS_PATH, {
129
247
  body: normalizeCreateRecordInput(input),
@@ -39,6 +39,72 @@ export interface RuntimeRequestOptions {
39
39
  actor?: RuntimeActorMetadata | null;
40
40
  headers?: Record<string, string>;
41
41
  }
42
+ export interface RuntimeAnonymousClaimInput {
43
+ token: string;
44
+ externalRef: string;
45
+ idempotencyKey: string;
46
+ }
47
+ export interface RuntimeAnonymousClaimFileHandle {
48
+ fileId: string;
49
+ status: 'ready' | 'processing';
50
+ }
51
+ export interface RuntimeAnonymousClaimResult {
52
+ sessionId: string;
53
+ bucketId: string;
54
+ externalRef: string;
55
+ claimedAt: string;
56
+ files: RuntimeAnonymousClaimFileHandle[];
57
+ }
58
+ export type RuntimeFileAccessMode = 'private' | 'authenticated' | 'team' | 'public';
59
+ export type RuntimeFileObjectStatus = 'pending_upload' | 'uploaded' | 'scanning' | 'ready' | 'verified_unclaimed' | 'claimed_ready' | 'deleting' | 'deleted' | 'rejected' | 'quarantined' | 'expired';
60
+ export interface RuntimeCreateFileUploadInput {
61
+ fileName: string;
62
+ contentType: string;
63
+ size: number;
64
+ checksumSha256: string;
65
+ access?: RuntimeFileAccessMode;
66
+ idempotencyKey: string;
67
+ }
68
+ export interface RuntimeFileUploadGrant {
69
+ id: string;
70
+ fileId: string;
71
+ bucketId: string;
72
+ status: 'issued' | 'uploaded' | 'verifying' | 'completed' | 'rejected' | 'expired';
73
+ expectedSizeBytes: number;
74
+ expiresAt: string;
75
+ completedAt: string | null;
76
+ uploadUrl: string;
77
+ uploadUrlExpiresAt: string;
78
+ requiredHeaders: Readonly<Record<string, string>>;
79
+ }
80
+ export interface RuntimeFileObject {
81
+ id: string;
82
+ bucketId: string;
83
+ projectId: string;
84
+ environment: string;
85
+ originalName: string;
86
+ detectedMime: string | null;
87
+ sizeBytes: number | null;
88
+ checksumSha256: string | null;
89
+ status: RuntimeFileObjectStatus;
90
+ access: RuntimeFileAccessMode;
91
+ readyAt: string | null;
92
+ deletedAt: string | null;
93
+ billableUntil: string | null;
94
+ physicalDeleteDueAt: string | null;
95
+ physicalDeletedAt: string | null;
96
+ expiresAt: string | null;
97
+ createdAt: string;
98
+ updatedAt: string;
99
+ }
100
+ export interface RuntimeFileUploadCompletion {
101
+ upload: Omit<RuntimeFileUploadGrant, 'uploadUrl' | 'uploadUrlExpiresAt' | 'requiredHeaders'>;
102
+ file: RuntimeFileObject;
103
+ }
104
+ export interface RuntimeFileDownloadUrl {
105
+ url: string;
106
+ expiresAt: string;
107
+ }
42
108
  export type RuntimeHeaderValue = string | string[] | undefined;
43
109
  export interface RuntimeAppAuthRequestLike {
44
110
  headers?: Headers | Record<string, RuntimeHeaderValue> | {
@@ -92,6 +158,33 @@ export interface RuntimeListRecordsOptions {
92
158
  q?: string;
93
159
  sort?: string;
94
160
  }
161
+ export type RuntimeAggregateOperation = 'count' | 'sum' | 'avg' | 'min' | 'max';
162
+ export interface RuntimeAggregateMetric {
163
+ operation: RuntimeAggregateOperation;
164
+ field?: string;
165
+ as: string;
166
+ }
167
+ export interface RuntimeAggregateOrderBy {
168
+ by: string;
169
+ direction: 'asc' | 'desc';
170
+ }
171
+ export interface RuntimeAggregateRecordsInput {
172
+ filter?: Record<string, unknown>;
173
+ q?: string;
174
+ groupBy?: string[];
175
+ metrics: RuntimeAggregateMetric[];
176
+ orderBy?: RuntimeAggregateOrderBy[];
177
+ limit?: number;
178
+ }
179
+ export interface RuntimeAggregateRow {
180
+ dimensions: Record<string, RuntimeScalar>;
181
+ metrics: Record<string, string | number | null>;
182
+ }
183
+ export interface RuntimeAggregateRecordsResult {
184
+ rows: RuntimeAggregateRow[];
185
+ limit: number;
186
+ hasMore: boolean;
187
+ }
95
188
  export interface RuntimeListWindowOptions {
96
189
  cursor?: string;
97
190
  limit?: number;