Repository navigation
feat(v3): T-Substrate-AnthropicMessagesCallable — fn anthropic_messages declaration #1266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
9b5d1e6
WIP: sharp-raven-604
briansrls e2f29e6
WIP: sharp-raven-604
briansrls 06c1b5d
WIP: sharp-raven-604
briansrls 589dc18
WIP: sharp-raven-604
briansrls 0d927a1
merge main into session/sharp-raven-604
briansrls 05d0de4
WIP: sharp-raven-604
briansrls 2093dbb
WIP: sharp-raven-604
briansrls e459b85
regen bootstrap after std.effects import path fix
briansrls 3df10af
merge main
briansrls 3d994a8
WIP: sharp-raven-604
briansrls 4a94f8d
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 5910cab
chore: apply cargo fmt
briansrls 3893e36
merge main; resolve manifest conflict (keep services row)
briansrls b3e513c
WIP: sharp-raven-604
briansrls b0d1ffb
regen bootstrap + refresh parse manifest after merge
briansrls c1f8ffa
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 27287a4
WIP: sharp-raven-604
briansrls 271f5c3
merge main; resolve bootstrap+manifest conflicts
briansrls ac85e45
WIP: sharp-raven-604
briansrls d39c9d4
WIP: sharp-raven-604
briansrls 33fb48e
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 9169155
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 090b8b6
PR-α: wrap Operation.callable in CallableRef (typed wrapper, mirrors …
briansrls b4ba9f9
chore: apply cargo fmt
briansrls 66c6b1c
doc: align test comments with CallableRef wrapper (cosmetic)
briansrls 921d05a
merge main; take theirs on bootstrap (re-regen follows)
briansrls 7cac46e
regen bootstrap after merge main
briansrls 5516db5
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls a5003a6
T-Substrate-AnthropicSchemaMirror: v3 typed mirror for Anthropic Mess…
briansrls 053679e
WIP: sharp-raven-604
briansrls 7519fa2
chore: apply cargo fmt
briansrls bc7bc2e
anthropic_schema lockstep: couple expected labels to v2 source + opti…
briansrls 63e845a
anthropic_schema lockstep: bidirectional set equality + structural op…
briansrls 3c8b660
chore: apply cargo fmt
briansrls faac2b6
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 1468cba
fix clippy: use char array in split (manual char comparison lint)
briansrls 92e1965
WIP: sharp-raven-604
briansrls 2eaa1b1
anthropic_schema lockstep: per-variant payload field+optionality cove…
briansrls 1e08a24
chore: apply cargo fmt
briansrls 3c6c0e7
WIP: sharp-raven-604
briansrls c47cede
chore: apply cargo fmt
briansrls ee78939
WIP: sharp-raven-604
briansrls b41143f
anthropic_schema lockstep: type-expression equality (records + varian…
briansrls 365e57f
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls dff070b
anthropic_schema lockstep: also reject Arrow declarations (fn leak gu…
briansrls 6613e08
chore: apply cargo fmt
briansrls c22c800
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls 1219c5d
T-Substrate-AnthropicMessagesCallable: fn anthropic_messages declaration
briansrls bc1b027
chore: apply cargo fmt
briansrls 88feef8
chore: restore comment/test adjacency in SG-0 census (cosmetic)
briansrls c74a9de
anthropic_messages: pin Unparsed body + correct file header prose
briansrls 00387e4
regen bootstrap: re-sync byte spans after anthropic_messages.dag head…
briansrls a69ed2d
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2,832 changes: 1,418 additions & 1,414 deletions
2,832
src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
src/v3/compiler/tests/integration/anthropic_messages_callable_test.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| //! **Layer:** integration | ||
| //! | ||
| //! T-Substrate-AnthropicMessagesCallable shape ratchet. | ||
| //! | ||
| //! Pins the `fn anthropic_messages` declaration in | ||
| //! `src/v3/std/anthropic_messages.dag` so PR-β can rebase against a | ||
| //! stable callable target via `CallableRef.decl`. Asserts: | ||
| //! | ||
| //! - The declaration resolves in the full bootstrap and is `Arrow`-shaped. | ||
| //! - Parameter labels and types match the v3 mirror in | ||
| //! `v3.std.anthropic_schema` plus kernel `Secret` / `String` / `Int` / | ||
| //! `Float?` / `String?` for the primitives the v2 source carries. | ||
| //! - Output type is `AnthropicMessages200Body` (the 200 response slot, | ||
| //! per the v2 `response { 200 => … }` row). | ||
| //! - The declaration is acceptable as a `CallableRef` target, i.e. | ||
| //! `Operation.callable: CallableRef` with `decl` set to | ||
| //! `anthropic_messages`'s id resolves structurally (the field type | ||
| //! reach matches the substrate-level `DeclarationRef` admits-anything | ||
| //! policy that PR-β fixture load fail-closes against). | ||
| //! - No `Operation` / `data anthropic_operations` row leaks here; that | ||
| //! stays Grounding-owned in PR-β. | ||
|
|
||
| use v3_compiler::dag::{Dag, DeclarationId, TypeConnective}; | ||
| use v3_compiler::generated_full_bootstrap_dag; | ||
|
|
||
| fn arrow_inputs_output(dag: &Dag, name: &str) -> (Vec<DeclarationId>, DeclarationId) { | ||
| let decl = dag | ||
| .declaration_by_name(name) | ||
| .unwrap_or_else(|| panic!("`{name}` missing from full bootstrap")); | ||
| match &decl.connective { | ||
| TypeConnective::Arrow { inputs, output, .. } => (inputs.clone(), *output), | ||
| other => panic!("`{name}` is not an Arrow: {other:?}"), | ||
| } | ||
| } | ||
|
|
||
| /// Reuse the same canonicalization rule as the schema-mirror lockstep: | ||
| /// named declarations canonicalize as their surface name; anonymous | ||
| /// `Cardinality(AtMostOne, T)` and `Instantiation { template, args }` | ||
| /// unfold. | ||
| fn canonical_ty(dag: &Dag, ty: DeclarationId) -> String { | ||
| let decl = dag.declaration(ty); | ||
| if let Some(name) = decl.name.as_deref() { | ||
| return name.to_string(); | ||
| } | ||
| match &decl.connective { | ||
| TypeConnective::Cardinality(p) => format!("{}?", canonical_ty(dag, p.element())), | ||
| TypeConnective::Instantiation { | ||
| template, | ||
| arguments, | ||
| } => { | ||
| let template_name = dag | ||
| .declaration(*template) | ||
| .name | ||
| .clone() | ||
| .unwrap_or_else(|| canonical_ty(dag, *template)); | ||
| if arguments.is_empty() { | ||
| template_name | ||
| } else { | ||
| let args: Vec<String> = arguments | ||
| .iter() | ||
| .map(|a| canonical_ty(dag, a.value)) | ||
| .collect(); | ||
| format!("{}<{}>", template_name, args.join(", ")) | ||
| } | ||
| } | ||
| _ => "<anon>".to_string(), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn anthropic_messages_is_arrow_shaped() { | ||
| let dag = generated_full_bootstrap_dag(); | ||
| let decl = dag | ||
| .declaration_by_name("anthropic_messages") | ||
| .expect("`anthropic_messages` missing from full bootstrap"); | ||
| assert!( | ||
| matches!(decl.connective, TypeConnective::Arrow { .. }), | ||
| "`anthropic_messages` must be `Arrow`-shaped so `CallableRef.decl` \ | ||
| can target an actual callable signature, not a `data` row or a \ | ||
| type alias. Got: {:?}", | ||
| decl.connective | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn anthropic_messages_parameter_types_match_v2_source_via_v3_mirror() { | ||
| // Expected canonical parameter types in declaration order. These | ||
| // mirror `dsl/extdeps/llm/anthropic.dag:182-187` modulo the two | ||
| // documented honesty-preserving simplifications: | ||
| // - `max_tokens: Int` (v2 `Int = 4096`; v3 has no parameter | ||
| // defaults — the default is a caller-side fold, not a v3 | ||
| // callable contract change). | ||
| // - return is the 200 body only (`AnthropicMessages200Body`); | ||
| // error responses are PR-β's response/wire lockstep concern. | ||
| let dag = generated_full_bootstrap_dag(); | ||
| let (inputs, _output) = arrow_inputs_output(&dag, "anthropic_messages"); | ||
| let actual: Vec<String> = inputs.iter().map(|id| canonical_ty(&dag, *id)).collect(); | ||
| let expected: Vec<&str> = vec![ | ||
| "Secret", | ||
| "String", | ||
| "List<AnthropicChatMessage>", | ||
| "Int", | ||
| "Float?", | ||
| "String?", | ||
| ]; | ||
| assert_eq!( | ||
| actual, | ||
| expected.iter().map(|s| s.to_string()).collect::<Vec<_>>(), | ||
| "anthropic_messages parameter types diverged from the v2 \ | ||
| operation Messages signature." | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn anthropic_messages_returns_anthropic_messages_200_body() { | ||
| let dag = generated_full_bootstrap_dag(); | ||
| let (_inputs, output) = arrow_inputs_output(&dag, "anthropic_messages"); | ||
| let output_canonical = canonical_ty(&dag, output); | ||
| assert_eq!( | ||
| output_canonical, "AnthropicMessages200Body", | ||
| "anthropic_messages must return `AnthropicMessages200Body` \ | ||
| (the v2 `response 200 =>` slot from \ | ||
| `dsl/extdeps/llm/anthropic.dag`). Error-response carriers are \ | ||
| deferred to PR-β's response/wire lockstep lane." | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn anthropic_messages_is_acceptable_callable_ref_target() { | ||
| // `CallableRef { decl: DeclarationRef }` — `DeclarationRef` admits | ||
| // any declaration at the substrate level (the same #1175 residual | ||
| // `MethodRef` carries). The PR-β fixture-load boundary check that | ||
| // every `Operation.callable.decl` resolves to an `Arrow`-shaped | ||
| // declaration (the actual callable contract) is what this test | ||
| // pre-validates: `anthropic_messages` IS an Arrow with a non-empty | ||
| // input list and a typed output, which is the property PR-β's | ||
| // fail-closed boundary will verify. | ||
| let dag = generated_full_bootstrap_dag(); | ||
| let decl = dag | ||
| .declaration_by_name("anthropic_messages") | ||
| .expect("`anthropic_messages` missing from full bootstrap"); | ||
| let (inputs, output) = match &decl.connective { | ||
| TypeConnective::Arrow { inputs, output, .. } => (inputs, *output), | ||
| other => panic!("`anthropic_messages` is not an Arrow: {other:?}"), | ||
| }; | ||
| assert!( | ||
| !inputs.is_empty(), | ||
| "callable target for `Operation.callable.decl` must carry the \ | ||
| operation's input list — anthropic_messages with empty inputs \ | ||
| is structurally unfit." | ||
| ); | ||
| let output_decl = dag.declaration(output); | ||
| assert!( | ||
| output_decl.name.is_some(), | ||
| "callable output should resolve to a named declaration, so PR-β \ | ||
| lockstep against the response/wire lane has a real type to \ | ||
| project. Got anonymous output: {:?}", | ||
| output_decl.connective | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn anthropic_messages_dag_authors_no_operation_rows() { | ||
| // The `Operation` row that closes the callable-to-source-identity | ||
| // edge (`callable: { decl: anthropic_messages }, inputs: …, | ||
| // endpoint: { method: POST, path: parse_path_template("/v1/messages"), … }`) | ||
| // is Grounding-owned PR-β work in a sibling | ||
| // `src/v3/std/anthropic_operations.dag`. Reject any `data` row | ||
| // landing in `anthropic_messages.dag` (which would mean a | ||
| // producerless `Operation` row or other parallel-surface scaffold | ||
| // leaked here). | ||
| let dag = generated_full_bootstrap_dag(); | ||
| let leaks: Vec<String> = dag | ||
| .declarations() | ||
| .iter() | ||
| .filter(|d| d.span.file == "src/v3/std/anthropic_messages.dag") | ||
| .filter(|d| d.value_body.is_some()) | ||
| .map(|d| { | ||
| d.name | ||
| .clone() | ||
| .unwrap_or_else(|| format!("DeclarationId({:?})", d.id)) | ||
| }) | ||
| .collect(); | ||
| assert!( | ||
| leaks.is_empty(), | ||
| "anthropic_messages.dag is callable-decl authority only; no \ | ||
| `data` rows allowed. PR-β authors operation rows in a sibling \ | ||
| file. Found: {leaks:?}." | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| module v3.std.anthropic_messages | ||
|
|
||
| import std.types { Secret } | ||
| import std.list { List } | ||
| import v3.std.anthropic_schema { | ||
| AnthropicChatMessage, | ||
| AnthropicMessages200Body | ||
| } | ||
|
|
||
| // T-Substrate-AnthropicMessagesCallable — service-operation callable | ||
| // declaration precursor for the Anthropic Messages REST operation. The | ||
| // real top-level callable that PR-β's `anthropic_operations: List<Operation>` | ||
| // row will reference via `Operation.callable.decl`, satisfying the | ||
| // `CallableRef` typed-edge requirement (#1246, #1261). | ||
| // | ||
| // Authority source for the signature is `dsl/extdeps/llm/anthropic.dag`'s | ||
| // `service llm.Anthropic { operation Messages { … } }` block at lines | ||
| // 180-203. The v3 mirror types in `v3.std.anthropic_schema` (#1261) carry | ||
| // the input/output structural fidelity that lets this callable land | ||
| // honestly — without the schema mirror, the only options were primitive- | ||
| // only signatures (forbidden as fake-by-omission) or wholesale v2 service | ||
| // parser ingestion (forbidden as out-of-scope). Both stops are documented | ||
| // in #1130's STOP+PING chain that produced #1261. | ||
| // | ||
| // **Signature shape vs. v2 source.** Two intentional simplifications | ||
| // preserve honesty at the v3 layer rather than introducing fake structure: | ||
| // | ||
| // 1. `max_tokens: Int` here vs `max_tokens: Int = 4096` in v2. | ||
| // v3's function-decl surface does not carry parameter defaults; the | ||
| // v2 default is a caller-side convenience that PR-β fixture rows | ||
| // surface (or that downstream consumers fold in). The v3 callable | ||
| // requires `max_tokens` explicitly, which is structurally stricter | ||
| // than the v2 default but does not invent a fake type — `Int` is | ||
| // the right type, only the optionality story differs. | ||
| // 2. The 4xx/5xx response carriers (`AnthropicErrorShape`) are not on | ||
| // the typed return; the callable returns the 200 body | ||
| // (`AnthropicMessages200Body`) per v2's `response { 200 => … }` | ||
| // slot. Error-response handling lives with the operation-row | ||
| // response/wire lockstep lane (PR-β scope, sibling to the row authoring | ||
| // Grounding owns). | ||
| // | ||
| // **Body.** `host anthropic_messages` lowers to | ||
| // `ArrowBody::ExternalRealization`, exactly the shape `pipeline.dag`'s | ||
| // `host parse` / `host lower` / etc. use. The realization is external | ||
| // to v3 — for service operations, the runtime dispatcher consumes the | ||
| // REST endpoint binding from the `Operation` row PR-β authors. v3 | ||
| // substrate does not need a `CompilerHostRealization`-style data row | ||
| // here because the realization is identified by the callable's | ||
| // `Operation.endpoint` REST shape, not by a Rust symbol; minting a | ||
| // data row whose only job is to satisfy a binding-carrier slot would | ||
| // be the producerless parallel surface the dispatch explicitly rejects. | ||
| // | ||
| // **Out of scope.** The `Operation` row that closes the | ||
| // callable-to-source-identity edge (`callable: { decl: anthropic_messages }, | ||
| // inputs: …, endpoint: { method: POST, path: parse_path_template("/v1/messages"), | ||
| // … }`) is Grounding-owned PR-β work in a sibling | ||
| // `src/v3/std/anthropic_operations.dag` file. Grounding can rebase | ||
| // #1252 against this PR's `anthropic_messages` decl id directly via | ||
| // `CallableRef.decl`. | ||
| // | ||
| // **Dissolution.** Same trigger as `anthropic_schema.dag`: when v3 | ||
| // grows a service-DSL parse/load surface that ingests | ||
| // `dsl/extdeps/llm/*.dag` with full structural fidelity, the v2 | ||
| // source becomes the only authority and this callable | ||
| // declaration retires alongside the schema mirror it references. | ||
| fn anthropic_messages( | ||
| api_key: Secret, | ||
| model: String, | ||
| messages: List<AnthropicChatMessage>, | ||
| max_tokens: Int, | ||
| temperature: Float?, | ||
| system: String? | ||
| ) -> AnthropicMessages200Body { | ||
| host anthropic_messages | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BLOCKING: This claims
host anthropic_messageslowers toArrowBody::ExternalRealization, but the generated bootstrap in this diff stores the callable withArrowBody::Unparsed, so the service-operation body fact does not flow forward as modeled (facts-flow-forward/modeling faithfulness).