@sequenceholdings/studio-cli 0.1.30 → 0.1.35
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/README.md +225 -16
- package/dist/atlas-client.d.ts +16 -0
- package/dist/atlas-client.js +26 -0
- package/dist/functions/bundle.js +4 -2
- package/dist/functions/commands.d.ts +12 -2
- package/dist/functions/commands.js +176 -14
- package/dist/functions/dev.d.ts +3 -0
- package/dist/functions/dev.js +97 -0
- package/dist/functions/egress-preview.d.ts +2 -1
- package/dist/functions/egress-preview.js +3 -2
- package/dist/functions/manifest.d.ts +18 -1
- package/dist/functions/manifest.js +19 -29
- package/dist/main.js +6 -1
- package/dist/pipeline/commands.js +16 -10
- package/dist/pipeline/lifecycle.d.ts +1 -0
- package/dist/pipeline/lifecycle.js +105 -28
- package/dist/pipeline/migrations.js +6 -1
- package/dist/pipeline/stage-secrets.d.ts +95 -0
- package/dist/pipeline/stage-secrets.js +166 -0
- package/dist/pipeline/templates.d.ts +1 -1
- package/dist/pipeline/templates.js +37 -3
- package/dist/process/build.js +1 -0
- package/dist/process/codegen.js +1 -0
- package/dist/process/lint.js +12 -7
- package/dist/process/plan-diff.js +1 -0
- package/dist/process/safety-baseline.d.ts +3 -3
- package/dist/process/safety-baseline.js +4 -5
- package/dist/process/simulate.js +7 -2
- package/dist/repos/commands.d.ts +1 -1
- package/dist/repos/commands.js +15 -7
- package/dist/secrets/commands.d.ts +1 -1
- package/dist/secrets/commands.js +73 -3
- package/dist/storage/commands.d.ts +2 -0
- package/dist/storage/commands.js +215 -0
- package/dist/templates/process/pnpm-workspace.yaml +2 -0
- package/package.json +9 -7
- package/templates/process/pnpm-workspace.yaml +2 -0
|
@@ -6,9 +6,10 @@ import { promisify } from 'node:util';
|
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
7
7
|
import { Writable } from 'node:stream';
|
|
8
8
|
import { load as parseYaml } from 'js-yaml';
|
|
9
|
+
import { MANAGED_FUNCTION_LIMITS, MF_LIMITS_DEFAULTS } from '@sequenceholdings/managed-functions/config';
|
|
9
10
|
import { getAccessTokenWithMode, tryGetAccessTokenWithMode } from '../auth.js';
|
|
10
11
|
import { resolveEnvWithDiscovery } from '../config.js';
|
|
11
|
-
import { AtlasApiError, deleteJson, getJson, postJson } from '../atlas-client.js';
|
|
12
|
+
import { AtlasApiError, deleteJson, getJson, postJson, postJsonResponse, } from '../atlas-client.js';
|
|
12
13
|
import { clarifyApplyFailureReason, printCliError } from '../cli-errors.js';
|
|
13
14
|
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
14
15
|
import { confirmYes } from '../prompt.js';
|
|
@@ -17,8 +18,8 @@ import { managedFunctionManifestSchema, MF_MANIFEST_FILENAME, manifestEgressHost
|
|
|
17
18
|
import { buildEgressPreviewLines, egressPropagationNote, formatEgressSummary, printFunctionEgressHosts, } from './egress-preview.js';
|
|
18
19
|
import { resolveArtifactSource, } from '@sequenceholdings/artifact-studio/source-resolver';
|
|
19
20
|
import { buildSecretPreviewLines, classifySecrets, } from './secret-reconcile.js';
|
|
20
|
-
import { parseFunctionsSourceSelection, resolveFunctionSourceDir
|
|
21
|
-
export { parseFunctionsSourceSelection, parseFunctionsSourceSpec, resolveFunctionSourceDir } from './source-selection.js';
|
|
21
|
+
import { parseFunctionsSourceSelection, resolveFunctionSourceDir } from './source-selection.js';
|
|
22
|
+
export { parseFunctionsSourceSelection, parseFunctionsSourceSpec, resolveFunctionSourceDir, } from './source-selection.js';
|
|
22
23
|
const execFileAsync = promisify(execFile);
|
|
23
24
|
export const LOG = '[seq-studio]';
|
|
24
25
|
const POLL_INTERVAL_MS = 5_000;
|
|
@@ -196,11 +197,20 @@ runtime: nodejs20
|
|
|
196
197
|
entrypoint: handler
|
|
197
198
|
|
|
198
199
|
limits:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
cpu: ${MF_LIMITS_DEFAULTS.cpu}
|
|
201
|
+
concurrency: ${MF_LIMITS_DEFAULTS.concurrency}
|
|
202
|
+
memory_mb: ${MF_LIMITS_DEFAULTS.memoryMb}
|
|
203
|
+
timeout_seconds: ${MF_LIMITS_DEFAULTS.timeoutSeconds}
|
|
204
|
+
min_instances: ${MF_LIMITS_DEFAULTS.minInstances}
|
|
205
|
+
max_instances: ${MF_LIMITS_DEFAULTS.maxInstances}
|
|
206
|
+
invoke_rate_per_minute: ${MF_LIMITS_DEFAULTS.invokeRatePerMinute}
|
|
207
|
+
|
|
208
|
+
# Opt-in per-function Valkey cache (allocated continuously, even while idle).
|
|
209
|
+
# cache:
|
|
210
|
+
# enabled: true
|
|
211
|
+
# tier: ${MANAGED_FUNCTION_LIMITS.cache.tier.default}
|
|
212
|
+
# replicas: ${MANAGED_FUNCTION_LIMITS.cache.replicas.default}
|
|
213
|
+
# default_ttl_seconds: ${MANAGED_FUNCTION_LIMITS.cache.default_ttl_seconds.default}
|
|
204
214
|
|
|
205
215
|
# Optional source-IP gate, checked before invocation permissions. Omit or leave
|
|
206
216
|
# empty for unrestricted source IPs.
|
|
@@ -226,15 +236,15 @@ output_schema:
|
|
|
226
236
|
message:
|
|
227
237
|
type: string
|
|
228
238
|
`;
|
|
229
|
-
const TEMPLATE_HANDLER = `import {
|
|
239
|
+
const TEMPLATE_HANDLER = `import { type Request, type Response } from '@google-cloud/functions-framework'
|
|
230
240
|
|
|
231
241
|
// The entrypoint named in managed-function.yml. Atlas proxies authorized
|
|
232
242
|
// POSTs here with a JSON body matching input_schema. Shared secrets are
|
|
233
243
|
// env-mounted at deploy time — read them via process.env.<NAME>.
|
|
234
|
-
|
|
244
|
+
export function handler(req: Request, res: Response) {
|
|
235
245
|
const { name } = (req.body ?? {}) as { name?: string }
|
|
236
246
|
res.json({ message: \`Hello, \${name ?? 'world'}!\` })
|
|
237
|
-
}
|
|
247
|
+
}
|
|
238
248
|
`;
|
|
239
249
|
// TypeScript is compiled server-side by the deploy worker (\`tsc\` runs with
|
|
240
250
|
// devDependencies installed, then the tree is pruned to \`--prod\`), so the
|
|
@@ -259,6 +269,7 @@ const TEMPLATE_PACKAGE_JSON = (id) => JSON.stringify({
|
|
|
259
269
|
name: id,
|
|
260
270
|
version: '0.0.1',
|
|
261
271
|
private: true,
|
|
272
|
+
packageManager: 'pnpm@10.28.2',
|
|
262
273
|
// The deploy worker compiles index.ts -> dist/index.js; `main` points at
|
|
263
274
|
// the compiled output Cloud Functions loads.
|
|
264
275
|
main: 'dist/index.js',
|
|
@@ -703,7 +714,7 @@ async function deployFromResolvedSource({ args, spec, ctx: earlyCtx, source, })
|
|
|
703
714
|
if (createdShell) {
|
|
704
715
|
console.log(`${LOG} registered shell for "${slug}"`);
|
|
705
716
|
}
|
|
706
|
-
console.log(`${LOG} version ${version.version} uploaded — building (server-side install +
|
|
717
|
+
console.log(`${LOG} version ${version.version} uploaded — building (server-side install + function startup)`);
|
|
707
718
|
if (args.flags['no-wait']) {
|
|
708
719
|
console.log(`${LOG} not waiting (--no-wait). Poll with: seq-studio functions list -e ${ctx.env.name}`);
|
|
709
720
|
return 0;
|
|
@@ -812,6 +823,7 @@ async function printFunctionShowDetails({ ctx, fn, }) {
|
|
|
812
823
|
printFunctionEgressHosts({
|
|
813
824
|
log: LOG,
|
|
814
825
|
hosts: detail?.function.egressHosts ?? fn.egressHosts ?? [],
|
|
826
|
+
platformHosts: detail?.function.platformEgressHosts ?? fn.platformEgressHosts ?? [],
|
|
815
827
|
ipRanges: detail?.function.egressIpRanges ?? fn.egressIpRanges ?? [],
|
|
816
828
|
egressEnforced: detail?.function.egressEnforced ?? fn.egressEnforced ?? false,
|
|
817
829
|
});
|
|
@@ -846,6 +858,135 @@ export async function functionsShowCommand(args) {
|
|
|
846
858
|
}
|
|
847
859
|
return 0;
|
|
848
860
|
}
|
|
861
|
+
export async function functionsLimitsCommand(args) {
|
|
862
|
+
for (const flag of ['e', 'env', 'fn']) {
|
|
863
|
+
if (args.flags[flag] !== undefined && (typeof args.flags[flag] !== 'string' || !args.flags[flag])) {
|
|
864
|
+
throw new Error(`--${flag} requires a value`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if (args.flags.fn && !requestedEnvironment(args)) {
|
|
868
|
+
throw new Error('--fn requires -e/--env to read the function’s effective limits');
|
|
869
|
+
}
|
|
870
|
+
const ctx = requestedEnvironment(args) ? await buildContext(args) : null;
|
|
871
|
+
const limits = ctx
|
|
872
|
+
? (await getJson({
|
|
873
|
+
...clientOptions(ctx), path: '/api/managed-functions/limits',
|
|
874
|
+
})).limits
|
|
875
|
+
: MANAGED_FUNCTION_LIMITS;
|
|
876
|
+
let effective;
|
|
877
|
+
if (ctx && args.flags.fn) {
|
|
878
|
+
const fn = await resolveFunction({ ctx, args, required: true });
|
|
879
|
+
if (!fn)
|
|
880
|
+
return 1;
|
|
881
|
+
const detail = await getFunctionDetail(ctx, fn.id);
|
|
882
|
+
if (!detail?.function.limits)
|
|
883
|
+
throw new Error('Effective limits are not available for this function');
|
|
884
|
+
effective = { id: fn.id, slug: fn.slug, limits: detail.function.limits };
|
|
885
|
+
}
|
|
886
|
+
const source = ctx ? 'environment' : 'installed-cli';
|
|
887
|
+
if (flagBool(args.flags, 'json')) {
|
|
888
|
+
console.log(JSON.stringify({ source, environment: ctx?.env.name ?? null, limits, function: effective }, null, 2));
|
|
889
|
+
return 0;
|
|
890
|
+
}
|
|
891
|
+
console.log(ctx
|
|
892
|
+
? `${LOG} managed function limits enforced by ${ctx.env.name}:`
|
|
893
|
+
: `${LOG} bundled limits (installed CLI); use -e <env> for deployed policy:`);
|
|
894
|
+
for (const [group, entries] of Object.entries(limits)) {
|
|
895
|
+
console.log(`\n${group}:`);
|
|
896
|
+
for (const [name, limit] of Object.entries(entries)) {
|
|
897
|
+
const fields = Object.entries(limit).map(([key, value]) => `${key}=${Array.isArray(value) ? value.join(', ') : value}`);
|
|
898
|
+
console.log(` ${name}: ${fields.join(' · ')}`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (effective) {
|
|
902
|
+
console.log(`\nEffective runtime limits for ${effective.slug}:`);
|
|
903
|
+
for (const [name, value] of Object.entries(effective.limits))
|
|
904
|
+
console.log(` ${name}: ${value}`);
|
|
905
|
+
}
|
|
906
|
+
return 0;
|
|
907
|
+
}
|
|
908
|
+
// ---------------------------------------------------------------------------
|
|
909
|
+
// invoke
|
|
910
|
+
// ---------------------------------------------------------------------------
|
|
911
|
+
async function readStdin() {
|
|
912
|
+
const chunks = [];
|
|
913
|
+
for await (const chunk of process.stdin) {
|
|
914
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
915
|
+
}
|
|
916
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
917
|
+
}
|
|
918
|
+
export async function parseInvokePayload({ data, useStdin = false, cwd = process.cwd(), readStdin: readStdinInput = readStdin, }) {
|
|
919
|
+
let raw = '{}';
|
|
920
|
+
let source = '--data';
|
|
921
|
+
if (useStdin || data === '-') {
|
|
922
|
+
raw = await readStdinInput();
|
|
923
|
+
source = 'stdin';
|
|
924
|
+
}
|
|
925
|
+
else if (data?.startsWith('@')) {
|
|
926
|
+
const filename = data.slice(1);
|
|
927
|
+
if (!filename)
|
|
928
|
+
throw new Error('--data @<file> requires a file path');
|
|
929
|
+
const path = resolve(cwd, filename);
|
|
930
|
+
try {
|
|
931
|
+
raw = await readFile(path, 'utf8');
|
|
932
|
+
}
|
|
933
|
+
catch (error) {
|
|
934
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
935
|
+
throw new Error(`Could not read invoke data file ${path}: ${detail}`);
|
|
936
|
+
}
|
|
937
|
+
source = `@${filename}`;
|
|
938
|
+
}
|
|
939
|
+
else if (data !== undefined) {
|
|
940
|
+
raw = data;
|
|
941
|
+
}
|
|
942
|
+
try {
|
|
943
|
+
return JSON.parse(raw);
|
|
944
|
+
}
|
|
945
|
+
catch (error) {
|
|
946
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
947
|
+
throw new Error(`Invalid JSON from ${source}: ${detail}`);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function formatInvokeBody(body, contentType) {
|
|
951
|
+
const looksLikeJson = contentType.toLowerCase().includes('json') || /^\s*[{[]/.test(body);
|
|
952
|
+
if (!looksLikeJson)
|
|
953
|
+
return body;
|
|
954
|
+
try {
|
|
955
|
+
return JSON.stringify(JSON.parse(body), null, 2);
|
|
956
|
+
}
|
|
957
|
+
catch {
|
|
958
|
+
return body;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
export async function functionsInvokeCommand(args) {
|
|
962
|
+
const dataFlag = args.flags.data;
|
|
963
|
+
if (dataFlag === true) {
|
|
964
|
+
throw new Error('--data requires inline JSON, @<file>, or =- for stdin');
|
|
965
|
+
}
|
|
966
|
+
if (args.flags.stdin !== undefined && !flagBool(args.flags, 'stdin')) {
|
|
967
|
+
throw new Error('--stdin does not take a value');
|
|
968
|
+
}
|
|
969
|
+
const useStdin = flagBool(args.flags, 'stdin') || dataFlag === '-';
|
|
970
|
+
if (args.flags.stdin !== undefined && dataFlag !== undefined) {
|
|
971
|
+
throw new Error('Choose either --data or --stdin, not both');
|
|
972
|
+
}
|
|
973
|
+
const payload = await parseInvokePayload({
|
|
974
|
+
data: typeof dataFlag === 'string' ? dataFlag : undefined,
|
|
975
|
+
useStdin,
|
|
976
|
+
});
|
|
977
|
+
const ctx = await buildContext(args);
|
|
978
|
+
const fn = (await resolveFunction({ ctx, args }));
|
|
979
|
+
const result = await postJsonResponse({
|
|
980
|
+
...clientOptions(ctx),
|
|
981
|
+
path: `/api/managed-functions/${fn.id}/invoke`,
|
|
982
|
+
body: payload,
|
|
983
|
+
headers: { 'X-Invocation-Source': 'cli' },
|
|
984
|
+
});
|
|
985
|
+
const rendered = formatInvokeBody(result.body, result.contentType);
|
|
986
|
+
process.stdout.write(rendered.endsWith('\n') ? rendered : `${rendered}\n`);
|
|
987
|
+
console.error(`${LOG} ${result.invocationId ? `invocation ${result.invocationId} ` : ''}returned HTTP ${result.status}`);
|
|
988
|
+
return result.status >= 200 && result.status < 300 ? 0 : 1;
|
|
989
|
+
}
|
|
849
990
|
// ---------------------------------------------------------------------------
|
|
850
991
|
// logs
|
|
851
992
|
// ---------------------------------------------------------------------------
|
|
@@ -986,10 +1127,15 @@ export const FUNCTIONS_USAGE = `usage:
|
|
|
986
1127
|
seq-studio functions deploy -e <env> [-m msg] preview + confirm secrets + upload and deploy
|
|
987
1128
|
seq-studio functions list -e <env> [--match-local] functions visible on the environment
|
|
988
1129
|
seq-studio functions show -e <env> [--fn slug] detail for one function (versions, secrets)
|
|
989
|
-
seq-studio functions
|
|
1130
|
+
seq-studio functions limits [-e <env>] [--json] bundled defaults/caps, or deployed policy
|
|
1131
|
+
[--fn slug] also show effective runtime limits (requires -e)
|
|
1132
|
+
seq-studio functions dev [--dir path] [--port 8080] local HTTP server with cache context
|
|
1133
|
+
seq-studio functions invoke -e <env> [--data JSON | --data @file | --stdin]
|
|
1134
|
+
invoke a function and print its response
|
|
1135
|
+
seq-studio functions logs -e <env> [--limit N] [--since t] function logs (reader-gated)
|
|
990
1136
|
seq-studio functions promote <version> -e <env> make a version live
|
|
991
1137
|
seq-studio functions rollback [<version>] -e <env> redeploy a prior version
|
|
992
|
-
seq-studio functions delete -e <env> [--yes] archive function + tear down
|
|
1138
|
+
seq-studio functions delete -e <env> [--yes] archive function + tear down its runtime
|
|
993
1139
|
(version history is retained)
|
|
994
1140
|
|
|
995
1141
|
Flags: -e/--env <env|preview:<slug>> (required for network commands; see: seq-studio envs list) · --fn <slug> · --dir <path>
|
|
@@ -999,6 +1145,14 @@ export const FUNCTIONS_USAGE = `usage:
|
|
|
999
1145
|
--no-provision (deploy) update-only: error instead of registering a new
|
|
1000
1146
|
shell, writing secret values, or attaching secrets (CI sweep)
|
|
1001
1147
|
|
|
1148
|
+
Local Atlas builds and runs deployed functions on this computer, including teardown.
|
|
1149
|
+
"functions dev" runs a standalone handler without Atlas registration.
|
|
1150
|
+
|
|
1151
|
+
Configure per-function CPU and concurrency in managed-function.yml under limits.
|
|
1152
|
+
Run "functions limits" for valid settings; redeploy to apply manifest changes.
|
|
1153
|
+
Invocation rates are shared across Atlas replicas; 429 includes Retry-After.
|
|
1154
|
+
If the shared rate limiter is unavailable, invocation fails closed with 503.
|
|
1155
|
+
|
|
1002
1156
|
Source for build/deploy: a local --dir (default .), a platform git-service
|
|
1003
1157
|
repo (--repo <ns>/<name>), or a public HTTPS git URL (--git-url <url>). --path selects
|
|
1004
1158
|
a function directory within a remote repo; omit it for the existing root-manifest
|
|
@@ -1018,6 +1172,10 @@ export async function runFunctionsCommand(sub, args) {
|
|
|
1018
1172
|
switch (sub) {
|
|
1019
1173
|
case 'init':
|
|
1020
1174
|
return await functionsInitCommand(args);
|
|
1175
|
+
case 'dev': {
|
|
1176
|
+
const { functionsDevCommand } = await import('./dev.js');
|
|
1177
|
+
return await functionsDevCommand(args);
|
|
1178
|
+
}
|
|
1021
1179
|
case 'build':
|
|
1022
1180
|
return await functionsBuildCommand(args);
|
|
1023
1181
|
case 'deploy':
|
|
@@ -1026,6 +1184,10 @@ export async function runFunctionsCommand(sub, args) {
|
|
|
1026
1184
|
return await functionsListCommand(args);
|
|
1027
1185
|
case 'show':
|
|
1028
1186
|
return await functionsShowCommand(args);
|
|
1187
|
+
case 'limits':
|
|
1188
|
+
return await functionsLimitsCommand(args);
|
|
1189
|
+
case 'invoke':
|
|
1190
|
+
return await functionsInvokeCommand(args);
|
|
1029
1191
|
case 'logs':
|
|
1030
1192
|
return await functionsLogsCommand(args);
|
|
1031
1193
|
case 'promote':
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { copyFile, mkdtemp, readFile, rm, symlink, writeFile, } from 'node:fs/promises';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { readCacheConfiguration } from '@sequenceholdings/managed-functions/config';
|
|
8
|
+
import { readManifestOptional, workDir } from './commands.js';
|
|
9
|
+
/** Run the HTTP framework locally with the same third-argument cache context. */
|
|
10
|
+
export async function functionsDevCommand(args) {
|
|
11
|
+
if (process.env.K_SERVICE || process.env.FUNCTION_TARGET)
|
|
12
|
+
throw new Error('functions dev is local-development only');
|
|
13
|
+
const dir = workDir(args);
|
|
14
|
+
const manifest = await readManifestOptional(dir);
|
|
15
|
+
if (!manifest)
|
|
16
|
+
throw new Error('managed-function.yml is required');
|
|
17
|
+
const port = z.coerce
|
|
18
|
+
.number()
|
|
19
|
+
.int()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(65535)
|
|
22
|
+
.parse(args.flags.port ?? 8080);
|
|
23
|
+
const pkg = z
|
|
24
|
+
.object({ main: z.string().default('index.js') })
|
|
25
|
+
.parse(JSON.parse(await readFile(join(dir, 'package.json'), 'utf8')));
|
|
26
|
+
const resolveLocal = createRequire(join(dir, 'package.json'));
|
|
27
|
+
const frameworkDir = dirname(resolveLocal.resolve('@google-cloud/functions-framework'));
|
|
28
|
+
const temporary = await mkdtemp(join(tmpdir(), 'seq-function-dev-'));
|
|
29
|
+
try {
|
|
30
|
+
// The project owns compilation. This uses its installed compiler without downloading tools.
|
|
31
|
+
if (await readFile(join(dir, 'tsconfig.json'), 'utf8').then(() => true, () => false)) {
|
|
32
|
+
const code = await run(process.execPath, [resolveLocal.resolve('typescript/bin/tsc')], { cwd: dir });
|
|
33
|
+
if (code !== 0)
|
|
34
|
+
return code;
|
|
35
|
+
}
|
|
36
|
+
await symlink(join(dir, 'node_modules'), join(temporary, 'node_modules'), 'dir');
|
|
37
|
+
await copyFile(createRequire(import.meta.url).resolve('@sequenceholdings/managed-functions/runtime'), join(temporary, 'cache.cjs'));
|
|
38
|
+
await writeFile(join(temporary, 'package.json'), JSON.stringify({ main: 'entry.cjs' }));
|
|
39
|
+
await writeFile(join(temporary, 'entry.cjs'), `
|
|
40
|
+
const { pathToFileURL } = require('node:url')
|
|
41
|
+
const tracing = require('./cache.cjs')
|
|
42
|
+
tracing.installFunctionTracing()
|
|
43
|
+
const context = tracing.createManagedFunctionContext()
|
|
44
|
+
const getExport = (value, name) => name.split('.').reduce((v, k) => v?.[k], value)
|
|
45
|
+
const handler = import(pathToFileURL(${JSON.stringify(join(dir, pkg.main))}).href).then(loaded => {
|
|
46
|
+
const registered = require(${JSON.stringify(join(frameworkDir, 'function_registry.js'))}).getRegisteredFunction(${JSON.stringify(manifest.entrypoint)})?.userFunction
|
|
47
|
+
const fn = registered || getExport(loaded, ${JSON.stringify(manifest.entrypoint)}) || getExport(loaded.default, ${JSON.stringify(manifest.entrypoint)})
|
|
48
|
+
if (typeof fn !== 'function') throw new Error('Managed Function entrypoint is not registered or exported')
|
|
49
|
+
return fn
|
|
50
|
+
})
|
|
51
|
+
exports.sequenceLocal = async (req, res) => tracing.runWithFunctionTracing(req, async () => (await handler)(req, res, context))
|
|
52
|
+
`);
|
|
53
|
+
const runtimeConfig = process.env.SEQUENCE_FUNCTION_CACHE_CONFIG ??
|
|
54
|
+
JSON.stringify({ cache: readCacheConfiguration(manifest) });
|
|
55
|
+
console.log(`[seq-studio] Local function on port ${port}; cache is per-process memory unless an explicit private Valkey connection is configured.`);
|
|
56
|
+
return await run(process.execPath, [
|
|
57
|
+
join(frameworkDir, 'main.js'),
|
|
58
|
+
'--source',
|
|
59
|
+
temporary,
|
|
60
|
+
'--target',
|
|
61
|
+
'sequenceLocal',
|
|
62
|
+
'--port',
|
|
63
|
+
String(port),
|
|
64
|
+
], {
|
|
65
|
+
cwd: dir,
|
|
66
|
+
env: {
|
|
67
|
+
...process.env,
|
|
68
|
+
SEQUENCE_FUNCTION_LOCAL: '1',
|
|
69
|
+
SEQUENCE_FUNCTION_CACHE_CONFIG: runtimeConfig,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await rm(temporary, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function run(command, args, options) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const child = spawn(command, args, { ...options, stdio: 'inherit' });
|
|
80
|
+
const interrupt = () => child.kill('SIGINT');
|
|
81
|
+
const terminate = () => child.kill('SIGTERM');
|
|
82
|
+
process.on('SIGINT', interrupt);
|
|
83
|
+
process.on('SIGTERM', terminate);
|
|
84
|
+
const cleanup = () => {
|
|
85
|
+
process.off('SIGINT', interrupt);
|
|
86
|
+
process.off('SIGTERM', terminate);
|
|
87
|
+
};
|
|
88
|
+
child.once('error', (error) => {
|
|
89
|
+
cleanup();
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
child.once('exit', (code) => {
|
|
93
|
+
cleanup();
|
|
94
|
+
resolve(code ?? 1);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -24,9 +24,10 @@ export declare function buildEgressPreviewLines(log: string, entries: readonly s
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function egressPropagationNote(log: string): string;
|
|
26
26
|
/** `functions show` — active manifest egress allowlist from the API. */
|
|
27
|
-
export declare function printFunctionEgressHosts({ log, hosts, ipRanges, egressEnforced, }: {
|
|
27
|
+
export declare function printFunctionEgressHosts({ log, hosts, platformHosts, ipRanges, egressEnforced, }: {
|
|
28
28
|
log: string;
|
|
29
29
|
hosts: readonly string[];
|
|
30
|
+
platformHosts?: readonly string[];
|
|
30
31
|
ipRanges?: readonly string[];
|
|
31
32
|
egressEnforced: boolean;
|
|
32
33
|
}): void;
|
|
@@ -37,7 +37,7 @@ export function egressPropagationNote(log) {
|
|
|
37
37
|
return `${log} note: egress allowlist — new updates may take a few minutes to propagate`;
|
|
38
38
|
}
|
|
39
39
|
/** `functions show` — active manifest egress allowlist from the API. */
|
|
40
|
-
export function printFunctionEgressHosts({ log, hosts, ipRanges = [], egressEnforced, }) {
|
|
40
|
+
export function printFunctionEgressHosts({ log, hosts, platformHosts = [], ipRanges = [], egressEnforced, }) {
|
|
41
41
|
console.log(`${log} egress allowlist:`);
|
|
42
42
|
if (hosts.length === 0 && ipRanges.length === 0) {
|
|
43
43
|
console.log(egressEnforced
|
|
@@ -45,8 +45,9 @@ export function printFunctionEgressHosts({ log, hosts, ipRanges = [], egressEnfo
|
|
|
45
45
|
: ' (none declared)');
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
+
const platformHostSet = new Set(platformHosts);
|
|
48
49
|
for (const host of hosts) {
|
|
49
|
-
console.log(` ${host}`);
|
|
50
|
+
console.log(` ${host}${platformHostSet.has(host) ? ' (platform-managed ORM access)' : ''}`);
|
|
50
51
|
}
|
|
51
52
|
for (const cidr of ipRanges) {
|
|
52
53
|
console.log(` ${cidr} (direct IP)`);
|
|
@@ -67,6 +67,16 @@ export declare function manifestEgressIpRanges(entries: readonly string[]): stri
|
|
|
67
67
|
*/
|
|
68
68
|
export declare function egressBudgetError(entries: string[]): string | null;
|
|
69
69
|
export declare const managedFunctionManifestSchema: z.ZodObject<{
|
|
70
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
72
|
+
tier: z.ZodDefault<z.ZodEnum<{
|
|
73
|
+
"custom-pico": "custom-pico";
|
|
74
|
+
"custom-micro": "custom-micro";
|
|
75
|
+
"custom-mini": "custom-mini";
|
|
76
|
+
}>>;
|
|
77
|
+
replicas: z.ZodDefault<z.ZodNumber>;
|
|
78
|
+
default_ttl_seconds: z.ZodDefault<z.ZodNumber>;
|
|
79
|
+
}, z.core.$strict>>;
|
|
70
80
|
schema_version: z.ZodDefault<z.ZodLiteral<1>>;
|
|
71
81
|
function: z.ZodObject<{
|
|
72
82
|
id: z.ZodString;
|
|
@@ -75,8 +85,10 @@ export declare const managedFunctionManifestSchema: z.ZodObject<{
|
|
|
75
85
|
}, z.core.$strip>;
|
|
76
86
|
runtime: z.ZodDefault<z.ZodLiteral<"nodejs20">>;
|
|
77
87
|
entrypoint: z.ZodDefault<z.ZodString>;
|
|
78
|
-
limits: z.
|
|
88
|
+
limits: z.ZodPrefault<z.ZodObject<{
|
|
79
89
|
memory_mb: z.ZodDefault<z.ZodNumber>;
|
|
90
|
+
cpu: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodNumber]>>;
|
|
91
|
+
concurrency: z.ZodDefault<z.ZodNumber>;
|
|
80
92
|
timeout_seconds: z.ZodDefault<z.ZodNumber>;
|
|
81
93
|
min_instances: z.ZodDefault<z.ZodNumber>;
|
|
82
94
|
max_instances: z.ZodDefault<z.ZodNumber>;
|
|
@@ -105,6 +117,11 @@ export declare const managedFunctionManifestSchema: z.ZodObject<{
|
|
|
105
117
|
input_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
106
118
|
output_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
107
119
|
capabilities: z.ZodDefault<z.ZodObject<{
|
|
120
|
+
storage: z.ZodOptional<z.ZodRecord<z.ZodUUID, z.ZodEnum<{
|
|
121
|
+
viewer: "viewer";
|
|
122
|
+
editor: "editor";
|
|
123
|
+
admin: "admin";
|
|
124
|
+
}>>>;
|
|
108
125
|
roles: z.ZodOptional<z.ZodObject<{
|
|
109
126
|
definitions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
110
127
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { storageScopesSchema, readStorageScopes } from '@sequenceholdings/storage';
|
|
2
|
+
import { cacheManifestSchema, managedFunctionWorkloadLimitsSchema } from '@sequenceholdings/managed-functions/config';
|
|
1
3
|
import { isIP } from 'node:net';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
/**
|
|
@@ -580,6 +582,7 @@ const invocationIpRangeSchema = z
|
|
|
580
582
|
}
|
|
581
583
|
});
|
|
582
584
|
export const managedFunctionManifestSchema = z.object({
|
|
585
|
+
cache: cacheManifestSchema.optional(),
|
|
583
586
|
schema_version: z.literal(1).default(1),
|
|
584
587
|
function: z.object({
|
|
585
588
|
id: z
|
|
@@ -592,30 +595,7 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
592
595
|
}),
|
|
593
596
|
runtime: z.literal('nodejs20').default('nodejs20'),
|
|
594
597
|
entrypoint: z.string().min(1).max(255).default('handler'),
|
|
595
|
-
limits:
|
|
596
|
-
.object({
|
|
597
|
-
memory_mb: z.number().int().min(128).max(2048).default(256),
|
|
598
|
-
timeout_seconds: z.number().int().min(1).max(540).default(60),
|
|
599
|
-
min_instances: z.number().int().min(0).max(10).default(1),
|
|
600
|
-
max_instances: z.number().int().min(1).max(10).default(3),
|
|
601
|
-
invoke_rate_per_minute: z.number().int().min(1).max(600).default(60),
|
|
602
|
-
})
|
|
603
|
-
.superRefine((limits, ctx) => {
|
|
604
|
-
if (limits.min_instances > limits.max_instances) {
|
|
605
|
-
ctx.addIssue({
|
|
606
|
-
code: 'custom',
|
|
607
|
-
message: 'min_instances cannot exceed max_instances',
|
|
608
|
-
path: ['min_instances'],
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
})
|
|
612
|
-
.default({
|
|
613
|
-
memory_mb: 256,
|
|
614
|
-
timeout_seconds: 60,
|
|
615
|
-
min_instances: 1,
|
|
616
|
-
max_instances: 3,
|
|
617
|
-
invoke_rate_per_minute: 60,
|
|
618
|
-
}),
|
|
598
|
+
limits: managedFunctionWorkloadLimitsSchema,
|
|
619
599
|
/**
|
|
620
600
|
* Source-IP gate applied by the Atlas invocation gateway before FGA.
|
|
621
601
|
* Empty or omitted means unrestricted. The policy is versioned with the
|
|
@@ -651,8 +631,8 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
651
631
|
})
|
|
652
632
|
.default([]),
|
|
653
633
|
/**
|
|
654
|
-
* The platform service account
|
|
655
|
-
* (slug or id). Required whenever
|
|
634
|
+
* The platform service account available for explicit service-mode data or storage access
|
|
635
|
+
* (slug or id). Required whenever data or storage capabilities are declared,
|
|
656
636
|
* rejected otherwise. Resolved and authorized server-side at activation —
|
|
657
637
|
* the deploy actor must hold `actor` on the account when the attachment
|
|
658
638
|
* changes. Mirrors atlas/src/server/services/managed-functions/manifest.ts.
|
|
@@ -674,6 +654,7 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
674
654
|
* activation and invoke time; validated here so push fails fast.
|
|
675
655
|
*/
|
|
676
656
|
capabilities: z.object({
|
|
657
|
+
storage: storageScopesSchema.optional(),
|
|
677
658
|
roles: customRolesBlockSchema.optional(),
|
|
678
659
|
uses: capabilityPinsSchema,
|
|
679
660
|
gates: capabilityGatesSchema,
|
|
@@ -711,6 +692,15 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
711
692
|
.default({}),
|
|
712
693
|
}).default({ uses: [], gates: [], data: {} }),
|
|
713
694
|
}).superRefine((manifest, ctx) => {
|
|
695
|
+
if (manifest.cache?.enabled) {
|
|
696
|
+
manifest.secrets.forEach((name, index) => {
|
|
697
|
+
if (name.startsWith('SEQUENCE_FUNCTION_'))
|
|
698
|
+
ctx.addIssue({
|
|
699
|
+
code: 'custom', path: ['secrets', index],
|
|
700
|
+
message: 'SEQUENCE_FUNCTION_ is reserved when caching is enabled',
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
}
|
|
714
704
|
const expectedAdapter = AUTHORIZATION_ADAPTER_BY_FUNCTION_ID[manifest.function.id];
|
|
715
705
|
if (expectedAdapter !== undefined && manifest.authorization === undefined) {
|
|
716
706
|
ctx.addIssue({
|
|
@@ -751,11 +741,11 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
751
741
|
// A namespace is "reached" when its block declares at least one table,
|
|
752
742
|
// action, operation, or raw query — the same rule the server's floor
|
|
753
743
|
// reconciliation uses (readManifestDataNamespaces).
|
|
754
|
-
const reachesData = Object.values(manifest.capabilities.data).some((block) => block.tables.length > 0 || block.actions.length > 0 || block.operations.length > 0 || block.query);
|
|
744
|
+
const reachesData = Object.keys(readStorageScopes(manifest)).length > 0 || Object.values(manifest.capabilities.data).some((block) => block.tables.length > 0 || block.actions.length > 0 || block.operations.length > 0 || block.query);
|
|
755
745
|
if (reachesData && manifest.service_account === undefined) {
|
|
756
746
|
ctx.addIssue({
|
|
757
747
|
code: 'custom',
|
|
758
|
-
message: 'capabilities
|
|
748
|
+
message: 'Data or storage capabilities require a top-level service_account — the platform service ' +
|
|
759
749
|
'account this function acts as for ORM data access (the deployer needs the actor role on it)',
|
|
760
750
|
path: ['service_account'],
|
|
761
751
|
});
|
|
@@ -763,7 +753,7 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
763
753
|
if (!reachesData && manifest.service_account !== undefined) {
|
|
764
754
|
ctx.addIssue({
|
|
765
755
|
code: 'custom',
|
|
766
|
-
message: 'service_account
|
|
756
|
+
message: 'service_account requires capabilities.data or capabilities.storage',
|
|
767
757
|
path: ['service_account'],
|
|
768
758
|
});
|
|
769
759
|
}
|
package/dist/main.js
CHANGED
|
@@ -29,7 +29,8 @@ const TOP_LEVEL_USAGE = `usage:
|
|
|
29
29
|
seq-studio deploy -e <env> deploy primitives from sequence.app.yml
|
|
30
30
|
seq-studio process <sub> [args] lint | plan | apply | test | simulate | bundle | init
|
|
31
31
|
seq-studio artifact <sub> [args] init | build | plan | deploy | dev | list | show | pull | promote | rollback
|
|
32
|
-
seq-studio functions <sub> [args] init | build | deploy | list | show | logs | promote | rollback | delete
|
|
32
|
+
seq-studio functions <sub> [args] init | build | deploy | list | show | limits | invoke | logs | promote | rollback | delete
|
|
33
|
+
seq-studio storage <sub> [args] init | validate | apply | list | show | mkdir | upload | download | access | trash | restore | purge | operations | abort | delete
|
|
33
34
|
seq-studio agents <sub> [args] init | validate | plan | apply | list | show
|
|
34
35
|
seq-studio secrets <sub> [args] create | set | list | attach | detach | apply
|
|
35
36
|
seq-studio repos <sub> [args] list | namespaces | show | create | clone | pull | delete
|
|
@@ -97,6 +98,10 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
97
98
|
const { runFunctionsCommand } = await import('./functions/commands.js');
|
|
98
99
|
return runFunctionsCommand(sub, parseArgs(rest));
|
|
99
100
|
}
|
|
101
|
+
case 'storage': {
|
|
102
|
+
const { runStorageCommand } = await import('./storage/commands.js');
|
|
103
|
+
return runStorageCommand(sub, parseArgs(rest));
|
|
104
|
+
}
|
|
100
105
|
case 'agents': {
|
|
101
106
|
const { runAgentsCommand } = await import('./agents/commands.js');
|
|
102
107
|
return runAgentsCommand(sub, parseArgs(rest));
|