pinecall 0.11.30 → 0.11.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd828c619164baace761c5df07a94fc7d61b5b29fc95e69f3b94fa099b752bec
4
- data.tar.gz: 1fb669bf22529d766bb8c440c6ad9845f68d26730977b47bdce2ec305839393a
3
+ metadata.gz: 415147a5b46689a9a4d21a43b1eab26cac2d68fef1468f32ffc1ec51764c9569
4
+ data.tar.gz: 3e18e5cf69f4f0871811e6562821c5ef1c33271e1023dc8824f82273811e137d
5
5
  SHA512:
6
- metadata.gz: df6967872c887c111f970a349515ed23a7a9eaa165ff6daae0e1a2121e3c97be8f5e11cc8f62d8c64563976c7e4b1c3fae84258261faae34b0f561441dd1a67d
7
- data.tar.gz: 05305b00cb25c66ca9f8c70e505667b19715d57d1ecce94af5d4af527ff6594f52d96111061102d2da4d9e269a50ad3b3a09dc47a0b1d792c744c66a4e0e41c8
6
+ metadata.gz: 9fe614cbd5df7eb6ca0ec7222fb3ad15dffbb379b3e94839806b3c14718b8a72c5a7cbcc13abc46d41eed19b04f7157d0bf41825930d9ed96759b9868b01ba69
7
+ data.tar.gz: 010fb5e3614b2f82642caa1d6eecf1cba999ed11d36518a5a7dab82b711e169c11c401370411675a599d551c1c2a2775e0d8e7bccafb57a9c95af0eb4a84894d
data/CHANGELOG.md CHANGED
@@ -4,7 +4,24 @@ Every change a person using this gem would notice. The format is
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); version numbers and tags are the
5
5
  maintainer's call.
6
6
 
7
- ## [Unreleased]
7
+ ## [0.11.32] — a passed call is answered at once, and the doctor reads a cluster (2026-11-12)
8
+
9
+ - **A call passed to a teammate is answered by the teammate, at once**, as in TypeScript: what the transfer
10
+ tool answers says the call is the teammate's, that nobody is left to connect the caller to, and to reply to
11
+ what they last said. Under the words before, a small model said "one moment while I connect you" and waited.
12
+
13
+ ## [0.11.31] — a voice app, and @agent says what an agent is (2026-11-12)
14
+
15
+ - **A voice app, as in TypeScript and Python:** `app.rb` makes `Pinecall.voice_app(…)`: lines with a
16
+ greeting, a team (`takes`) the call passes between, a line that chooses who answers, rules, `silence`,
17
+ `on` for what the app hears, and a page of its own.
18
+ - **Flows:** `Pinecall.flow("…") { |input, step| … }`, its runs kept by the gateway.
19
+ - **Tasks:** a tool asks the caller with `ask(Pinecall::GetEmail)`; `Pinecall.task(…)` makes one.
20
+ - **The caller's screen:** `screen`, `Pinecall.part`, `scenes`, `tool shows:`, `call.show`.
21
+ - **A class declares its `timezone`.**
22
+
23
+ - **The wire reads `stage.changed`**: the agent's settings name another vendor, model or voice for a stage of a
24
+ live call. The model and the voice run from its next turn; the ears wait for the next call (`applied` false).
8
25
 
9
26
  ## [0.11.30] — an app is written whole in its class (2026-11-09)
10
27
 
@@ -13,7 +13,7 @@ module Pinecall
13
13
  AS_WRITTEN = %i[phone whatsapp web channel_rules].freeze
14
14
 
15
15
  # The settings a class may declare. Must match the TypeScript package's `ENVIRONMENT`.
