mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 19:17:38 +00:00
* feat(agent): type-safe CREATION_CONTEXT metadata on create_file/create_version
Build the create_file and create_version tool metadata parameter from the
project's CREATION_CONTEXT fields at harness creation time, instead of the
schemaless key-value map that required the agent to call list_autofill_fields
first.
- Thread projectId from the chat workflow into createAgentSession and build
a strict, all-required (nullable) metadata schema via fieldsToTypeBoxSchema
(additionalProperties: false, option IDs enforced via enum).
- Remove the list_autofill_fields tool and its activity case.
- Reject metadata keys that are not CREATION_CONTEXT fields of the target
project with a clear non-retryable error telling the agent to omit metadata.
- Skip null metadata values when persisting (create_file/create_version and
the autofill workflow).
- Switch the touched schemas from @sinclair/typebox 0.34 to typebox v1 to
match the harness validator.
* refactor(agent): migrate remaining tools from @sinclair/typebox 0.34 to typebox v1
All agent tool schemas now use the same typebox v1 package as the harness
validator; drop the @sinclair/typebox 0.34 dependency from @shumai/agent.
* test(agent): reproduce null coercion in harness tool validation
The pi-ai harness (<=0.82.1) coerces null values in [string, null] unions to
'' during tool argument validation for typebox v1 schemas. A valid create_file
call with path: null + data: {...} therefore arrives at execute with path: ''
and fails with 'Provide exactly one of path or data'. Null metadata values
(the 'unknown' sentinel) are likewise turned into ''.
This test reproduces both failures. It is expected to fail until
@earendil-works/pi-ai is upgraded to >=0.84.0 (#7328), which preserves values
that already match a union arm.
* fix(agent): patch pi-ai 0.82.1 to preserve null in nullable union tool args
Apply the upstream fix for earendil-works/pi#7328 (PR #7373) via a bun
patch instead of upgrading pi-ai. coerceWithUnionSchema now returns the
original value when it already validates against any union member,
instead of coercing null in [string, null] unions into "".
Fixes the create_file false "Provide exactly one of path or data" error
when the model passes path: null with data. Reproduced by
packages/agent/src/reproduce-tool-null-coercion.test.ts, which now passes.
* fix(docker): copy bun patch dir before frozen-lockfile install
The pi-ai patchedDependencies entry makes bun install --frozen-lockfile
fail in the builder stage because patches/ was not present in the image
yet. Copy it alongside package.json/bun.lock so the patch applies.
* refactor(agent): simplify metadata guidance in system prompt and error message
Shorten the create_file/create_version metadata instructions in the system
prompt and reword the invalid-metadata-key error to not reference
CREATION_CONTEXT internals. Update the matching test assertion.
18 lines
689 B
Diff
18 lines
689 B
Diff
diff --git a/dist/utils/validation.js b/dist/utils/validation.js
|
|
index 6cffb0855554b0f53d9ca76eba3bd1641dcc19ef..bcd7991bb59163e6f2f2819827790227f8b69e8c 100644
|
|
--- a/dist/utils/validation.js
|
|
+++ b/dist/utils/validation.js
|
|
@@ -150,6 +150,12 @@ function applySchemaArrayCoercion(value, schema) {
|
|
}
|
|
}
|
|
function coerceWithUnionSchema(value, schemas) {
|
|
+ for (const schema of schemas) {
|
|
+ const validator = getSubSchemaValidator(schema);
|
|
+ if (validator?.Check(value)) {
|
|
+ return value;
|
|
+ }
|
|
+ }
|
|
for (const schema of schemas) {
|
|
const candidate = structuredClone(value);
|
|
const coerced = coerceWithJsonSchema(candidate, schema);
|