Skip to content

Commit 9ea05de

Browse files
committed
Merge commit '8e963675aaa67ba2462d3a7ed8865ad2a583e9bd' into fix/bb-file-bucket-mock-phantom-versions
2 parents 66e5dbd + 8e96367 commit 9ea05de

197 files changed

Lines changed: 8425 additions & 672 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/agent-canary-e2e.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@aws-blocks/create-blocks-app": patch
3+
---
4+
5+
feat: add an `agent` template with a deterministic e2e test
6+
7+
`npx @aws-blocks/create-blocks-app my-app --template agent` scaffolds an AI Agent
8+
with a tool and `AuthBasic`-gated chat. Locally it runs on the built-in
9+
`canned` provider, a deterministic fake model that needs no AWS account and no
10+
LLM, so the shipped e2e test drives a plain-text turn and a tool-calling turn
11+
over the real RPC boundary and checks the tool's side effect landed.

‎.changeset/blocks-migrate.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
"@aws-blocks/blocks": minor
3+
"@aws-blocks/create-blocks-app": patch
4+
---
5+
6+
feat(blocks): add `cdk-blocks migrate`
7+
8+
`npx --no -- cdk-blocks migrate` moves an app that create-blocks-app scaffolded with `aws-blocks/scripts/*.ts` wrappers to the `cdk-blocks` CLI. It rewrites each `package.json` script whose value is exactly a generated command (for example `"deploy": "tsx aws-blocks/scripts/deploy.ts"` becomes `"deploy": "cdk-blocks deploy"`), moves the port and frontend settings of a generated `server.ts` to `package.json#blocks.dev` (`"frontend": false` for a backend-only one), and deletes the generated wrappers that nothing uses any more. A wrapper that a script or any app file other than Markdown docs still uses is kept: it reads TypeScript and JavaScript sources (including nested and parent-relative imports such as `import '../server.js'`), shell scripts, Dockerfiles, and dot directories such as `.github` and `.vscode`. In a git repository the app files are the tracked files and the untracked files that are not gitignored, in any directory, so gitignored build output and logs do not count, plus the files of a submodule or an untracked git repository inside the app; outside git, or where git does not track the app (a parent repository ignores its directory), they are the files under the app directory other than `node_modules`, `.git`, build output (`build-temp` included) and tool caches. Markdown docs and editor rules (`*.md`, `*.mdx`, `*.mdc`), binary files, files over 1 MiB and symbolic links never count. It does not read outside the app directory, so check the scripts of a parent workspace yourself. It recognises every wrapper version that create-blocks-app has shipped, ignoring whitespace. A wrapper you changed is never deleted, only reported. If you changed `server.ts`, the `sandbox` scripts are kept too, because `sandbox.ts` starts that server, and a `sandbox.ts` that stays keeps its `server.ts`; in the Amplify overlay, `blocks:stop` and `stop.ts` are kept as well, because that `stop.ts` stops the server's own port. If `.blocks/config.json` is missing or has no `stackId`, as in apps scaffolded before create-blocks-app wrote it, the `deploy` and `destroy` scripts and wrappers are kept, because `cdk-blocks deploy` and `cdk-blocks destroy` need it; the report says how to add it. Every other script is left alone.
9+
10+
Run `npx --no -- cdk-blocks migrate --dry-run` first to see the plan. Unless you pass `--force`, it refuses an app outside git (or where git is not installed), a git working tree with uncommitted changes, an app that git does not track (so git could not undo the changes), and a repository that git fails to read, such as one with "dubious ownership", quoting git's error. `--output json` prints `{changed, removed, kept, scriptsRewritten, devConfig}`, where `devConfig` is the `blocks.dev` config that migrate adds to `package.json` (or, with `--dry-run`, would add), or `null`. It exits 0 when the app is fully migrated and 1 when kept items remain for you to finish by hand; exit 1 is a report, not a crash, and running it again is safe.
11+
12+
It recognises the wrappers of every public create-blocks-app release up to 0.4.0, including the `sandbox.ts` that runs `npm run sandbox:preview`, whose `"sandbox:preview": "tsx aws-blocks/scripts/sandbox.ts --preview"` becomes `"sandbox:preview": "cdk-blocks sandbox preview"`.
13+
14+
Fixes from CLI testing:
15+
16+
- Two `cdk-blocks migrate` runs at the same time no longer crash with `ENOENT` when one deletes a wrapper that the other is reading or planned to delete.
17+
- `cdk-blocks migrate --dry-run` no longer says "everything else was migrated" above the items it would keep.
18+
- The hint for an app without `stackId` now says that `<stackId>-prod` must equal the production stack name in `aws-blocks/index.cdk.ts`: an app that hard-codes `my-blocks-stack-prod` uses `{"stackId": "my-blocks-stack"}`.
19+
- A wrapper that matches no known version is reported as an "unrecognised version (only public create-blocks-app releases are recognised)", not as "customized": it may be an unmodified file from a release that migrate does not know. The README and `cdk-blocks migrate -h` say that only the public releases are recognised.
20+
- A generated script that still runs a kept, unrecognised wrapper (for example `dev` and `dev:server` with a changed `server.ts`) is now listed in `kept` with the reason, so `--output json` names every script that still uses `aws-blocks/scripts`.
21+
- `cdk-blocks migrate` writes `blocks.dev.frontendCommand` only when it differs from the command `cdk-blocks dev` detects from the `vite` or `next` dependency; the ports still move. A migrated default app gets `{"frontendPort": 3100}`, as new apps do, so `cdk-blocks dev --frontend-port` keeps working.
22+
- With `--output json`, a refusal (uncommitted changes, an app git does not track, a git failure) prints `{"error": {"message", "hint"}}` on stdout, so a script can tell it from kept items, which also exit 1. `cdk-blocks migrate -h` and the README list the exit codes: 0 fully migrated, 1 kept items remain or refused, 2 usage error.
23+
- `cdk-blocks migrate` keeps a wrapper that a CI workflow, shell script, Dockerfile or script runs from another working directory: a bare `scripts/deploy.ts` or `deploy.ts` there now counts as a use (`working-directory: aws-blocks` with `npx tsx scripts/deploy.ts`, `cd aws-blocks/scripts && npx tsx typegen.ts`). In a monorepo it also reads every `package.json` and every CI, shell, Make and Docker file that git tracks outside the app, at any depth (`.github/workflows/*`, `scripts/deploy-web.sh`, `ci/Makefile`, `tools/release/package.json`; not under `node_modules`, nor over 1 MiB), and, when the app is in a git submodule, those files of the superproject, so it no longer deletes a wrapper that a root workflow, a monorepo script or a sibling workspace still runs.
24+
- `cdk-blocks migrate --query <path>` checks the path against the result before anything runs, as the other commands do: `kept.0.reason`, `scriptsRewritten.<script>.to` and `devConfig.frontendPort` are accepted, and a typo exits 2 with the fields it could be.
25+
- `cdk-blocks migrate --query <path>` prints a refusal only as the error on stderr, with nothing on stdout, also under `--output json`: `--query` prints one field of the result, and a refusal has no result. The `{"error"}` document is for `--output json` without `--query`.
26+
- An app `package.json` that is not valid JSON stops `cdk-blocks migrate` with `cannot read <app>/package.json: <the parse error>`, as the other commands say, instead of only `Unexpected end of JSON input`.
27+
- In a monorepo, a file above the app counts as a use of a wrapper only when it names this app: `apps/web/aws-blocks/scripts/deploy.ts` (relative to the repository top or to the file), or a bare `aws-blocks/scripts/deploy.ts`, `scripts/deploy.ts` or `deploy.ts` in a file that changes into the app (`working-directory: apps/web`, `cd apps/web`). Before, `apps/api`'s workflow, with `working-directory: apps/api` or `apps/api/aws-blocks/scripts/typegen.ts`, kept `apps/web`'s wrappers and made its migration exit 1.
28+
- An app `package.json` that is valid JSON but not an object (`null`, an array, a string) stops `cdk-blocks migrate` with `<app>/package.json must be a JSON object, not null.` and changes nothing, instead of `Cannot read properties of null (reading 'scripts')`, or `Nothing to migrate` for an array or a string.
29+
- A path written with backslashes counts as a use of a wrapper: `npx tsx aws-blocks\scripts\deploy.ts` in a `.cmd`, `.bat` or `.ps1` file (or a `package.json` script) keeps `deploy.ts`, which `cdk-blocks migrate` deleted before.
30+
- On Windows, two `cdk-blocks migrate` runs at the same time no longer crash with `EPERM: operation not permitted, rmdir '…\aws-blocks\scripts'`: a directory that the other run holds or is deleting is tried again, then left to it.
31+
- Outside git, or where git is not installed, `cdk-blocks migrate` now refuses unless you pass `--force`, as it does for an app that git does not track: git could not undo the rewritten scripts or the deleted wrappers. The hint points to `--dry-run` first, and `--output json` prints the `{"error"}` document.
32+
- In a monorepo, a quoted `cd` or `working-directory` into the app now counts when it holds an escaped quote (`cd "apps/we\"b"`) or a command substitution: `cd "$(git rev-parse --show-toplevel)/apps/web" && npx tsx aws-blocks/scripts/deploy.ts`, or `cd "$(dirname "$0")/../apps/web"` from the script's own directory. Before, `cdk-blocks migrate` deleted `deploy.ts` there and exited 0 while the root script still ran it.
33+
- A `.blocks/config.json` that is not valid JSON is no longer reported as missing: the kept `deploy` and `destroy` items say `.blocks/config.json is not valid JSON (<the parse error>): fix <path>, then run cdk-blocks migrate again`, as core's deploy and `cdk-blocks whoami` do, instead of telling you to create the file.
34+
- A `package.json` edit made while `cdk-blocks migrate` scanned the app is no longer overwritten: migrate now stops with `package.json changed while cdk-blocks migrate ran; nothing was written.` before it writes or deletes anything, also with `--force`, and `--output json` prints the `{"error"}` document. Before, it wrote the scripts it had planned over the edit, and could delete a wrapper that a newly added script ran.
35+
- A wrapper that a field of the app's `package.json` other than `scripts` runs is no longer deleted: a `lint-staged`, `simple-git-hooks` or `nodemonConfig` block with `tsx aws-blocks/scripts/typegen.ts` (or a bare `scripts/deploy.ts` after `cd aws-blocks`) keeps that wrapper, reported as `generated, but still used by package.json#lint-staged`. Before, `cdk-blocks migrate` read only the `scripts` of the app's own `package.json`, deleted the wrapper and exited 0.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
"@aws-blocks/create-blocks-app": patch
3+
---
4+
5+
fix(create-blocks-app): gate the remaining public template methods and git-ignore secrets when adding Blocks to an existing project
6+
7+
- The `api-only` template's `createUploadUrl` / `createDownloadUrl` now call
8+
`auth.requireAuth(context)` and scope the path to the caller, so a signed-out
9+
caller can no longer mint presigned URLs to read or write any file in the
10+
bucket.
11+
- The `demo` template's SQL ledger methods (`openAccount`, `balanceOf`,
12+
`transfer`) now call `auth.requireAuth(context)`, and accounts belong to the
13+
signed-in user (a new `owner` column in `accounts`), so a caller can only
14+
read and move money between their own accounts. `transfer` declines a
15+
non-positive amount, which previously slipped past the overdraft guard, and
16+
an amount that is not a finite number (a numeric string passed `> 0`).
17+
- The `demo` template's `searchDocs` now calls `auth.requireAuth(context)`: on
18+
deploy each query is a billed Bedrock retrieval.
19+
- The `demo` and `auth-cognito` templates' `updateTodo` copies only `completed`,
20+
`priority` and `title` from `updates`. It spread the whole argument, so a
21+
caller could set the owner key and write a todo into another user's list.
22+
- Adding Blocks to an existing project (or an Amplify Gen 2 app) now appends
23+
`.env`, `.env.*` (except `.env.example`), `*.pem`, `*.key`, `*.p12`,
24+
`credentials` files (not `credentials/` directories), and `.aws/` to its
25+
`.gitignore`, the same patterns the templates ship. Entries are compared as
26+
whole lines, so an existing `.env.local` no longer stops `.env` being added.
27+
The `.env.example` / `credentials/` exceptions are left out when the project's
28+
own `.gitignore` could already ignore those names, so they never un-ignore them.
29+
A project that un-ignores `.env` (`!.env`) gets `.env` ignored again, and
30+
`.env.*` also ignores new `.env.development` / `.env.production` files (files
31+
git already tracks stay tracked). The plan and the `Modified .gitignore` line
32+
now list the entries added, and a CRLF `.gitignore` keeps CRLF line endings.
33+
- The `api-only` and `demo` templates keep FileBucket versioning on (the
34+
default), so an overwritten or deleted file can be restored, and the
35+
`api-only` template's `createUploadUrl` and the `demo` template's
36+
`getUploadSlot` sign only an explicit list of content types
37+
(`ALLOWED_UPLOAD_TYPES`).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-blocks/bb-container-compute": patch
3+
---
4+
5+
Harden the `ecs-tasks.amazonaws.com` trust that a container compute adds to the shared execution role: it is now scoped with `aws:SourceAccount` and `aws:SourceArn` (`arn:<partition>:ecs:<region>:<account>:*`), so only ECS tasks in the stack's own account and region can assume the role. The role's Lambda trust is unchanged.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aws-blocks/core': patch
3+
'@aws-blocks/blocks': patch
4+
---
5+
6+
`blocks-telemetry --disable` and `--enable` (without `--global`) now write `.blocks/config.json` at the project root, the nearest directory above the working directory that holds a `package.json` and an `aws-blocks/` directory, falling back to the working directory when there is none. Run from a subdirectory of an app, `--disable` previously wrote the opt-out into that subdirectory, where the telemetry check never read it, so telemetry kept sending while the command reported success. `--status` reads the same project root, and `--disable` now also reads the status back and prints a warning and exits non-zero if telemetry is still enabled. `--global` is unchanged.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@aws-blocks/hosting": patch
3+
"@aws-blocks/blocks": patch
4+
---
5+
6+
docs(hosting): explain what a plain-HTTP front door does to session cookies
7+
8+
The README's front-door section now says that behind a standalone ALB door with no certificate, `AuthBasic` omits `Secure` from its same-origin session cookie (a browser discards a `Secure` cookie from a plain-HTTP origin), so the cookie and the session travel in clear text, while `AuthCognito` and `AuthOIDC` keep `Secure` and their sign-in doesn't persist. It recommends a certificate (an HTTPS listener) for anything beyond testing, and points at the separate `StackedRouterPlainHttp` warning for the stacked door's edge → router hop.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@aws-blocks/bb-knowledge-base": patch
3+
"@aws-blocks/blocks": patch
4+
---
5+
6+
fix(bb-knowledge-base): keep raw ingestion failure text out of client errors
7+
8+
When the latest ingestion job had failed, `isSynced()` and `waitUntilSynced()` threw `IngestionFailedException` with Bedrock's `failureReasons` in the message. That message is returned to RPC callers, and the reasons are raw service text that can name buckets, object keys or ARNs. The error now has a fixed message. When Bedrock reports reasons, they are written to the server log and kept on the error's non-enumerable `cause`, so `JSON.stringify(err)` and the RPC response leave them out. The new exported type `IngestionFailureCause` describes that `cause`. The error name, `KnowledgeBaseErrors.IngestionFailed` and the method signatures are unchanged. If your server code read the reasons from `err.message`, read `failureReasons` from `err.cause` instead, treating it as optional: `cause` is absent when the job reported no reasons or the lookup failed.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@aws-blocks/core": minor
3+
"@aws-blocks/blocks": minor
4+
"@aws-blocks/bb-auth-oidc": patch
5+
"@aws-blocks/bb-container-compute": patch
6+
---
7+
8+
fix(core): `ctx.request.url.pathname` no longer includes the API Gateway stage when deployed
9+
10+
On AWS, a `RawRoute` handler's `ctx.request.url` had the API Gateway stage in front of the path (`/prod/bench/me`), while `npm run dev` gave the route path (`/bench/me`). A handler that sub-routed on `url.pathname` passed every local test and returned its own 404 for every request after deploy. Behind `Hosting`, the stage wasn't part of the browser's URL either.
11+
12+
`ctx.request.url.pathname` is now the route path in every environment, on Lambda and on a container compute, which took the stage from the front door's `x-blocks-forwarded-stage` header. The origin is unchanged: on AWS it is still the host the backend received, which behind a front door is the API Gateway host. An HTTP API `$default` stage is no longer prepended either, and a request path starting with `//` no longer changes the URL's host.
13+
14+
This is a `minor` bump because it changes an existing value. If you build an absolute link from `ctx.request.url.pathname` or `href` while clients call the API Gateway URL directly, add the stage yourself, or build the link from your app's configured origin. The likeliest such code resolves a relative path against the request URL: `new URL('next', ctx.request.url)` used to give `/prod/…/next` and now gives `/…/next`. Building Block authors who need the externally reachable base, stage included, can use the new `getRequestBaseUrl(ctx)` from `@aws-blocks/core/bb-utils`; every transport sets it for every request it dispatches.
15+
16+
`@aws-blocks/bb-auth-oidc` now takes the stage for its fallback callback URL and its stub IdP issuer from `getRequestBaseUrl()`, so those URLs are unchanged.
17+
18+
The `@aws-blocks/bb-container-compute` design notes now say that the stamped stage goes to `getRequestBaseUrl()`, not to the request path.

0 commit comments

Comments
 (0)