sai-sdk 0.1.0 → 0.2.1

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: b354a76d6581874f8fb42a95a2c08e493e35caeff8719badd6ea1b3bcc2833f7
4
- data.tar.gz: '079cf8b51f0604c50904643c772085e8a63873afa437a56286140d27273a1000'
3
+ metadata.gz: d8a0a6c688d54e3719db71fb3ffa74980efe963c6a3d5e3926861286383e97cc
4
+ data.tar.gz: 4ff11be47d9fdc707e24c1444b97711cceccceab0b89c3b56693fabad967fa29
5
5
  SHA512:
6
- metadata.gz: 1b7a1c2cb4783e1b4ef6a9add4d445e6dda1b6d37794c2cb23f7b95f57026deebcbf689a0dbb12772cdda9ea3427a73bf444edf1dab60b42d22c020a22859b14
7
- data.tar.gz: f568d3063e62375cbc35f6f0eb2dabdcf5a173f77ab70b1f291326e39a95d640a67d8464a7a12a131e2ebc706bb7c71a8fc08366549e2752d1abc767f89effe2
6
+ metadata.gz: 2773ec415819ea241e55c31d2e97009b7dd432571f8c23bce1d82ea26c23c2e6efe4119f2dc310670bf2e33ac9fa48866f2257e4be9231fc64c5d99d3e21444a
7
+ data.tar.gz: 5e516f46a6f4558bc98f02169faec4a0c74501718fb42d4143c5df3475f2fba1d76e178cc2b5a73a1c1e13956a7b0616b5db1789ec70d84726f585cc231f3a9e
data/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Ruby SDK for the [Sai API](https://platform.simular.ai/documentation). Hand desktop work to Sai on a
4
4
  computer (a Sai cloud computer, or your own PC with the Sai app) and get the answer back, or drive a
5
- cloud computer yourself.
5
+ computer yourself.
6
6
 
7
- Status: **alpha (0.1), unreleased**. The surface may still change before 1.0. It matches the
7
+ Status: **alpha (0.1)**. The surface may still change before 1.0. It matches the
8
8
  [Python SDK](../python/README.md) and the [TypeScript SDK](../typescript/README.md) method for method.
9
9
 
10
10
  | Layer | What it is | Status |
11
11
  | -------------- | --------------------------------------------- | ---------------- |
12
12
  | `sai.sessions` | A conversation with Sai on one computer | available |
13
- | `sai.control` | Drive a cloud computer directly with Simulang | research preview |
13
+ | `sai.control` | Drive a computer (cloud or own) with Simulang | research preview |
14
14
  | `sai.turns` | A turn's record: typed output, evidence | available |
15
15
 
16
16
  ## Install
@@ -142,8 +142,8 @@ end
142
142
  ## Drive a computer yourself
143
143
 
144
144
  Direct control runs [Simulang](https://platform.simular.ai/documentation/concepts/direct-control)
145
- blocks on a cloud computer. With a block, `open` closes the lease when the block ends; while it is
146
- open, Sai's own tasks on that computer wait.
145
+ blocks on one of your computers, cloud or your own. With a block, `open` closes the lease when the
146
+ block ends; while it is open, Sai's own tasks on that computer wait.
147
147
 
148
148
  ```ruby
149
149
  sai.control.open(machine: pc) do |lease|
@@ -180,6 +180,8 @@ done = sai.learn.wait(job) # timeout: to stop waiting
180
180
  run = sai.learn.rollout(job, 1, 1)
181
181
  ```
182
182
 
183
+ `done.agent_run_end` says how the job's agent run ended when it gave no answer: `time_limit` (still converted), or `needs_input` or the turn's `reason_code` such as `agent_error`, which stop the job (`agent_failed`) before it writes code.
184
+
183
185
  ## Run Sai for your customers
184
186
 
185
187
  ```ruby
@@ -193,10 +195,16 @@ clinic = org.tenants.client(tenant) # acts as the Tenant; renews its token
193
195
  clinic.sessions.create(machine: machine.id).run("Open the calendar and read today's appointments")
194
196
 
195
197
  org.tenants.update(tenant, cloud_machine_limit: nil) # nil removes the cap; leaving it out changes nothing
198
+ org.tenants.update(tenant, own_computer_access: true) # learn and control on its enrolled machines
196
199
  usage = org.usage.get(granularity: "month", from: "2026-10", to: "2026-10")
197
200
  page = org.usage.sessions(tenant, from: "2026-10-01", to: "2026-10-31")
198
201
  ```
199
202
 
203
+ A machine from `tenant_machines` or `machines.list` has `capabilities`: what stands in the way of
204
+ driving it (`can_see`, `can_use_accessibility`, `can_control`, each nil when nothing was found in the
205
+ way, else a sentence saying what to fix), or nil when there is no answer yet (the machine has not
206
+ reported, or its check failed). See [machine capabilities](https://platform.simular.ai/documentation/organisations/tenant-machines#machine-capabilities).
207
+
200
208
  `usage.sessions` pages what each of a Tenant's sessions spent on AI calls, for UTC days `from:` to `to:`
201
209
  (at most 93). A page can be empty and still have a `next_cursor`: keep paging until it is `nil`.
202
210
 
data/lib/sai/control.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "json"
4
4
 
5
5
  module Sai
6
- # Direct control: drive a cloud computer with Simulang. No agent. A lease on the machine: at
6
+ # Direct control: drive a computer with Simulang. No agent. A lease on the machine: at
7
7
  # most one per machine. Research preview; model calls the code makes are billed as usual.
8
8
  class Control
9
9
  OPEN_TIMEOUT = 240
@@ -13,7 +13,7 @@ module Sai
13
13
  @http = http
14
14
  end
15
15
 
16
- # Take a cloud computer (a Machine or its id). Returns once the lease holds it, up to about
16
+ # Take a computer (a Machine or its id). Returns once the lease holds it, up to about
17
17
  # three minutes when a Sai task holds it or it has to start. Sai's tasks on that computer wait
18
18
  # until the lease is closed. With a block, yields the lease, closes it after, and returns the
19
19
  # block's value.
@@ -36,7 +36,7 @@ module Sai
36
36
  # The result of ControlLease#shell.
37
37
  ShellResult = Struct.new(:stdout, :stderr, :exit_code, :timed_out, keyword_init: true)
38
38
 
39
- # A lease on a cloud computer. Close it when done: Sai's tasks on that computer wait until then.
39
+ # A lease on a computer. Close it when done: Sai's tasks on that computer wait until then.
40
40
  class ControlLease
41
41
  attr_reader :machine_id, :idle_timeout_sec
42
42
 
data/lib/sai/tenants.rb CHANGED
@@ -45,15 +45,19 @@ module Sai
45
45
  # Sends only what is given. +metadata+ replaces the whole map. +status: "disabled"+ stops the
46
46
  # Tenant's tokens and machines; +"active"+ brings it back. +cloud_machine_limit+ (0 to 1000)
47
47
  # caps the Tenant's cloud machines, and +cloud_machine_limit: nil+ removes the cap.
48
- # +residential_proxy+ has no effect yet. Only the Organisation Key or an owner may set these two.
48
+ # +residential_proxy+ has no effect yet. +own_computer_access+ lets the Tenant's learn jobs and
49
+ # direct control run code on its enrolled machines (default off). Only the Organisation Key or
50
+ # an owner may set these three.
49
51
  # @return [Tenant]
50
- def update(tenant, name: nil, metadata: nil, status: nil, cloud_machine_limit: UNSET, residential_proxy: nil)
52
+ def update(tenant, name: nil, metadata: nil, status: nil, cloud_machine_limit: UNSET, residential_proxy: nil,
53
+ own_computer_access: nil)
51
54
  body = {}
52
55
  body["name"] = name unless name.nil?
53
56
  body["metadata"] = metadata unless metadata.nil?
54
57
  body["status"] = status unless status.nil?
55
58
  body["cloudMachineLimit"] = cloud_machine_limit unless cloud_machine_limit.equal?(UNSET)
56
59
  body["residentialProxy"] = residential_proxy unless residential_proxy.nil?
60
+ body["ownComputerAccess"] = own_computer_access unless own_computer_access.nil?
57
61
  Tenant.parse(Parse.obj(@http.json("PATCH", self.class.path(tenant), json: body)))
58
62
  end
59
63
 
data/lib/sai/types.rb CHANGED
@@ -105,10 +105,32 @@ module Sai
105
105
  end
106
106
  end
107
107
 
108
+ # What stands in the way of driving a machine, as the Sai runtime on it last reported. Each field
109
+ # is nil when nothing was found in the way (a check that cannot tell counts as fine), else a
110
+ # sentence for the user saying what is missing and how to fix it:
111
+ # +can_see+ (screenshots show what is on screen), +can_use_accessibility+ (other apps'
112
+ # accessibility trees can be read and acted on), +can_control+ (mouse, keyboard and element
113
+ # actions reach other apps; needs what +can_use_accessibility+ needs). See
114
+ # https://platform.simular.ai/documentation/organisations/tenant-machines#machine-capabilities.
115
+ MachineCapabilities = Struct.new(:can_see, :can_use_accessibility, :can_control,
116
+ keyword_init: true) do
117
+ # nil unless +v+ is an object whose three answers are each a string or nil.
118
+ def self.parse(v)
119
+ return nil unless v.is_a?(Hash)
120
+ return nil unless %w[canSee canUseAccessibility canControl].all? { |k| v.key?(k) && (v[k].nil? || v[k].is_a?(String)) }
121
+
122
+ new(can_see: v["canSee"], can_use_accessibility: v["canUseAccessibility"],
123
+ can_control: v["canControl"])
124
+ end
125
+ end
126
+
108
127
  # A computer Sai works on. +kind+ is +cloud+ or +own+; +state+ is +running+, +starting+,
109
128
  # +asleep+, +creating+ or +unknown+ (nil on servers that do not send it). +status+ is deprecated.
110
- Machine = Struct.new(:id, :name, :kind, :online, :state, :status, :can_wake, :os, :raw,
111
- keyword_init: true) do
129
+ # +capabilities+ is what stands in the way of driving it; nil when there is no answer yet: the
130
+ # machine has not reported (its runtime is too old to, or has not yet), or its check failed; also
131
+ # from older servers.
132
+ Machine = Struct.new(:id, :name, :kind, :online, :state, :status, :can_wake, :os, :capabilities,
133
+ :raw, keyword_init: true) do
112
134
  def self.parse(d)
113
135
  new(
114
136
  id: Parse.str(d["machineId"]) || "",
@@ -119,6 +141,7 @@ module Sai
119
141
  status: Parse.str(d["status"]),
120
142
  can_wake: Parse.truthy(d["canWake"]),
121
143
  os: Parse.str(d["os"]),
144
+ capabilities: MachineCapabilities.parse(d["capabilities"]),
122
145
  raw: d
123
146
  )
124
147
  end
@@ -417,9 +440,12 @@ module Sai
417
440
 
418
441
  # The result of +sai.learn.create+: Simulang code made from recorded turns or an agent run, a
419
442
  # repair of code you sent, or a learn job. Run the code with +lease.run(learned, inputs)+.
420
- # +status+ is +succeeded+, +failed+, +running+ or +stopped+. Research preview.
443
+ # +status+ is +succeeded+, +failed+, +running+ or +stopped+. +agent_run_end+ is how a job's agent
444
+ # run ended when it gave no answer (nil when it answered): +time_limit+ (still converted),
445
+ # +needs_input+ or the turn's +reason_code+, e.g. +agent_error+; every end but +time_limit+ stops
446
+ # the job (+agent_failed+) before conversion. Research preview.
421
447
  LearnResult = Struct.new(:id, :mode, :status, :stop_reason, :message, :test_result, :progress,
422
- :agent_turn_id, :agent_run_reset, :agent_judgement, :version, :iterations,
448
+ :agent_turn_id, :agent_run_end, :agent_run_reset, :agent_judgement, :version, :iterations,
423
449
  :title, :template, :parameters, :code, :output_schema, :validation,
424
450
  :changes, :source_turns, :usage, :error, :replayed, :raw,
425
451
  keyword_init: true) do
@@ -447,6 +473,7 @@ module Sai
447
473
  rollout: Parse.num_or_nil(p["rollout"])
448
474
  ),
449
475
  agent_turn_id: Parse.str(d["agentTurnId"]),
476
+ agent_run_end: Parse.str(d["agentRunEnd"]),
450
477
  agent_run_reset: LearnReset.parse(d["agentRunReset"]),
451
478
  agent_judgement: aj && AgentJudgement.new(
452
479
  judgement_id: Parse.str(aj["judgementId"]) || "",
@@ -545,10 +572,11 @@ module Sai
545
572
  end
546
573
 
547
574
  # One of your customers under an Organisation. Times are Unix milliseconds;
548
- # +cloud_machine_limit+ nil means no limit.
575
+ # +cloud_machine_limit+ nil means no limit. +own_computer_access+: whether learn jobs and direct
576
+ # control may run code on its enrolled machines; nil from +list+ and from older servers.
549
577
  Tenant = Struct.new(:id, :name, :external_id, :metadata, :status, :created_at, :disabled_at,
550
578
  :machine_count, :cloud_machine_limit, :residential_proxy, :cloud_machine_count,
551
- :raw, keyword_init: true) do
579
+ :own_computer_access, :raw, keyword_init: true) do
552
580
  def self.parse(d)
553
581
  new(
554
582
  id: Parse.str(d["tenantId"]) || "",
@@ -562,6 +590,7 @@ module Sai
562
590
  cloud_machine_limit: Parse.num_or_nil(d["cloudMachineLimit"]),
563
591
  residential_proxy: [true, false].include?(d["residentialProxy"]) ? d["residentialProxy"] : nil,
564
592
  cloud_machine_count: Parse.num_or_nil(d["cloudMachineCount"]),
593
+ own_computer_access: [true, false].include?(d["ownComputerAccess"]) ? d["ownComputerAccess"] : nil,
565
594
  raw: d
566
595
  )
567
596
  end
@@ -572,9 +601,12 @@ module Sai
572
601
 
573
602
  # A Tenant's computer: enrolled, or a cloud machine Sai hosts. +kind+ is +enrolled+ or +cloud+;
574
603
  # +state+ is +online+/+offline+ (enrolled) or +provisioning+, +ready+, +starting+,
575
- # +hibernated+, +deleting+ or +failed+ (cloud).
604
+ # +hibernated+, +deleting+ or +failed+ (cloud). +capabilities+ is what stands in the way of
605
+ # driving it; nil when there is no answer yet: the machine has not reported (its runtime is too
606
+ # old to, or has not yet), or its check failed; also from older servers.
576
607
  TenantMachine = Struct.new(:id, :name, :platform, :status, :online, :last_seen, :runtime_version,
577
- :kind, :state, :machine_class, :created_at, :raw, keyword_init: true) do
608
+ :kind, :state, :machine_class, :created_at, :capabilities, :raw,
609
+ keyword_init: true) do
578
610
  def self.parse(d)
579
611
  # Servers before cloud machines send online and status and no kind or state.
580
612
  state = Parse.present(d["state"]) || (Parse.truthy(d["online"]) ? "online" : "offline")
@@ -590,6 +622,7 @@ module Sai
590
622
  state: state,
591
623
  machine_class: Parse.str(d["machineClass"]),
592
624
  created_at: Parse.num_or_nil(d["createdAt"]),
625
+ capabilities: MachineCapabilities.parse(d["capabilities"]),
593
626
  raw: d
594
627
  )
595
628
  end
data/lib/sai/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sai
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/sai.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # - +sai.sessions+: give Sai a task on a computer and get the answer back.
6
6
  # - +sai.learn+, +sai.judge+: turn recorded turns or a task into Simulang code, repair it, run,
7
7
  # judge and repair it on a machine, judge turns.
8
- # - +sai.control+: drive a cloud computer yourself with Simulang.
8
+ # - +sai.control+: drive a computer yourself with Simulang.
9
9
  # - +sai.machines+, +sai.models+, +sai.files+, +sai.account+, +sai.auth+.
10
10
  # - +sai.tenants+, +sai.tenant_machines+, +sai.usage+: your customers under an Organisation.
11
11
  module Sai
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sai-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simular, Inc.
@@ -10,7 +10,7 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Hand desktop work to Sai on a computer and get the answer back, or drive
13
- a cloud computer yourself.
13
+ a computer yourself.
14
14
  executables: []
15
15
  extensions: []
16
16
  extra_rdoc_files: []