poetry-agent 0.0.2
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/app/javascript/poetry/agent/a2ui_surface_controller.js +141 -0
- data/app/javascript/poetry/agent/adapter.js +77 -0
- data/app/javascript/poetry/agent/agui_client_tool_controller.js +53 -0
- data/app/javascript/poetry/agent/index.js +41 -0
- data/app/javascript/poetry/agent/stream_actions.js +65 -0
- data/app/javascript/poetry/agent/webmcp_controller.js +248 -0
- data/app/javascript/poetry/agent/webmcp_form_controller.js +109 -0
- data/config/controllers_manifest.json +82 -0
- data/config/importmap.rb +10 -0
- data/exe/poetry-agent +28 -0
- data/lib/poetry/agent/a2ui/catalog.rb +289 -0
- data/lib/poetry/agent/a2ui/catalogs/basic.rb +460 -0
- data/lib/poetry/agent/a2ui/catalogs/native.rb +176 -0
- data/lib/poetry/agent/a2ui/checks.rb +45 -0
- data/lib/poetry/agent/a2ui/evaluator.rb +139 -0
- data/lib/poetry/agent/a2ui/expression.rb +175 -0
- data/lib/poetry/agent/a2ui/functions.rb +417 -0
- data/lib/poetry/agent/a2ui/markdown.rb +63 -0
- data/lib/poetry/agent/a2ui/pointer.rb +113 -0
- data/lib/poetry/agent/a2ui/protocol.rb +12 -0
- data/lib/poetry/agent/a2ui/renderer.rb +242 -0
- data/lib/poetry/agent/a2ui/session.rb +302 -0
- data/lib/poetry/agent/a2ui/streams.rb +82 -0
- data/lib/poetry/agent/a2ui/surface.rb +352 -0
- data/lib/poetry/agent/a2ui.rb +48 -0
- data/lib/poetry/agent/agui/client.rb +69 -0
- data/lib/poetry/agent/agui/json_patch.rb +137 -0
- data/lib/poetry/agent/agui/relay.rb +105 -0
- data/lib/poetry/agent/agui/run_input.rb +83 -0
- data/lib/poetry/agent/agui/sse.rb +97 -0
- data/lib/poetry/agent/agui/transcript.rb +540 -0
- data/lib/poetry/agent/agui/turbo_stream.rb +68 -0
- data/lib/poetry/agent/agui.rb +87 -0
- data/lib/poetry/agent/config.rb +49 -0
- data/lib/poetry/agent/engine.rb +37 -0
- data/lib/poetry/agent/mcp/bundled.rb +54 -0
- data/lib/poetry/agent/mcp/http.rb +89 -0
- data/lib/poetry/agent/mcp/server.rb +962 -0
- data/lib/poetry/agent/version.rb +8 -0
- data/lib/poetry/agent/webmcp/origin_trial.rb +49 -0
- data/lib/poetry/agent/webmcp.rb +37 -0
- data/lib/poetry/agent.rb +66 -0
- data/lib/poetry-agent.rb +4 -0
- metadata +117 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Poetry
|
|
4
|
+
module Agent
|
|
5
|
+
module WebMCP
|
|
6
|
+
# Rack middleware serving the `Origin-Trial` response header on HTML
|
|
7
|
+
# responses, one token per browser trial (Chrome and Edge run
|
|
8
|
+
# separate trials and issue separate tokens). Tokens come from
|
|
9
|
+
# {Poetry::Agent::Config#origin_trial_tokens}; with none configured
|
|
10
|
+
# the middleware is a pass-through, so it is always safe to mount.
|
|
11
|
+
#
|
|
12
|
+
# Local development needs no token: enable the API through the
|
|
13
|
+
# browser flag instead.
|
|
14
|
+
#
|
|
15
|
+
# @example config/application.rb
|
|
16
|
+
# config.middleware.use Poetry::Agent::WebMCP::OriginTrial
|
|
17
|
+
class OriginTrial
|
|
18
|
+
# The response header the browsers read (Rack 3 lowercases names).
|
|
19
|
+
HEADER = "origin-trial"
|
|
20
|
+
|
|
21
|
+
def initialize(app, tokens: nil)
|
|
22
|
+
@app = app
|
|
23
|
+
@tokens = tokens
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The Rack entry point: appends the tokens to HTML responses.
|
|
27
|
+
#
|
|
28
|
+
# @param env [Hash] the Rack environment
|
|
29
|
+
# @return [Array(Integer, Hash, Object)] the downstream response
|
|
30
|
+
def call(env)
|
|
31
|
+
status, headers, body = @app.call(env)
|
|
32
|
+
tokens = (@tokens || Poetry::Agent.config.origin_trial_tokens).compact.reject(&:empty?)
|
|
33
|
+
if tokens.any? && html?(headers)
|
|
34
|
+
existing = headers[HEADER] || headers["Origin-Trial"]
|
|
35
|
+
headers[HEADER] = [existing, *tokens].compact.join(", ")
|
|
36
|
+
end
|
|
37
|
+
[status, headers, body]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def html?(headers)
|
|
43
|
+
type = headers["content-type"] || headers["Content-Type"]
|
|
44
|
+
type.to_s.include?("text/html")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "webmcp/origin_trial"
|
|
4
|
+
|
|
5
|
+
module Poetry
|
|
6
|
+
module Agent
|
|
7
|
+
# The WebMCP runtime's Ruby side. The contract itself lives in
|
|
8
|
+
# poetry-core (the `tool` declarations, their registry projection, and
|
|
9
|
+
# the per-instance `webmcp:` payload a component root carries); this
|
|
10
|
+
# module owns what only the runtime gem knows: the Stimulus controller
|
|
11
|
+
# identifiers the JS registers, the controllers manifest that lets
|
|
12
|
+
# core's attribute builder validate them, and origin-trial delivery.
|
|
13
|
+
#
|
|
14
|
+
# Nothing here exposes a tool by itself - a rendered instance opts in
|
|
15
|
+
# (`webmcp: "country"` on the helper call), and the registrar
|
|
16
|
+
# controller registers that instance's declared tools with
|
|
17
|
+
# `document.modelContext` on connect, aborting them on disconnect.
|
|
18
|
+
module WebMCP
|
|
19
|
+
# The registrar controller: reads a root's payload and registers
|
|
20
|
+
# its tools, dispatching each to the component's own controller.
|
|
21
|
+
CONTROLLER = "poetry--agent--webmcp"
|
|
22
|
+
# The declarative-form controller: answers an agent-invoked submit
|
|
23
|
+
# with the form's outcome through `SubmitEvent.respondWith`.
|
|
24
|
+
FORM_CONTROLLER = "poetry--agent--webmcp-form"
|
|
25
|
+
|
|
26
|
+
# The committed controllers manifest (the JS surface of the two
|
|
27
|
+
# controllers), merged into poetry-core's catalog by the engine so
|
|
28
|
+
# use_stimulus / the Builder validate poetry--agent--* names exactly
|
|
29
|
+
# like core's own.
|
|
30
|
+
#
|
|
31
|
+
# @return [Pathname]
|
|
32
|
+
def self.manifest_path
|
|
33
|
+
Poetry::Agent.root.join("config/controllers_manifest.json")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/poetry/agent.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pathname"
|
|
4
|
+
require "poetry/core"
|
|
5
|
+
require_relative "agent/version"
|
|
6
|
+
require_relative "agent/config"
|
|
7
|
+
require_relative "agent/mcp/server"
|
|
8
|
+
require_relative "agent/mcp/bundled"
|
|
9
|
+
require_relative "agent/mcp/http"
|
|
10
|
+
require_relative "agent/webmcp"
|
|
11
|
+
require_relative "agent/agui"
|
|
12
|
+
require_relative "agent/a2ui"
|
|
13
|
+
require_relative "agent/engine" if defined?(Rails::Engine)
|
|
14
|
+
|
|
15
|
+
# The poetry namespace.
|
|
16
|
+
module Poetry
|
|
17
|
+
# poetry-agent: the agent-interop gem of the poetry family - the
|
|
18
|
+
# surfaces through which agents reach the component contract, built
|
|
19
|
+
# once (the registry) and projected many ways:
|
|
20
|
+
#
|
|
21
|
+
# - {MCP::Server} - the boot-free `poetry-agent` MCP server (discover:
|
|
22
|
+
# list_components / describe_component / check / compose / build_page
|
|
23
|
+
# / get_skill) for coding agents in editors.
|
|
24
|
+
# - {WebMCP} - the in-page runtime: rendered components' declared tools
|
|
25
|
+
# (`tool` declarations in poetry-core) registered with the browser's
|
|
26
|
+
# `document.modelContext` for the user's own agent (operate), plus the
|
|
27
|
+
# declarative-form path and the origin-trial delivery.
|
|
28
|
+
# - {A2UI} - the registry projected as an A2UI catalog (the vocabulary
|
|
29
|
+
# an agent generates declarative UI against).
|
|
30
|
+
# - {AGUI} - the Rails-side AG-UI client: an agent backend's event stream
|
|
31
|
+
# folded into chat frames and relayed as versioned Turbo Streams,
|
|
32
|
+
# with the component tools the browser executes advertised as the
|
|
33
|
+
# agent's frontend tools.
|
|
34
|
+
#
|
|
35
|
+
# Both read the same committed registries; neither is a second source.
|
|
36
|
+
module Agent
|
|
37
|
+
class << self
|
|
38
|
+
# Gem root (the directory containing lib/, exe/, app/).
|
|
39
|
+
#
|
|
40
|
+
# @return [Pathname]
|
|
41
|
+
def root
|
|
42
|
+
@root ||= Pathname.new(File.expand_path("../..", __dir__))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The gem's configuration (origin-trial tokens, registration budget).
|
|
46
|
+
#
|
|
47
|
+
# @return [Poetry::Agent::Config]
|
|
48
|
+
def config
|
|
49
|
+
Config.current
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Yields the configuration for block-style setup.
|
|
53
|
+
#
|
|
54
|
+
# @yieldparam config [Poetry::Agent::Config]
|
|
55
|
+
# @return [Poetry::Agent::Config]
|
|
56
|
+
# @example config/initializers/poetry_agent.rb
|
|
57
|
+
# Poetry::Agent.configure do |config|
|
|
58
|
+
# config.origin_trial_tokens = [ENV["WEBMCP_ORIGIN_TRIAL_TOKEN"]].compact
|
|
59
|
+
# end
|
|
60
|
+
def configure
|
|
61
|
+
yield config
|
|
62
|
+
config
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/poetry-agent.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: poetry-agent
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Matt Solt
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: poetry-core
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - '='
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.0.2
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - '='
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.0.2
|
|
26
|
+
description: 'The agent-interop gem of Poetry, the AI-native UI component library.
|
|
27
|
+
Five surfaces: the boot-free poetry-agent MCP server (the component contract over
|
|
28
|
+
Model Context Protocol, with runtime skill delivery); the WebMCP runtime that registers
|
|
29
|
+
rendered components'' declared tools with in-browser agents (document.modelContext)
|
|
30
|
+
behind safe-by-default, opt-in registration, declarative forms, and an origin-trial
|
|
31
|
+
middleware; the AG-UI relay, a Rails client of the Agent-User Interaction protocol
|
|
32
|
+
that runs an agent and relays its events as Turbo Streams, with frontend tools and
|
|
33
|
+
interrupts; the A2UI catalog projected from the component registry; and the A2UI
|
|
34
|
+
renderer that folds the envelope into server-rendered surfaces with forms, checks,
|
|
35
|
+
functions, and morphing updates.'
|
|
36
|
+
email:
|
|
37
|
+
- mattsolt@gmail.com
|
|
38
|
+
executables:
|
|
39
|
+
- poetry-agent
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- CHANGELOG.md
|
|
44
|
+
- LICENSE.txt
|
|
45
|
+
- README.md
|
|
46
|
+
- app/javascript/poetry/agent/a2ui_surface_controller.js
|
|
47
|
+
- app/javascript/poetry/agent/adapter.js
|
|
48
|
+
- app/javascript/poetry/agent/agui_client_tool_controller.js
|
|
49
|
+
- app/javascript/poetry/agent/index.js
|
|
50
|
+
- app/javascript/poetry/agent/stream_actions.js
|
|
51
|
+
- app/javascript/poetry/agent/webmcp_controller.js
|
|
52
|
+
- app/javascript/poetry/agent/webmcp_form_controller.js
|
|
53
|
+
- config/controllers_manifest.json
|
|
54
|
+
- config/importmap.rb
|
|
55
|
+
- exe/poetry-agent
|
|
56
|
+
- lib/poetry-agent.rb
|
|
57
|
+
- lib/poetry/agent.rb
|
|
58
|
+
- lib/poetry/agent/a2ui.rb
|
|
59
|
+
- lib/poetry/agent/a2ui/catalog.rb
|
|
60
|
+
- lib/poetry/agent/a2ui/catalogs/basic.rb
|
|
61
|
+
- lib/poetry/agent/a2ui/catalogs/native.rb
|
|
62
|
+
- lib/poetry/agent/a2ui/checks.rb
|
|
63
|
+
- lib/poetry/agent/a2ui/evaluator.rb
|
|
64
|
+
- lib/poetry/agent/a2ui/expression.rb
|
|
65
|
+
- lib/poetry/agent/a2ui/functions.rb
|
|
66
|
+
- lib/poetry/agent/a2ui/markdown.rb
|
|
67
|
+
- lib/poetry/agent/a2ui/pointer.rb
|
|
68
|
+
- lib/poetry/agent/a2ui/protocol.rb
|
|
69
|
+
- lib/poetry/agent/a2ui/renderer.rb
|
|
70
|
+
- lib/poetry/agent/a2ui/session.rb
|
|
71
|
+
- lib/poetry/agent/a2ui/streams.rb
|
|
72
|
+
- lib/poetry/agent/a2ui/surface.rb
|
|
73
|
+
- lib/poetry/agent/agui.rb
|
|
74
|
+
- lib/poetry/agent/agui/client.rb
|
|
75
|
+
- lib/poetry/agent/agui/json_patch.rb
|
|
76
|
+
- lib/poetry/agent/agui/relay.rb
|
|
77
|
+
- lib/poetry/agent/agui/run_input.rb
|
|
78
|
+
- lib/poetry/agent/agui/sse.rb
|
|
79
|
+
- lib/poetry/agent/agui/transcript.rb
|
|
80
|
+
- lib/poetry/agent/agui/turbo_stream.rb
|
|
81
|
+
- lib/poetry/agent/config.rb
|
|
82
|
+
- lib/poetry/agent/engine.rb
|
|
83
|
+
- lib/poetry/agent/mcp/bundled.rb
|
|
84
|
+
- lib/poetry/agent/mcp/http.rb
|
|
85
|
+
- lib/poetry/agent/mcp/server.rb
|
|
86
|
+
- lib/poetry/agent/version.rb
|
|
87
|
+
- lib/poetry/agent/webmcp.rb
|
|
88
|
+
- lib/poetry/agent/webmcp/origin_trial.rb
|
|
89
|
+
homepage: https://poetryui.com
|
|
90
|
+
licenses:
|
|
91
|
+
- MIT
|
|
92
|
+
metadata:
|
|
93
|
+
homepage_uri: https://poetryui.com
|
|
94
|
+
documentation_uri: https://poetryui.com/docs
|
|
95
|
+
source_code_uri: https://github.com/roboruby/poetry-agent
|
|
96
|
+
changelog_uri: https://github.com/roboruby/poetry-agent/blob/main/CHANGELOG.md
|
|
97
|
+
bug_tracker_uri: https://github.com/roboruby/poetry-agent/issues
|
|
98
|
+
rubygems_mfa_required: 'true'
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: 3.4.0
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubygems_version: 4.0.16
|
|
114
|
+
specification_version: 4
|
|
115
|
+
summary: 'Poetry''s agent surfaces: MCP server, WebMCP runtime, AG-UI relay, and A2UI
|
|
116
|
+
catalog and renderer.'
|
|
117
|
+
test_files: []
|