16
- ENVIRONMENT = %i[language voice llm realtime stt judge greeting hangup turn says hears knowledge docs memory record judges
16
+ ENVIRONMENT = %i[language timezone voice llm realtime stt judge greeting hangup turn says hears knowledge docs memory record judges
17
17
  personas widget idle voicemail stt_fallbacks tts_fallbacks bases monitors].freeze
18
18
 
19
19
  # The ones written as the wire's own fields, keyword by keyword: `docs base: "…"`, `judges on: [...]`.
@@ -143,7 +143,7 @@ module Pinecall
143
143
  end
144
144
 
145
145
  # `language "es"`, `says [{ word: "GSA", spoken: "ge ese a" }]`, `record false`, `bases [{ base: "faq" }, { base: "prices" }]`.
146
- %i[language says record bases monitors].each do |field|
146
+ %i[language timezone says record bases monitors].each do |field|
147
147
  define_method(field) do |value = NOTHING|
148
148
  return environment[field] if value.equal?(NOTHING)
149
149
 
@@ -217,6 +217,36 @@ module Pinecall
217
217
  end
218
218
  end
219
219
 
220
+ # What a teammate passes it, as a model reads it: `takes "a question about a bill"`.
221
+ def takes(what = NOTHING)
222
+ return declared_takes if what.equal?(NOTHING)
223
+
224
+ @takes = what.to_s.strip.empty? ? nil : what.to_s.strip
225
+ end
226
+
227
+ def declared_takes = @takes || (superclass.respond_to?(:declared_takes) ? superclass.declared_takes : nil)
228
+
229
+ # The tasks its tools may ask the caller for: `tasks Pinecall::GetEmail, Pinecall::GetPhone`.
230
+ def tasks(*asked)
231
+ return declared_tasks if asked.empty?
232
+
233
+ wrong = asked.flatten.reject { |one| one.is_a?(Task) }
234
+ raise DeclarationRefused, "#{self}: tasks is a list of tasks, like tasks Pinecall::GetEmail, Pinecall::GetPhone" unless wrong.empty?
235
+
236
+ @tasks = asked.flatten
237
+ end
238
+
239
+ def declared_tasks = @tasks || (superclass.respond_to?(:declared_tasks) ? superclass.declared_tasks : [])
240
+
241
+ # The scenes of the caller's screen, each with what it shows: `scenes agenda: "the open times"`.
242
+ def scenes(**declared)
243
+ return declared_scenes if declared.empty?
244
+
245
+ @scenes = declared.to_h { |name, what| Screen.scene!(self, name, what) }
246
+ end
247
+
248
+ def declared_scenes = @scenes || (superclass.respond_to?(:declared_scenes) ? superclass.declared_scenes : {})
249
+
220
250
  # What the class declares of its environment, including inherited values.
221
251
  def environment
222
252
  @environment ||= superclass.respond_to?(:environment) ? superclass.environment.dup : {}
@@ -26,9 +26,10 @@ module Pinecall
26
26
  # @param pii [Array<Symbol>] parameters with personal data, masked in the log
27
27
  # @param timeout [Numeric] seconds the platform waits for the method
28
28
  # @param params [Hash{Symbol=>Object}] parameter types, e.g. `{ day: String, how_many: Integer }`
29
+ # @param shows [Symbol] the scene of the caller's screen it puts up once it returns (`scenes`)
29
30
  def tool(**options)
30
31
  unknown = options.keys - %i[
31
- when stage confirm announce delayed delayed_after failed quiet preview pii timeout params doc
32
+ when stage confirm announce delayed delayed_after failed quiet preview pii timeout params doc shows
32
33
  ]
33
34
  raise DeclarationRefused, "tool takes no #{unknown.join(", ")}" unless unknown.empty?
34
35
 
@@ -79,6 +79,12 @@ module Pinecall
79
79
  # Make the model speak now, guided by instructions the caller does not hear.
80
80
  def reply(instructions, **options) = call.reply(instructions, **options)
81
81
 
82
+ # Ask the caller for one of the class's `tasks` from inside a tool; blocks the tool until given.
83
+ def ask(task) = call.ask(task)
84
+
85
+ # What the caller's page shows now: parts (`Agenda.(slots:)`), words, an array of them.
86
+ def screen = nil
87
+
82
88
  # Append a named entry to the call's log.
83
89
  def log(name, data = nil)
84
90
  entry = LogEntry.new(seq: next_seq, name: name.to_s, data:, at: Time.now.to_f)
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pinecall
4
+ # The asking of one call: a tool that stops to ask has its call answered with the question, and
5
+ # goes on, on its own thread, once the tool that gives the answer is called. One question at a time.
6
+ class Asking
7
+ NOT_IN_A_TOOL = "ask is for inside a tool: the tool's call is what the question is answered on"
8
+
9
+ # What a tool stopped to ask for, for a screen that draws it as a form.
10
+ Asked = Data.define(:task, :asks, :fields, :refused)
11
+
12
+ # One tool running on its thread: its name, and where it says it finished, raised or asked.
13
+ Frame = Data.define(:tool, :said)
14
+
15
+ # The task one tool waits for, and where its answer is handed to it.
16
+ Waiting = Data.define(:task, :frame, :answer)
17
+
18
+ attr_reader :tasks
19
+
20
+ # The tasks a call may ask for: its class's, and with a team every member's, once each.
21
+ def self.tasks_on(klass, team = nil) = (team.nil? ? [klass] : team.keys).flat_map(&:declared_tasks).uniq
22
+
23
+ # The tools a set of tasks is given with; a name an agent's own tool has is refused.
24
+ def self.giving_tools(tasks, taken)
25
+ clash = tasks.find { |asked| taken.include?(Tasks.given_with(asked)) }
26
+ unless clash.nil?
27
+ raise DeclarationRefused, "the task #{clash.name} is given with #{Tasks.given_with(clash)}, and an agent declares a tool of that name"
28
+ end
29
+
30
+ tasks.map { |asked| Tasks.giving_tool(asked) }
31
+ end
32
+
33
+ def initialize(tasks)
34
+ @tasks = tasks
35
+ @waiting = nil
36
+ @refused = nil
37
+ @lock = Mutex.new
38
+ end
39
+
40
+ # The one tool open while something is asked for; nil when nothing is.
41
+ def open = (waiting = @waiting) && Tasks.giving_tool(waiting.task)
42
+
43
+ # What is asked for now, or nil.
44
+ def asking
45
+ waiting = @waiting
46
+ return nil if waiting.nil?
47
+
48
+ Asked.new(task: waiting.task.name, asks: waiting.task.asks, fields: waiting.task.fields, refused: @refused)
49
+ end
50
+
51
+ # Whether a tool of that name gives one of the call's tasks.
52
+ def gives?(tool) = @tasks.any? { |asked| Tasks.given_with(asked) == tool.to_s }
53
+
54
+ # Run the tool on a thread of its own: what it returned, or the question it stopped at.
55
+ def run(name, &tool)
56
+ frame = Frame.new(tool: name.to_s, said: Thread::Queue.new)
57
+ Thread.new do
58
+ Fiber[:pinecall_frame] = frame
59
+ frame.said.push([:returned, tool.call])
60
+ rescue StandardError => e
61
+ frame.said.push([:raised, e])
62
+ end
63
+ outcome(frame)
64
+ end
65
+
66
+ # Ask for a task from inside a tool: blocks the tool's thread until the answer is given.
67
+ def ask(asked)
68
+ frame = Fiber[:pinecall_frame]
69
+ raise Error, NOT_IN_A_TOOL if frame.nil?
70
+ raise Error, "#{asked.name} is not a task of this agent: name it in tasks" unless @tasks.include?(asked)
71
+
72
+ answer = Thread::Queue.new
73
+ @lock.synchronize do
74
+ raise Error, "#{@waiting.task.name} is being asked for: one question at a time" unless @waiting.nil?
75
+
76
+ @waiting = Waiting.new(task: asked, frame:, answer:)
77
+ end
78
+ frame.said.push([:asked, Tasks.asking_for(asked)])
79
+ kind, value = answer.pop
80
+ raise value if kind == :dropped
81
+
82
+ value
83
+ end
84
+
85
+ # The model gave the answer: the waiting tool goes on, and this call says how it ended.
86
+ def given(tool, arguments)
87
+ waiting = @waiting
88
+ raise ToolFailed, "#{tool}: nothing is being asked for with it now" if waiting.nil? || Tasks.given_with(waiting.task) != tool.to_s
89
+
90
+ given = arguments.to_h { |key, value| [key.to_s, value] }
91
+ missing = waiting.task.fields.keys.reject { |field| given[field].is_a?(String) }
92
+ raise ToolFailed, "#{tool}: #{missing.join(", ")} must be given, in words" unless missing.empty?
93
+
94
+ value = checked(waiting.task, given.slice(*waiting.task.fields.keys))
95
+ @lock.synchronize { @waiting = nil }
96
+ @refused = nil
97
+ waiting.answer.push([:given, value])
98
+ ended = outcome(waiting.frame)
99
+ ended.is_a?(String) ? ended : { finished: waiting.frame.tool, result: ended }
100
+ end
101
+
102
+ # The caller's page gave the answer: what the model is to be told, or nil.
103
+ def given_by_page(task, values)
104
+ waiting = @waiting
105
+ return nil if waiting.nil? || waiting.task.name != task.to_s || !values.is_a?(Hash)
106
+
107
+ ended = given(Tasks.given_with(waiting.task), values)
108
+ what = waiting.task.asks
109
+ return "The caller gave #{what} on their screen. #{ended}" if ended.is_a?(String)
110
+
111
+ "The caller gave #{what} on their screen, and #{waiting.frame.tool} is done with this result: #{JSON.generate(ended[:result])}. Tell them how it went."
112
+ rescue ToolFailed => e
113
+ @refused = e.message
114
+ nil
115
+ end
116
+
117
+ # The call ended with a question open: the tool that asked is told.
118
+ def abandon
119
+ waiting = @lock.synchronize { @waiting.tap { @waiting = nil } }
120
+ return if waiting.nil?
121
+
122
+ waiting.answer.push([:dropped, Error.new("the call ended before the caller gave #{waiting.task.asks}")])
123
+ end
124
+
125
+ private
126
+
127
+ # What the tool's thread said next: its result, its question, or what it raised.
128
+ def outcome(frame)
129
+ kind, value = frame.said.pop
130
+ raise value if kind == :raised
131
+
132
+ value
133
+ end
134
+
135
+ def checked(task, given)
136
+ task.check.call(given)
137
+ rescue StandardError => e
138
+ raise ToolFailed, e.message
139
+ end
140
+ end
141
+ end
@@ -74,17 +74,18 @@ module Pinecall
74
74
 
75
75
  module_function
76
76
 
77
- def render(agent, resumed: false, remembered: [], line: nil)
77
+ def render(agent, resumed: false, remembered: [], line: nil, rules: [])
78
78
  reading = reading_for(agent, resumed:, remembered:, line:)
79
79
  blocks = FRAMEWORK.map do |spec|
80
- Block.new(name: spec[:name], region: spec[:region], text: text_of(agent, spec[:name], reading))
80
+ Block.new(name: spec[:name], region: spec[:region], text: text_of(agent, spec[:name], reading, rules))
81
81
  end
82
82
  Blocks.new(blocks:, history: history(agent))
83
83
  end
84
84
 
85
- # The class docstring, the framework's rules and protocols, and the channel's. Reads no state.
86
- def identity(agent)
87
- [agent.doc, tagged("rules", Rules::RULES), tagged("protocols", Rules::PROTOCOLS), channel(agent)]
85
+ # The class docstring, the framework's and the app's rules, the protocols, the channel's. Reads no state.
86
+ def identity(agent, rules = [])
87
+ app_rules = rules.map { |rule| "- #{rule}" }.join("\n")
88
+ [agent.doc, tagged("rules", Rules::RULES), tagged("app_rules", app_rules), tagged("protocols", Rules::PROTOCOLS), channel(agent)]
88
89
  .compact.reject { |part| part.strip.empty? }.join("\n\n")
89
90
  end
90
91
 
@@ -113,9 +114,12 @@ module Pinecall
113
114
  # Marker for a collapsed stretch of the call.
114
115
  def collapsed(seq) = "<!-- collapsed: #{JSON.generate({ seq: })} -->"
115
116
 
117
+ # The view, and what the model reads of its caller's screen.
116
118
  def view(agent, reading)
117
119
  view = agent.class.view
118
- view.nil? ? "" : view.render(reading)
120
+ shown = view.nil? ? "" : view.render(reading)
121
+ scene = agent.call? ? agent.call.scene : nil
122
+ [shown, tagged("screen", Screen.scene_line(agent.class.declared_scenes, scene))].reject(&:empty?).join("\n\n")
119
123
  end
120
124
 
121
125
  # The view's scope: state, call context, and remembered facts (queryable, never printed).
@@ -135,9 +139,9 @@ module Pinecall
135
139
  sections.map { |header, text| "#{header}\n#{text}".rstrip }.join("\n\n")
136
140
  end
137
141
 
138
- def text_of(agent, called, reading)
142
+ def text_of(agent, called, reading, rules = [])
139
143
  case called
140
- when "identity" then identity(agent)
144
+ when "identity" then identity(agent, rules)
141
145
  # Filled by the gateway from the agent's settings (`pinecall agent knowledge edit`).
142
146
  when "knowledge" then ""
143
147
  when "tools" then tools(agent)
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pinecall
4
+ # What a tool call does on a served call, and one agent of a team taking the call from another.
5
+ module Bridge
6
+ module_function
7
+
8
+ # A task given, the screen moved, the call passed, or one of the agent's own tools run.
9
+ def dispatched(serving, name, arguments, call_id)
10
+ return serving.asking.given(name, arguments) if serving.asking.gives?(name)
11
+ return Screened.scene_chosen(serving.world, serving.screened, serving.klass, arguments[:scene]) if name == Screen::SHOW_SCREEN
12
+
13
+ declared = serving.klass.tool_named(name)
14
+ mate = declared.nil? && !serving.team.nil? ? Handoff.mate_named(name, serving.team) : nil
15
+ return serving.world.handoff(mate, arguments) unless mate.nil?
16
+ raise ToolFailed, "#{name}: this agent declares no such tool" if declared.nil?
17
+
18
+ serving.asking.run(name) { showing(serving, declared, arguments, call_id) }
19
+ end
20
+
21
+ # Run a tool; one that shows a scene keeps it through the turn, and puts it up once it returns.
22
+ def showing(serving, declared, arguments, call_id)
23
+ scene = declared.options[:shows]
24
+ serving.screened.kept = true unless scene.nil?
25
+ result = Agent::Tools.run(serving.agent, declared, arguments, call_id)
26
+ serving.world.scene = scene.to_s unless scene.nil?
27
+ result
28
+ end
29
+
30
+ # The call is served by an instance of `klass` from now on; the call itself stays.
31
+ def become(serving, klass, call, instance = nil)
32
+ instance ||= klass.new.seal
33
+ instance.reads_last_from(serving.last) unless serving.last.nil?
34
+ instance.serving(serving.world)
35
+ serving.agent = instance
36
+ serving.klass = klass
37
+ serving.transfers = Handoff.transfers_of(klass, serving.team) unless serving.team.nil?
38
+ forward_log(serving, call)
39
+ end
40
+
41
+ # One agent of the team takes the call from another; the model is told whose it is now.
42
+ def passed(serving, call, to, data)
43
+ slug = serving.team&.[](to)
44
+ raise ToolFailed, "#{to} is not of this call's team" if slug.nil?
45
+ raise ToolFailed, "this call was passed #{Handoff::MOST_PASSES} times already: answer the caller yourself" if serving.passes >= Handoff::MOST_PASSES
46
+
47
+ serving.stops.values_at(:state, :entries, :log).compact.each(&:call)
48
+ serving.stops.clear
49
+ serving.agent.serving(nil)
50
+ handed = as_object(data)
51
+ call.log(Handoff::PASSED, { from: serving.team.fetch(serving.klass, ""), to: slug, **handed })
52
+ serving.world.handed = handed
53
+ serving.world.scene = nil
54
+ become(serving, to, call)
55
+ serving.passes += 1
56
+ hooked(serving, call, :on_call, serving.world)
57
+ call.set_state(state_of(serving))
58
+ sync(serving, call)
59
+ listen(serving, call)
60
+ passed_to(slug)
61
+ end
62
+
63
+ # What the model reads once the call is the teammate's. It called a tool named for a transfer, and a
64
+ # small model goes on as whoever transfers ("one moment while I connect you") and then waits: so the
65
+ # words say there is nobody left to connect the caller to, and to answer them now.
66
+ def passed_to(slug)
67
+ "Done: you are #{slug} now, and the caller is already talking to you. There is nobody left to connect " \
68
+ 'them to, so never say "one moment" or that you are connecting or transferring them. ' \
69
+ "Reply to their last message now, as #{slug}."
70
+ end
71
+
72
+ # The line chooses while the caller hears its greeting; a choice it could not make is said on the log.
73
+ def routed(serving, call, answers)
74
+ first = Handoff.answered_by(answers, serving.world, serving.klass, serving.team)
75
+ if first.agent != serving.klass || !first.why.nil?
76
+ call.log(Handoff::ROUTED, { to: serving.team.fetch(first.agent, ""), why: first.why }.compact)
77
+ end
78
+ return if first.agent == serving.klass
79
+
80
+ serving.stops.delete(:log)&.call
81
+ become(serving, first.agent, call)
82
+ end
83
+
84
+ # The call's state as the gateway is told it: the agent's own, and its screen once drawn.
85
+ def state_of(serving) = Screened.state_with(serving.agent.snapshot, serving.screened)
86
+
87
+ # The page answered a task: the waiting tool goes on, the model is told, the form drawn again.
88
+ def given_by_page(serving, call, data)
89
+ told = serving.asking.given_by_page(data[:task], data[:given])
90
+ serving.world.reply(told) unless told.nil?
91
+ sync(serving, call)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pinecall
4
+ module Bridge
5
+ # A call's screen as the bridge keeps it: drawn from the agent, sent in the state when it moved,
6
+ # and moved by the conversation's turns.
7
+ module Screened
8
+ # The screen a call's page was last sent, and whether this turn kept its scene.
9
+ class Kept
10
+ attr_accessor :screen, :key, :by_user, :kept
11
+
12
+ def initialize
13
+ @screen = nil
14
+ @key = "[]"
15
+ @by_user = false
16
+ @kept = false
17
+ end
18
+ end
19
+
20
+ module_function
21
+
22
+ # Whether one of the classes draws a screen: its field is then public.
23
+ def screens?(classes) = classes.any? { |klass| Screen.draws?(klass) }
24
+
25
+ # A class with a screen declares its field public, and with tasks the page's event.
26
+ def declared(options, tasks:)
27
+ fields = [*options[:state_fields], { name: Screen::SCREEN, visibility: "public" }]
28
+ events = tasks ? [*options[:events], { name: Screen::TASK_GIVE, from: ["participant"] }] : options[:events]
29
+ options.merge(state_fields: fields, events:).compact
30
+ end
31
+
32
+ # Draw the screen with what is shown over it; true when it is not the one already sent.
33
+ def redrawn(drawn, shown, kept)
34
+ screen = Screen.screen_of([drawn, shown])
35
+ key = JSON.generate(screen)
36
+ return false if key == kept.key
37
+
38
+ kept.screen = screen
39
+ kept.key = key
40
+ true
41
+ end
42
+
43
+ # The call's state as the gateway is told it: the agent's own, and its screen once drawn.
44
+ def state_with(snapshot, kept) = kept.screen.nil? ? snapshot : snapshot.merge(Screen::SCREEN.to_sym => kept.screen)
45
+
46
+ # A state the gateway kept, without the screen: it is drawn again, never restored.
47
+ def unscreened(state) = state.reject { |name, _| name.to_s == Screen::SCREEN }
48
+
49
+ # The tool the classes of a call move their screen with, declared once for all of them.
50
+ def scene_tools(classes, taken)
51
+ scenes = classes.each_with_object({}) { |klass, all| all.merge!(Screen.scenes_of(klass)) }
52
+ return [] if scenes.empty?
53
+ if taken.include?(Screen::SHOW_SCREEN)
54
+ raise DeclarationRefused, "#{Screen::SHOW_SCREEN} is the tool a screen is moved with, and an agent declares a tool so named"
55
+ end
56
+
57
+ [Screen.showing_tool(scenes)]
58
+ end
59
+
60
+ # The tool the class serving the call moves its screen with, when it declares scenes.
61
+ def scene_tool_of(klass)
62
+ scenes = klass.declared_scenes
63
+ scenes.empty? ? [] : [Screen.showing_tool(scenes)]
64
+ end
65
+
66
+ # The model chose a scene, or none: it is the call's now, and kept through this turn.
67
+ def scene_chosen(world, kept, klass, scene)
68
+ scene = scene.to_s
69
+ scenes = klass.declared_scenes
70
+ return "There is no scene #{scene}: #{[*scenes.keys, Screen::NO_SCENE].join(", ")}." unless scene == Screen::NO_SCENE || scenes.key?(scene)
71
+
72
+ world.scene = scene == Screen::NO_SCENE ? nil : scene
73
+ kept.kept = true
74
+ "shown"
75
+ end
76
+
77
+ # A turn went by; one the caller opened that kept no scene takes it away once the agent waits.
78
+ # True when the scene moved.
79
+ def turned(type, world, kept)
80
+ if type == "turn.user"
81
+ kept.by_user = true
82
+ kept.kept = false
83
+ return false
84
+ end
85
+ return false unless type == "agent.waiting" && kept.by_user
86
+
87
+ kept.by_user = false
88
+ return false if kept.kept || world.scene.nil?
89
+
90
+ world.scene = nil
91
+ true
92
+ end
93
+ end
94
+ end
95
+ end