datagrout-conduit 0.1.0 → 0.2.0
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/lib/datagrout_conduit/client.rb +45 -170
- data/lib/datagrout_conduit/namespaces/deliverables.rb +29 -0
- data/lib/datagrout_conduit/namespaces/ephemerals.rb +25 -0
- data/lib/datagrout_conduit/namespaces/flow.rb +62 -0
- data/lib/datagrout_conduit/namespaces/logic.rb +78 -0
- data/lib/datagrout_conduit/namespaces/prism.rb +58 -0
- data/lib/datagrout_conduit/namespaces/warden.rb +33 -0
- data/lib/datagrout_conduit/types.rb +56 -0
- data/lib/datagrout_conduit/version.rb +1 -1
- data/lib/datagrout_conduit.rb +6 -22
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28e196cb29ede549875a2c3ecb87eeff2b2c6479d6a24a6a095d00b4891ff11c
|
|
4
|
+
data.tar.gz: 45eeee43e6fe5eaee59fd2527c8d48b9317cece38d503637b7225abf11d6b67d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e763c86181e3d7ef415e3bf07cb7544d76bb064d725c78fbf006a6adc8f3ef95922cee7a375bdf5aded71c26679cf06d30548c7e7cb56fd672c2b7f212b40d0
|
|
7
|
+
data.tar.gz: 44eb007fc146df62969f0428b1d0ced58c8cba78167ca67df5744a25314686023b99a73eb6a4a4b1b2a11377921969a3cb7b8b2e88e4e11a635790ed7b29b405
|
|
@@ -193,6 +193,34 @@ module DatagroutConduit
|
|
|
193
193
|
result["messages"] || []
|
|
194
194
|
end
|
|
195
195
|
|
|
196
|
+
# ================================================================
|
|
197
|
+
# Namespace Accessors
|
|
198
|
+
# ================================================================
|
|
199
|
+
|
|
200
|
+
def prism
|
|
201
|
+
@prism ||= PrismNamespace.new(self)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def logic
|
|
205
|
+
@logic ||= LogicNamespace.new(self)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def warden
|
|
209
|
+
@warden ||= WardenNamespace.new(self)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def deliverables
|
|
213
|
+
@deliverables ||= DeliverablesNamespace.new(self)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def ephemerals
|
|
217
|
+
@ephemerals ||= EphemeralsNamespace.new(self)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def flow
|
|
221
|
+
@flow ||= FlowNamespace.new(self)
|
|
222
|
+
end
|
|
223
|
+
|
|
196
224
|
# ================================================================
|
|
197
225
|
# DataGrout Extensions
|
|
198
226
|
# ================================================================
|
|
@@ -225,6 +253,23 @@ module DatagroutConduit
|
|
|
225
253
|
call_dg_tool("data-grout/discovery.perform", params)
|
|
226
254
|
end
|
|
227
255
|
|
|
256
|
+
# Execute multiple tool calls in a single gateway request.
|
|
257
|
+
#
|
|
258
|
+
# Each element should be a hash with "tool" and "args" keys.
|
|
259
|
+
# Returns an array of results in the same order as the input calls.
|
|
260
|
+
#
|
|
261
|
+
# results = client.perform_batch([
|
|
262
|
+
# { "tool" => "data-grout/data.count", "args" => { "data" => [1, 2, 3] } },
|
|
263
|
+
# { "tool" => "data-grout/data.keys", "args" => { "data" => { "a" => 1 } } }
|
|
264
|
+
# ])
|
|
265
|
+
def perform_batch(calls)
|
|
266
|
+
warn_if_not_dg("perform_batch")
|
|
267
|
+
ensure_initialized!
|
|
268
|
+
|
|
269
|
+
result = call_dg_tool("data-grout/discovery.perform", calls)
|
|
270
|
+
result.is_a?(Array) ? result : [result]
|
|
271
|
+
end
|
|
272
|
+
|
|
228
273
|
# Start or continue a guided workflow.
|
|
229
274
|
def guide(goal: nil, session_id: nil, choice: nil)
|
|
230
275
|
warn_if_not_dg("guide")
|
|
@@ -239,32 +284,6 @@ module DatagroutConduit
|
|
|
239
284
|
GuidedSession.new(self, GuideState.from_hash(result))
|
|
240
285
|
end
|
|
241
286
|
|
|
242
|
-
# Execute a multi-step workflow plan.
|
|
243
|
-
def flow_into(plan, validate_ctc: true, save_as_skill: false, input_data: nil)
|
|
244
|
-
warn_if_not_dg("flow_into")
|
|
245
|
-
ensure_initialized!
|
|
246
|
-
|
|
247
|
-
params = {
|
|
248
|
-
"plan" => plan,
|
|
249
|
-
"validate_ctc" => validate_ctc,
|
|
250
|
-
"save_as_skill" => save_as_skill
|
|
251
|
-
}
|
|
252
|
-
params["input_data"] = input_data if input_data
|
|
253
|
-
|
|
254
|
-
call_dg_tool("data-grout/flow.into", params)
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
# Semantic type transformation via Prism.
|
|
258
|
-
def prism_focus(data:, source_type:, target_type:, source_annotations: nil, target_annotations: nil, context: nil)
|
|
259
|
-
params = { "data" => data, "source_type" => source_type, "target_type" => target_type }
|
|
260
|
-
params["source_annotations"] = source_annotations if source_annotations
|
|
261
|
-
params["target_annotations"] = target_annotations if target_annotations
|
|
262
|
-
params["context"] = context if context
|
|
263
|
-
warn_if_not_dg("prism_focus")
|
|
264
|
-
ensure_initialized!
|
|
265
|
-
call_dg_tool("data-grout/prism.focus", params)
|
|
266
|
-
end
|
|
267
|
-
|
|
268
287
|
# Semantic discovery plan — return a ranked list of tools for a goal.
|
|
269
288
|
# At least one of `goal:` or `query:` must be provided.
|
|
270
289
|
def plan(goal: nil, query: nil, **opts)
|
|
@@ -285,150 +304,6 @@ module DatagroutConduit
|
|
|
285
304
|
call_dg_tool("data-grout/discovery.plan", params)
|
|
286
305
|
end
|
|
287
306
|
|
|
288
|
-
# Transform / reshape a payload via Prism.
|
|
289
|
-
def refract(goal:, payload:, **opts)
|
|
290
|
-
params = { "goal" => goal, "payload" => payload }
|
|
291
|
-
params["verbose"] = opts[:verbose] if opts.key?(:verbose)
|
|
292
|
-
params["chart"] = opts[:chart] if opts.key?(:chart)
|
|
293
|
-
warn_if_not_dg("refract")
|
|
294
|
-
ensure_initialized!
|
|
295
|
-
call_dg_tool("data-grout/prism.refract", params)
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
# Generate a chart/visual from a payload via Prism.
|
|
299
|
-
def chart(goal:, payload:, **opts)
|
|
300
|
-
params = { "goal" => goal, "payload" => payload }
|
|
301
|
-
params["format"] = opts[:format] if opts[:format]
|
|
302
|
-
params["chart_type"] = opts[:chart_type] if opts[:chart_type]
|
|
303
|
-
params["title"] = opts[:title] if opts[:title]
|
|
304
|
-
params["x_label"] = opts[:x_label] if opts[:x_label]
|
|
305
|
-
params["y_label"] = opts[:y_label] if opts[:y_label]
|
|
306
|
-
params["width"] = opts[:width] if opts[:width]
|
|
307
|
-
params["height"] = opts[:height] if opts[:height]
|
|
308
|
-
warn_if_not_dg("chart")
|
|
309
|
-
ensure_initialized!
|
|
310
|
-
call_dg_tool("data-grout/prism.chart", params)
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
# Generate a document toward a natural-language goal.
|
|
314
|
-
def render(goal:, payload: nil, format: "markdown", sections: nil, **opts)
|
|
315
|
-
params = { "goal" => goal, "format" => format }.merge(normalize_hash(opts))
|
|
316
|
-
params["payload"] = payload if payload
|
|
317
|
-
params["sections"] = sections if sections
|
|
318
|
-
warn_if_not_dg("render")
|
|
319
|
-
ensure_initialized!
|
|
320
|
-
call_dg_tool("data-grout/prism.render", params)
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
# Convert content to another format (no LLM). Supports csv, xlsx, pdf, json, etc.
|
|
324
|
-
def export(content:, format:, style: nil, metadata: nil, **opts)
|
|
325
|
-
params = { "content" => content, "format" => format }.merge(normalize_hash(opts))
|
|
326
|
-
params["style"] = style if style
|
|
327
|
-
params["metadata"] = metadata if metadata
|
|
328
|
-
warn_if_not_dg("export")
|
|
329
|
-
ensure_initialized!
|
|
330
|
-
call_dg_tool("data-grout/prism.export", params)
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
# Pause workflow for human approval.
|
|
334
|
-
def request_approval(action:, details: nil, reason: nil, context: nil, **opts)
|
|
335
|
-
params = { "action" => action }.merge(normalize_hash(opts))
|
|
336
|
-
params["details"] = details if details
|
|
337
|
-
params["reason"] = reason if reason
|
|
338
|
-
params["context"] = context if context
|
|
339
|
-
warn_if_not_dg("request_approval")
|
|
340
|
-
ensure_initialized!
|
|
341
|
-
call_dg_tool("data-grout/flow.request-approval", params)
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
# Request user clarification for missing fields.
|
|
345
|
-
def request_feedback(missing_fields:, reason:, current_data: nil, suggestions: nil, context: nil, **opts)
|
|
346
|
-
params = { "missing_fields" => missing_fields, "reason" => reason }.merge(normalize_hash(opts))
|
|
347
|
-
params["current_data"] = current_data if current_data
|
|
348
|
-
params["suggestions"] = suggestions if suggestions
|
|
349
|
-
params["context"] = context if context
|
|
350
|
-
warn_if_not_dg("request_feedback")
|
|
351
|
-
ensure_initialized!
|
|
352
|
-
call_dg_tool("data-grout/flow.request-feedback", params)
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
# List recent tool executions for the current server.
|
|
356
|
-
def execution_history(limit: 50, offset: 0, status: nil, refractions_only: false, **opts)
|
|
357
|
-
params = { "limit" => limit, "offset" => offset, "refractions_only" => refractions_only }.merge(normalize_hash(opts))
|
|
358
|
-
params["status"] = status if status
|
|
359
|
-
warn_if_not_dg("execution_history")
|
|
360
|
-
ensure_initialized!
|
|
361
|
-
call_dg_tool("data-grout/inspect.execution-history", params)
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
# Get details for a specific execution.
|
|
365
|
-
def execution_details(execution_id:)
|
|
366
|
-
params = { "execution_id" => execution_id }
|
|
367
|
-
warn_if_not_dg("execution_details")
|
|
368
|
-
ensure_initialized!
|
|
369
|
-
call_dg_tool("data-grout/inspect.execution-details", params)
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
# ================================================================
|
|
373
|
-
# Logic Cell Methods
|
|
374
|
-
# ================================================================
|
|
375
|
-
|
|
376
|
-
# Assert a fact or statement into the logic cell.
|
|
377
|
-
def remember(statement: nil, facts: nil, tag: nil)
|
|
378
|
-
raise ArgumentError, "must provide statement or facts" unless statement || facts
|
|
379
|
-
|
|
380
|
-
params = {}
|
|
381
|
-
params["statement"] = statement if statement
|
|
382
|
-
params["facts"] = facts if facts
|
|
383
|
-
params["tag"] = tag if tag
|
|
384
|
-
warn_if_not_dg("remember")
|
|
385
|
-
ensure_initialized!
|
|
386
|
-
call_dg_tool("data-grout/logic.remember", params)
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
# Query the logic cell by question or patterns.
|
|
390
|
-
def query_cell(question: nil, patterns: nil, limit: nil)
|
|
391
|
-
raise ArgumentError, "must provide question or patterns" unless question || patterns
|
|
392
|
-
|
|
393
|
-
params = {}
|
|
394
|
-
params["question"] = question if question
|
|
395
|
-
params["patterns"] = patterns if patterns
|
|
396
|
-
params["limit"] = limit if limit
|
|
397
|
-
warn_if_not_dg("query_cell")
|
|
398
|
-
ensure_initialized!
|
|
399
|
-
call_dg_tool("data-grout/logic.query", params)
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
# Remove facts from the logic cell by handles or pattern.
|
|
403
|
-
def forget(handles: nil, pattern: nil)
|
|
404
|
-
raise ArgumentError, "must provide handles or pattern" unless handles || pattern
|
|
405
|
-
|
|
406
|
-
params = {}
|
|
407
|
-
params["handles"] = handles if handles
|
|
408
|
-
params["pattern"] = pattern if pattern
|
|
409
|
-
warn_if_not_dg("forget")
|
|
410
|
-
ensure_initialized!
|
|
411
|
-
call_dg_tool("data-grout/logic.forget", params)
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
# Assert a constraint rule into the logic cell.
|
|
415
|
-
def constrain(rule:, tag: nil)
|
|
416
|
-
params = { "rule" => rule }
|
|
417
|
-
params["tag"] = tag if tag
|
|
418
|
-
warn_if_not_dg("constrain")
|
|
419
|
-
ensure_initialized!
|
|
420
|
-
call_dg_tool("data-grout/logic.constrain", params)
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
# Reflect on known facts about an entity.
|
|
424
|
-
def reflect(entity: nil, summary_only: false)
|
|
425
|
-
params = { "summary_only" => summary_only }
|
|
426
|
-
params["entity"] = entity if entity
|
|
427
|
-
warn_if_not_dg("reflect")
|
|
428
|
-
ensure_initialized!
|
|
429
|
-
call_dg_tool("data-grout/logic.reflect", params)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
307
|
# Call any DataGrout first-party tool by short name.
|
|
433
308
|
# e.g. client.dg("prism.render", { payload: data, goal: "summary" })
|
|
434
309
|
def dg(tool_short_name, params = {})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class DeliverablesNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def register(params = {})
|
|
10
|
+
dg_call("deliverables.register", params)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list(params = {})
|
|
14
|
+
dg_call("deliverables.list", params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get(ref_id)
|
|
18
|
+
dg_call("deliverables.get", { "ref" => ref_id })
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def dg_call(short_name, params)
|
|
24
|
+
@client.send(:warn_if_not_dg, short_name)
|
|
25
|
+
@client.send(:ensure_initialized!)
|
|
26
|
+
@client.send(:call_dg_tool, "data-grout/#{short_name}", params)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class EphemeralsNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def list(params = {})
|
|
10
|
+
dg_call("ephemerals.list", "data-grout/ephemerals.list", params)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def inspect(cache_ref)
|
|
14
|
+
dg_call("ephemerals.inspect", "data-grout/ephemerals.inspect", { "cache_ref" => cache_ref })
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def dg_call(label, tool_name, params)
|
|
20
|
+
@client.send(:warn_if_not_dg, label)
|
|
21
|
+
@client.send(:ensure_initialized!)
|
|
22
|
+
@client.send(:call_dg_tool, tool_name, params)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class FlowNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def run(plan, validate_ctc: true, save_as_skill: false, input_data: nil)
|
|
10
|
+
params = {
|
|
11
|
+
"plan" => plan,
|
|
12
|
+
"validate_ctc" => validate_ctc,
|
|
13
|
+
"save_as_skill" => save_as_skill
|
|
14
|
+
}
|
|
15
|
+
params["input_data"] = input_data if input_data
|
|
16
|
+
dg_call("flow.into", "data-grout/flow.into", params)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def route(branches:, payload: nil, cache_ref: nil, else_target: nil, **opts)
|
|
20
|
+
params = { "branches" => branches }
|
|
21
|
+
params["payload"] = payload if payload
|
|
22
|
+
params["cache_ref"] = cache_ref if cache_ref
|
|
23
|
+
params["else"] = else_target if else_target
|
|
24
|
+
dg_call("flow.route", "data-grout/flow.route", @client.send(:normalize_hash, opts).merge(params))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def request_approval(action:, details: nil, reason: nil, context: nil, **opts)
|
|
28
|
+
params = { "action" => action }.merge(@client.send(:normalize_hash, opts))
|
|
29
|
+
params["details"] = details if details
|
|
30
|
+
params["reason"] = reason if reason
|
|
31
|
+
params["context"] = context if context
|
|
32
|
+
dg_call("flow.request-approval", "data-grout/flow.request-approval", params)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def request_feedback(missing_fields:, reason:, current_data: nil, suggestions: nil, context: nil, **opts)
|
|
36
|
+
params = { "missing_fields" => missing_fields, "reason" => reason }.merge(@client.send(:normalize_hash, opts))
|
|
37
|
+
params["current_data"] = current_data if current_data
|
|
38
|
+
params["suggestions"] = suggestions if suggestions
|
|
39
|
+
params["context"] = context if context
|
|
40
|
+
dg_call("flow.request-feedback", "data-grout/flow.request-feedback", params)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def history(limit: 50, offset: 0, status: nil, refractions_only: false, **opts)
|
|
44
|
+
params = { "limit" => limit, "offset" => offset, "refractions_only" => refractions_only }.merge(@client.send(:normalize_hash, opts))
|
|
45
|
+
params["status"] = status if status
|
|
46
|
+
dg_call("inspect.execution-history", "data-grout/inspect.execution-history", params)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def details(execution_id:)
|
|
50
|
+
params = { "execution_id" => execution_id }
|
|
51
|
+
dg_call("inspect.execution-details", "data-grout/inspect.execution-details", params)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def dg_call(label, tool_name, params)
|
|
57
|
+
@client.send(:warn_if_not_dg, label)
|
|
58
|
+
@client.send(:ensure_initialized!)
|
|
59
|
+
@client.send(:call_dg_tool, tool_name, params)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class LogicNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def remember(statement: nil, facts: nil, tag: nil)
|
|
10
|
+
raise ArgumentError, "must provide statement or facts" unless statement || facts
|
|
11
|
+
|
|
12
|
+
params = {}
|
|
13
|
+
params["statement"] = statement if statement
|
|
14
|
+
params["facts"] = facts if facts
|
|
15
|
+
params["tag"] = tag if tag
|
|
16
|
+
dg_call("logic.remember", params)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def query(question: nil, patterns: nil, limit: nil)
|
|
20
|
+
raise ArgumentError, "must provide question or patterns" unless question || patterns
|
|
21
|
+
|
|
22
|
+
params = {}
|
|
23
|
+
params["question"] = question if question
|
|
24
|
+
params["patterns"] = patterns if patterns
|
|
25
|
+
params["limit"] = limit if limit
|
|
26
|
+
dg_call("logic.query", params)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def forget(handles: nil, pattern: nil)
|
|
30
|
+
raise ArgumentError, "must provide handles or pattern" unless handles || pattern
|
|
31
|
+
|
|
32
|
+
params = {}
|
|
33
|
+
params["handles"] = handles if handles
|
|
34
|
+
params["pattern"] = pattern if pattern
|
|
35
|
+
dg_call("logic.forget", params)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def constrain(rule:, tag: nil)
|
|
39
|
+
params = { "rule" => rule }
|
|
40
|
+
params["tag"] = tag if tag
|
|
41
|
+
dg_call("logic.constrain", params)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reflect(entity: nil, summary_only: false)
|
|
45
|
+
params = { "summary_only" => summary_only }
|
|
46
|
+
params["entity"] = entity if entity
|
|
47
|
+
dg_call("logic.reflect", params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def hydrate(params = {})
|
|
51
|
+
dg_call("logic.hydrate", params)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def export_cell(params = {})
|
|
55
|
+
dg_call("logic.export", params)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def import_cell(params = {})
|
|
59
|
+
dg_call("logic.import", params)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def tabulate(params = {})
|
|
63
|
+
dg_call("logic.tabulate", params)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def worlds(params = {})
|
|
67
|
+
dg_call("logic.worlds", params)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def dg_call(short_name, params)
|
|
73
|
+
@client.send(:warn_if_not_dg, short_name)
|
|
74
|
+
@client.send(:ensure_initialized!)
|
|
75
|
+
@client.send(:call_dg_tool, "data-grout/#{short_name}", params)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class PrismNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def refract(goal:, payload:, **opts)
|
|
10
|
+
params = { "goal" => goal, "payload" => payload }
|
|
11
|
+
params["verbose"] = opts[:verbose] if opts.key?(:verbose)
|
|
12
|
+
params["chart"] = opts[:chart] if opts.key?(:chart)
|
|
13
|
+
dg_call("prism.refract", params)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def chart(goal:, payload:, **opts)
|
|
17
|
+
params = { "goal" => goal, "payload" => payload }
|
|
18
|
+
params["format"] = opts[:format] if opts[:format]
|
|
19
|
+
params["chart_type"] = opts[:chart_type] if opts[:chart_type]
|
|
20
|
+
params["title"] = opts[:title] if opts[:title]
|
|
21
|
+
params["x_label"] = opts[:x_label] if opts[:x_label]
|
|
22
|
+
params["y_label"] = opts[:y_label] if opts[:y_label]
|
|
23
|
+
params["width"] = opts[:width] if opts[:width]
|
|
24
|
+
params["height"] = opts[:height] if opts[:height]
|
|
25
|
+
dg_call("prism.chart", params)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def render(goal:, payload: nil, format: "markdown", sections: nil, **opts)
|
|
29
|
+
params = { "goal" => goal, "format" => format }.merge(@client.send(:normalize_hash, opts))
|
|
30
|
+
params["payload"] = payload if payload
|
|
31
|
+
params["sections"] = sections if sections
|
|
32
|
+
dg_call("prism.render", params)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def export(content:, format:, style: nil, metadata: nil, **opts)
|
|
36
|
+
params = { "content" => content, "format" => format }.merge(@client.send(:normalize_hash, opts))
|
|
37
|
+
params["style"] = style if style
|
|
38
|
+
params["metadata"] = metadata if metadata
|
|
39
|
+
dg_call("prism.export", params)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def focus(data:, source_type:, target_type:, source_annotations: nil, target_annotations: nil, context: nil)
|
|
43
|
+
params = { "data" => data, "source_type" => source_type, "target_type" => target_type }
|
|
44
|
+
params["source_annotations"] = source_annotations if source_annotations
|
|
45
|
+
params["target_annotations"] = target_annotations if target_annotations
|
|
46
|
+
params["context"] = context if context
|
|
47
|
+
dg_call("prism.focus", params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def dg_call(short_name, params)
|
|
53
|
+
@client.send(:warn_if_not_dg, short_name)
|
|
54
|
+
@client.send(:ensure_initialized!)
|
|
55
|
+
@client.send(:call_dg_tool, "data-grout/#{short_name}", params)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatagroutConduit
|
|
4
|
+
class WardenNamespace
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def canary(params = {})
|
|
10
|
+
dg_call("warden.canary", params)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def verify_intent(params = {})
|
|
14
|
+
dg_call("warden.intent", params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def adjudicate(params = {})
|
|
18
|
+
dg_call("warden.adjudicate", params)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def ensemble(params = {})
|
|
22
|
+
dg_call("warden.ensemble", params)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def dg_call(short_name, params)
|
|
28
|
+
@client.send(:warn_if_not_dg, short_name)
|
|
29
|
+
@client.send(:ensure_initialized!)
|
|
30
|
+
@client.send(:call_dg_tool, "data-grout/#{short_name}", params)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -90,6 +90,62 @@ module DatagroutConduit
|
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Extract DataGrout metadata from a tool-call result hash.
|
|
94
|
+
#
|
|
95
|
+
# Checks sources in priority order:
|
|
96
|
+
# 1. +result["_meta"]["datagrout"]+ — rich format
|
|
97
|
+
# 2. +result["_datagrout"]+ / +result["_meta"]+ — legacy
|
|
98
|
+
# 3. +result["_dg"]+ — compact inline (synthesized)
|
|
99
|
+
#
|
|
100
|
+
# Returns +nil+ when no metadata is found.
|
|
101
|
+
def self.extract_meta(result)
|
|
102
|
+
return nil unless result.is_a?(Hash)
|
|
103
|
+
|
|
104
|
+
# 1. Rich: _meta.datagrout (string or symbol keys)
|
|
105
|
+
rich = result.dig("_meta", "datagrout") || result.dig(:_meta, :datagrout)
|
|
106
|
+
if rich.is_a?(Hash) && (rich["receipt"] || rich[:receipt])
|
|
107
|
+
return ToolMeta.from_hash(rich.transform_keys(&:to_s))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# 2. Legacy: _datagrout or bare _meta (string or symbol keys)
|
|
111
|
+
%w[_datagrout _meta].each do |key|
|
|
112
|
+
legacy = result[key] || result[key.to_sym]
|
|
113
|
+
if legacy.is_a?(Hash) && (legacy["receipt"] || legacy[:receipt])
|
|
114
|
+
return ToolMeta.from_hash(legacy.transform_keys(&:to_s))
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# 3. Compact: _dg (string or symbol keys)
|
|
119
|
+
dg = result["_dg"] || result[:_dg]
|
|
120
|
+
if dg.is_a?(Hash)
|
|
121
|
+
credits = dg["credits"] || {}
|
|
122
|
+
breakdown = {}
|
|
123
|
+
breakdown["premium"] = credits["premium"] if credits.key?("premium")
|
|
124
|
+
breakdown["llm"] = credits["llm"] if credits.key?("llm")
|
|
125
|
+
|
|
126
|
+
return ToolMeta.new(
|
|
127
|
+
receipt: Receipt.new(
|
|
128
|
+
receipt_id: nil,
|
|
129
|
+
timestamp: nil,
|
|
130
|
+
estimated_credits: (credits["estimated"] || 0.0).to_f,
|
|
131
|
+
actual_credits: (credits["charged"] || 0.0).to_f,
|
|
132
|
+
net_credits: (credits["charged"] || 0.0).to_f,
|
|
133
|
+
savings: 0.0,
|
|
134
|
+
savings_bonus: 0.0,
|
|
135
|
+
balance_after: credits["remaining"]&.to_f,
|
|
136
|
+
breakdown: breakdown,
|
|
137
|
+
byok: Byok.new(enabled: false, discount_applied: 0.0, discount_rate: 0.0)
|
|
138
|
+
),
|
|
139
|
+
credit_estimate: nil
|
|
140
|
+
)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
warn "[conduit] No DataGrout metadata found in tool result. " \
|
|
144
|
+
"Cost tracking data is unavailable. Enable 'Include DG Inline' " \
|
|
145
|
+
"or 'Include DataGrout Metadata' in your server settings."
|
|
146
|
+
nil
|
|
147
|
+
end
|
|
148
|
+
|
|
93
149
|
DiscoveredTool = Struct.new(:name, :description, :input_schema, :score, :integration, :server, keyword_init: true) do
|
|
94
150
|
def self.from_hash(hash)
|
|
95
151
|
hash = hash.transform_keys(&:to_s)
|
data/lib/datagrout_conduit.rb
CHANGED
|
@@ -11,6 +11,12 @@ require_relative "datagrout_conduit/registration"
|
|
|
11
11
|
require_relative "datagrout_conduit/transport/base"
|
|
12
12
|
require_relative "datagrout_conduit/transport/mcp"
|
|
13
13
|
require_relative "datagrout_conduit/transport/jsonrpc"
|
|
14
|
+
require_relative "datagrout_conduit/namespaces/prism"
|
|
15
|
+
require_relative "datagrout_conduit/namespaces/logic"
|
|
16
|
+
require_relative "datagrout_conduit/namespaces/warden"
|
|
17
|
+
require_relative "datagrout_conduit/namespaces/deliverables"
|
|
18
|
+
require_relative "datagrout_conduit/namespaces/ephemerals"
|
|
19
|
+
require_relative "datagrout_conduit/namespaces/flow"
|
|
14
20
|
require_relative "datagrout_conduit/client"
|
|
15
21
|
|
|
16
22
|
module DatagroutConduit
|
|
@@ -28,26 +34,4 @@ module DatagroutConduit
|
|
|
28
34
|
ENV.key?("CONDUIT_IS_DG")
|
|
29
35
|
end
|
|
30
36
|
|
|
31
|
-
# Extract the DataGrout metadata block from a tool-call result.
|
|
32
|
-
#
|
|
33
|
-
# Checks +_meta.datagrout+ first (current format), then +_datagrout+,
|
|
34
|
-
# then falls back to +_meta+ for backward compatibility with older
|
|
35
|
-
# gateway responses.
|
|
36
|
-
#
|
|
37
|
-
# Returns nil when the result contains neither key (e.g. upstream servers
|
|
38
|
-
# that don't go through the DG gateway).
|
|
39
|
-
#
|
|
40
|
-
# meta = DatagroutConduit.extract_meta(result)
|
|
41
|
-
# meta.receipt.net_credits #=> 1.5
|
|
42
|
-
# meta.receipt.receipt_id #=> "rcp_abc123"
|
|
43
|
-
def self.extract_meta(result)
|
|
44
|
-
return nil unless result.is_a?(Hash)
|
|
45
|
-
|
|
46
|
-
raw = result.dig("_meta", "datagrout") || result.dig(:_meta, :datagrout) ||
|
|
47
|
-
result["_datagrout"] || result[:_datagrout] ||
|
|
48
|
-
result["_meta"] || result[:_meta]
|
|
49
|
-
return nil if raw.nil?
|
|
50
|
-
|
|
51
|
-
ToolMeta.from_hash(raw)
|
|
52
|
-
end
|
|
53
37
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: datagrout-conduit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- DataGrout
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -108,6 +108,12 @@ files:
|
|
|
108
108
|
- lib/datagrout_conduit/client.rb
|
|
109
109
|
- lib/datagrout_conduit/errors.rb
|
|
110
110
|
- lib/datagrout_conduit/identity.rb
|
|
111
|
+
- lib/datagrout_conduit/namespaces/deliverables.rb
|
|
112
|
+
- lib/datagrout_conduit/namespaces/ephemerals.rb
|
|
113
|
+
- lib/datagrout_conduit/namespaces/flow.rb
|
|
114
|
+
- lib/datagrout_conduit/namespaces/logic.rb
|
|
115
|
+
- lib/datagrout_conduit/namespaces/prism.rb
|
|
116
|
+
- lib/datagrout_conduit/namespaces/warden.rb
|
|
111
117
|
- lib/datagrout_conduit/oauth.rb
|
|
112
118
|
- lib/datagrout_conduit/registration.rb
|
|
113
119
|
- lib/datagrout_conduit/transport/base.rb
|