pwn 0.5.802 → 0.5.803
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 +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/lib/pwn/ai/open_web_ui.rb +33 -0
- data/lib/pwn/plugins/repl/ai_console.rb +22 -4
- data/lib/pwn/version.rb +1 -1
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +35 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +48 -0
- data/third_party/pwn_rdoc.jsonl +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 084348206227df7ff3160a96ab3a4dffbd7cfb9a5ffb2b7cd11d61ecd3b8222e
|
|
4
|
+
data.tar.gz: 226f2583c220b01014152a1eb8fb57d6379470f00bd30267957b654643ea7e5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 552132ef9ae49b21ae58e3021c44e64c21e5f4dc2a844be9d8b82d4b6ca9bd9d4d4e585d1bd6fe52d22abe2ec1105c552077dfd75521459602f2d285aa509381
|
|
7
|
+
data.tar.gz: 85ff41569586d1a5b4e024784a73c27d54da09c01ece7196981c4f81829f26ffba6aad01bb889b17495cbda80cd82fee826a2b2cf73513dd5bc735b9091c5bec
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.10
|
data/Gemfile
CHANGED
data/lib/pwn/ai/open_web_ui.rb
CHANGED
|
@@ -285,6 +285,13 @@ module PWN
|
|
|
285
285
|
body = opts[:body].to_s
|
|
286
286
|
rest_call = opts[:rest_call].to_s
|
|
287
287
|
|
|
288
|
+
# Net::HTTP can deliver valid UTF-8 tagged as binary, even across character boundaries.
|
|
289
|
+
# Decode the complete buffer for a display-only preview, never for action assembly.
|
|
290
|
+
preview = body.encoding == Encoding::BINARY && !body.ascii_only?
|
|
291
|
+
if preview
|
|
292
|
+
body = body.dup.force_encoding(Encoding::UTF_8)
|
|
293
|
+
raise 'ERROR: Open WebUI response contains invalid UTF-8' unless body.valid_encoding?
|
|
294
|
+
end
|
|
288
295
|
records = stream_records(body: body, rest_call: rest_call)
|
|
289
296
|
done = false
|
|
290
297
|
payloads = records.filter_map do |record|
|
|
@@ -300,6 +307,8 @@ module PWN
|
|
|
300
307
|
payload = parse_stream_payload(data: data, rest_call: rest_call)
|
|
301
308
|
error = payload[:error] || (payload if record[:event] == 'error')
|
|
302
309
|
if error
|
|
310
|
+
raise "ERROR: Open WebUI stream error for #{rest_call}" if preview
|
|
311
|
+
|
|
303
312
|
detail = error.is_a?(Hash) ? (error[:message] || error) : error
|
|
304
313
|
raise "ERROR: Open WebUI stream error for #{rest_call}: #{detail}"
|
|
305
314
|
end
|
|
@@ -312,15 +321,39 @@ module PWN
|
|
|
312
321
|
finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
|
|
313
322
|
raise "ERROR: Open WebUI incomplete stream for #{rest_call}: missing terminal event" unless done || finished
|
|
314
323
|
|
|
324
|
+
return preview_stream!(payloads: payloads, sse: true) if preview
|
|
325
|
+
|
|
315
326
|
assemble_openai_compat_stream(payloads: payloads)
|
|
316
327
|
else
|
|
317
328
|
raise "ERROR: Open WebUI malformed native stream for #{rest_call}: expected message object" unless payloads.any? { |p| p[:message].is_a?(Hash) } && payloads.all? { |p| !p.key?(:message) || p[:message].is_a?(Hash) }
|
|
318
329
|
raise "ERROR: Open WebUI incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
|
|
319
330
|
|
|
331
|
+
return preview_stream!(payloads: payloads, sse: false) if preview
|
|
332
|
+
|
|
320
333
|
assemble_native_chat_stream(payloads: payloads)
|
|
321
334
|
end
|
|
322
335
|
end
|
|
323
336
|
|
|
337
|
+
# Never return a recovered record to the caller. Do not collect arguments or thinking.
|
|
338
|
+
private_class_method def self.preview_stream!(opts = {})
|
|
339
|
+
text = +''
|
|
340
|
+
role = 'assistant'
|
|
341
|
+
pending = false
|
|
342
|
+
opts[:payloads].each do |payload|
|
|
343
|
+
choices = opts[:sse] ? Array(payload[:choices]) : [{ message: payload[:message], finish_reason: payload[:done_reason] }]
|
|
344
|
+
choices.each_with_index do |choice, index|
|
|
345
|
+
msg = choice[:delta] || choice[:message] || {}
|
|
346
|
+
pending ||= %w[tool_calls function_call].include?(choice[:finish_reason]) || !Array(msg[:tool_calls]).empty? || !msg[:function_call].nil?
|
|
347
|
+
next unless 0.eql?(choice.fetch(:index, index))
|
|
348
|
+
|
|
349
|
+
role = msg[:role] || role
|
|
350
|
+
text << msg[:content] if role == 'assistant' && msg[:content].is_a?(String)
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
Thread.current[:pwn_openwebui_preview]&.call(text, pending)
|
|
354
|
+
raise 'Open WebUI reply is display-only; no actions from this reply were submitted.'
|
|
355
|
+
end
|
|
356
|
+
|
|
324
357
|
# SSE dispatches at blank lines, joining every data field with a newline.
|
|
325
358
|
# Native NDJSON accepts a complete last record without a trailing newline.
|
|
326
359
|
private_class_method def self.stream_records(opts = {})
|
|
@@ -273,6 +273,7 @@ module PWN
|
|
|
273
273
|
# Cancellation never raises asynchronously into a tool.
|
|
274
274
|
class Control < PWN::AI::Agent::Loop::Steering
|
|
275
275
|
class Stopped < Exception; end # rubocop:disable Lint/InheritException
|
|
276
|
+
class PreviewShown < Stopped; end
|
|
276
277
|
|
|
277
278
|
def stopping?
|
|
278
279
|
@stopping == true
|
|
@@ -769,6 +770,19 @@ module PWN
|
|
|
769
770
|
%i[pwn_ai_session_id pwn_ai_debug pwn_ai_trace pwn_ai_speak pwn_ai_agent].to_h { |key| [key, @pry.config.public_send(key)] }
|
|
770
771
|
end
|
|
771
772
|
|
|
773
|
+
def with_stream_preview(events)
|
|
774
|
+
previous = Thread.current[:pwn_openwebui_preview]
|
|
775
|
+
Thread.current[:pwn_openwebui_preview] = lambda do |text, pending|
|
|
776
|
+
visible = text.gsub(/[\x00-\x08\x0B-\x1F\x7F-\u009F]/, '')
|
|
777
|
+
events << [:assistant, visible] unless visible.empty?
|
|
778
|
+
status = pending ? 'A requested action was not processed.' : 'No actions from this reply were processed.'
|
|
779
|
+
raise Control::PreviewShown, "Open WebUI reply recovered for display only. #{status} This turn has ended."
|
|
780
|
+
end
|
|
781
|
+
yield
|
|
782
|
+
ensure
|
|
783
|
+
Thread.current[:pwn_openwebui_preview] = previous
|
|
784
|
+
end
|
|
785
|
+
|
|
772
786
|
def mission_request_child(data, writer, commands)
|
|
773
787
|
request, generation, session_id, title_config = data.values_at(:request, :generation, :session_id, :title_config)
|
|
774
788
|
events = MissionEvents.new(writer, generation)
|
|
@@ -797,14 +811,18 @@ module PWN
|
|
|
797
811
|
events << [:result, result.to_s]
|
|
798
812
|
end
|
|
799
813
|
end
|
|
800
|
-
final =
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
814
|
+
final = with_stream_preview(events) do
|
|
815
|
+
PWN::AI::Agent::Loop.run(request: request, session_id: session_id,
|
|
816
|
+
enabled_toolsets: PWN::Env.dig(:ai, :agent, :toolsets),
|
|
817
|
+
on_tool: on_tool, steering: control, debug: @pry.config.pwn_ai_debug,
|
|
818
|
+
trace: @pry.config.pwn_ai_trace, debug_tee: output)
|
|
819
|
+
end
|
|
804
820
|
promoted = Thread.current[:pwn_thinking_promoted] && final.to_s.strip == Thread.current[:pwn_last_thinking].to_s.strip
|
|
805
821
|
events << [:assistant, final.to_s] unless promoted
|
|
806
822
|
events << [:session_title, PWN::Sessions.refresh_title(session_id: session_id, ai_config: title_config, on_error: ->(kind) { events << [:warning, "Session title refresh unavailable (#{kind}); previous title retained."] })]
|
|
807
823
|
end
|
|
824
|
+
rescue Control::PreviewShown => e
|
|
825
|
+
events << [:warning, e.message]
|
|
808
826
|
rescue StandardError, Interrupt, Control::Stopped => e
|
|
809
827
|
warning = if e.respond_to?(:http_code) && e.http_code == 403
|
|
810
828
|
'Access denied (HTTP 403). Check that your account can use the selected model and endpoint.'
|
data/lib/pwn/version.rb
CHANGED
|
@@ -344,3 +344,38 @@ describe PWN::AI::OpenWebUI do
|
|
|
344
344
|
expect(described_class).not_to respond_to(:get_plan_usage)
|
|
345
345
|
end
|
|
346
346
|
end
|
|
347
|
+
|
|
348
|
+
describe PWN::AI::OpenWebUI, 'binary stream display recovery' do
|
|
349
|
+
let(:previews) { [] }
|
|
350
|
+
|
|
351
|
+
around do |example|
|
|
352
|
+
previous = Thread.current[:pwn_openwebui_preview]
|
|
353
|
+
Thread.current[:pwn_openwebui_preview] = ->(text, pending) { previews << [text, pending] }
|
|
354
|
+
example.run
|
|
355
|
+
ensure
|
|
356
|
+
Thread.current[:pwn_openwebui_preview] = previous
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
it 'recovers only visible assistant text, without returning a provider response' do
|
|
360
|
+
event = JSON.generate(message: { role: 'assistant', thinking: 'private', content: 'Café' }, done: true)
|
|
361
|
+
wire = "\uFEFF#{event}".b.freeze
|
|
362
|
+
expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /display.only/i)
|
|
363
|
+
expect(previews).to eq([['Café', false]])
|
|
364
|
+
expect(wire.encoding).to eq(Encoding::BINARY)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
it 'reports an SSE action without displaying its arguments or returning it to the caller' do
|
|
368
|
+
delta = { role: 'assistant', content: 'Résumé', function_call: { name: 'fixture', arguments: 'private' } }
|
|
369
|
+
event = JSON.generate(choices: [{ delta: delta, finish_reason: 'function_call' }])
|
|
370
|
+
wire = "data: #{event}\r\n\r\ndata: [DONE]\r\n\r\n".b
|
|
371
|
+
expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'api/v1/chat/completions') }.to raise_error(RuntimeError, /display.only/i)
|
|
372
|
+
expect(previews).to eq([['Résumé', true]])
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
it 'does not preview invalid bytes or an incomplete reply' do
|
|
376
|
+
wire = JSON.generate(message: { content: 'Café' }, done: false).b
|
|
377
|
+
expect { described_class.send(:assemble_openwebui_stream, body: wire + "\xFF".b, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /invalid UTF-8/)
|
|
378
|
+
expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /incomplete/)
|
|
379
|
+
expect(previews).to be_empty
|
|
380
|
+
end
|
|
381
|
+
end
|
|
@@ -2812,6 +2812,54 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
2812
2812
|
expect(events.none? { |type, *| type == :assistant }).to be(true)
|
|
2813
2813
|
end
|
|
2814
2814
|
|
|
2815
|
+
it 'shows a split UTF-8 Open WebUI preview once without returning actions to the worker' do
|
|
2816
|
+
require 'rest-client'
|
|
2817
|
+
PWN::Env[:ai] = { active: :openwebui, openwebui: { model: 'fixture', base_uri: 'https://example.invalid', key: 'fixture-key' }, agent: { toolsets: [], plan_first: false } }
|
|
2818
|
+
calls = File.join(@tmp, 'preview-calls')
|
|
2819
|
+
answer = 'Café — ready.'
|
|
2820
|
+
msg = { role: 'assistant', content: answer, tool_calls: [{ function: { name: 'fixture', arguments: { value: 'private-fixture' } } }] }
|
|
2821
|
+
wire = JSON.generate(message: msg, done: true).b
|
|
2822
|
+
cut = wire.index('é'.b) + 1
|
|
2823
|
+
allow(PWN::AI::Router).to receive(:summarize).and_return('{"title":"Preview","summary":"A text preview."}')
|
|
2824
|
+
allow(PWN::AI::OpenWebUI).to receive(:chat_with_tools).and_wrap_original do |chat, opts|
|
|
2825
|
+
chat.call(opts.merge(tools: [{ type: 'function', function: { name: 'fixture', parameters: { type: 'object' } } }]))
|
|
2826
|
+
File.open(calls, 'a') { |file| file.puts 'returned to caller' }
|
|
2827
|
+
raise 'Unexpected normal return'
|
|
2828
|
+
end
|
|
2829
|
+
allow(PWN::Plugins::TransparentBrowser).to receive(:open).and_return(browser: RestClient)
|
|
2830
|
+
allow(RestClient::Request).to receive(:execute) do |args|
|
|
2831
|
+
next '{}' if args.fetch(:url).end_with?('/show')
|
|
2832
|
+
|
|
2833
|
+
File.open(calls, 'a') { |file| file.puts 'read' }
|
|
2834
|
+
response = double('offline stream', code: '200')
|
|
2835
|
+
allow(response).to receive(:read_body).and_yield(wire.byteslice(0, cut)).and_yield(wire.byteslice(cut..))
|
|
2836
|
+
args.fetch(:block_response).call(response)
|
|
2837
|
+
end
|
|
2838
|
+
allow(PWN::AI::Agent::Dispatch).to receive(:call) do
|
|
2839
|
+
File.open(calls, 'a') { |file| file.puts 'unexpected dispatch' }
|
|
2840
|
+
raise 'Action must not be dispatched'
|
|
2841
|
+
end
|
|
2842
|
+
launch("what color is a lemon?\n".chars) { "\u0004" unless @console.send(:busy?) }
|
|
2843
|
+
events = @console.instance_variable_get(:@timeline)
|
|
2844
|
+
expect(events.filter_map { |type, text, *| text if type == :assistant }).to contain_exactly(answer)
|
|
2845
|
+
expect(events.filter_map { |type, text, *| text if type == :warning }).to contain_exactly(a_string_matching(/action.*not processed/i))
|
|
2846
|
+
expect(events.to_s).not_to include('private-fixture')
|
|
2847
|
+
expect(File.readlines(calls, chomp: true)).to eq(['read'])
|
|
2848
|
+
end
|
|
2849
|
+
|
|
2850
|
+
it 'states that instructions in preview text were not run even without structured actions' do
|
|
2851
|
+
console = PWN::Plugins::REPL::AIConsole::Console.new(pry: Pry.new, input: StringIO.new, curses: nil, getch: nil)
|
|
2852
|
+
events = []
|
|
2853
|
+
text = 'Please highlight the word café.'
|
|
2854
|
+
wire = JSON.generate(message: { role: 'assistant', content: text }, done: true).b
|
|
2855
|
+
expect do
|
|
2856
|
+
console.send(:with_stream_preview, events) do
|
|
2857
|
+
PWN::AI::OpenWebUI.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat')
|
|
2858
|
+
end
|
|
2859
|
+
end.to raise_error(PWN::Plugins::REPL::AIConsole::Control::PreviewShown, /No actions from this reply were processed/)
|
|
2860
|
+
expect(events).to eq([[:assistant, text]])
|
|
2861
|
+
end
|
|
2862
|
+
|
|
2815
2863
|
it 'delivers and saves a split UTF-8 text reply in a session with debugging off' do
|
|
2816
2864
|
require 'rest-client'
|
|
2817
2865
|
PWN::Env[:ai] = { active: :ollama, ollama: { model: 'fixture', base_uri: 'https://example.invalid' }, agent: { toolsets: [], plan_first: false } }
|
data/third_party/pwn_rdoc.jsonl
CHANGED
|
@@ -1423,6 +1423,7 @@
|
|
|
1423
1423
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.openwebui_rest_call Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.openwebui_rest_call`: Supported Method Parameters\n\nopenwebui_rest_call(\n\nhttp_method: 'optional HTTP method (defaults to GET)',\nrest_call: 'required rest call path relative to base_uri',\nparams: 'optional params passed in the URI or HTTP Headers',\nhttp_body: 'optional HTTP body sent in HTTP methods that support it e.g. POST',\ntimeout: 'optional timeout in seconds (defaults to 900)',\nspinner: 'optional - display spinner (defaults to false)'\n\n)\n"}]}
|
|
1424
1424
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.parse_stream_payload Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.parse_stream_payload`: "}]}
|
|
1425
1425
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.parse_tool_arguments_object Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.parse_tool_arguments_object`: "}]}
|
|
1426
|
+
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.preview_stream! Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.preview_stream!`: "}]}
|
|
1426
1427
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.real_config_value? Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.real_config_value?`: "}]}
|
|
1427
1428
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.server_tool_ids Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.server_tool_ids`: "}]}
|
|
1428
1429
|
{"messages":[{"role":"user","content":"PWN::AI::OpenWebUI.stream_records Usage"},{"role":"assistant","content":"`PWN::AI::OpenWebUI.stream_records`: "}]}
|
|
@@ -3712,6 +3713,7 @@
|
|
|
3712
3713
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.toggle_verbose Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.toggle_verbose`: "}]}
|
|
3713
3714
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.tone Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.tone`: "}]}
|
|
3714
3715
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.width Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.width`: "}]}
|
|
3716
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.with_stream_preview Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.with_stream_preview`: "}]}
|
|
3715
3717
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.wrap Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.wrap`: "}]}
|
|
3716
3718
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.wrap_command Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.wrap_command`: "}]}
|
|
3717
3719
|
{"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Control.checkpoint Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Control.checkpoint`: "}]}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pwn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.803
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 0day Inc.
|
|
@@ -592,7 +592,7 @@ dependencies:
|
|
|
592
592
|
-
|
|
593
593
|
- "="
|
|
594
594
|
- !ruby/object:Gem::Version
|
|
595
|
-
version: 0.0.
|
|
595
|
+
version: 0.0.194
|
|
596
596
|
type: :development
|
|
597
597
|
prerelease: false
|
|
598
598
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -600,7 +600,7 @@ dependencies:
|
|
|
600
600
|
-
|
|
601
601
|
- "="
|
|
602
602
|
- !ruby/object:Gem::Version
|
|
603
|
-
version: 0.0.
|
|
603
|
+
version: 0.0.194
|
|
604
604
|
- !ruby/object:Gem::Dependency
|
|
605
605
|
name: metasm
|
|
606
606
|
requirement: !ruby/object:Gem::Requirement
|