@kortexya/reasoninglayer 0.21.0 → 0.22.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.
package/dist/index.cjs CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
  };
8
8
 
9
9
  // src/config.ts
10
- var SDK_VERSION = "0.21.0";
10
+ var SDK_VERSION = "0.22.1";
11
11
  function resolveConfig(config) {
12
12
  if (!config.baseUrl) {
13
13
  throw new Error("ClientConfig.baseUrl is required");
@@ -7390,6 +7390,54 @@ var Scheduling = class {
7390
7390
  constructor(http) {
7391
7391
  this.http = http;
7392
7392
  }
7393
+ /**
7394
+ * No description
7395
+ *
7396
+ * @tags scheduling
7397
+ * @name AddPin
7398
+ * @summary `POST /api/v1/scheduling/problems/{id}/pins`
7399
+ * @request POST:/api/v1/scheduling/problems/{problem_id}/pins
7400
+ */
7401
+ addPin = (problemId, data, params = {}) => this.http.request({
7402
+ path: `/api/v1/scheduling/problems/${problemId}/pins`,
7403
+ method: "POST",
7404
+ body: data,
7405
+ type: "application/json" /* Json */,
7406
+ format: "json",
7407
+ ...params
7408
+ });
7409
+ /**
7410
+ * No description
7411
+ *
7412
+ * @tags scheduling
7413
+ * @name AddPreference
7414
+ * @summary `POST /api/v1/scheduling/problems/{id}/preferences`
7415
+ * @request POST:/api/v1/scheduling/problems/{problem_id}/preferences
7416
+ */
7417
+ addPreference = (problemId, data, params = {}) => this.http.request({
7418
+ path: `/api/v1/scheduling/problems/${problemId}/preferences`,
7419
+ method: "POST",
7420
+ body: data,
7421
+ type: "application/json" /* Json */,
7422
+ format: "json",
7423
+ ...params
7424
+ });
7425
+ /**
7426
+ * @description Freeze the inline scheduling inputs into a `scheduling.problem` Ψ-term snapshot stored in the application-layer scheduling store, and return its ID. The endpoint does NOT solve — call `POST /api/v1/scheduling/problems/{id}/solve` to compute the optimum, then `GET /api/v1/scheduling/problems/{id}/assignments` to retrieve the per-cell trichotomy. Snapshot mode: subsequent re-solves read only the snapshot, not any source terms in the KB. This keeps the optimum reproducible and auditable from the moment the problem is created.
7427
+ *
7428
+ * @tags scheduling
7429
+ * @name CreateProblem
7430
+ * @summary `POST /api/v1/scheduling/problems`
7431
+ * @request POST:/api/v1/scheduling/problems
7432
+ */
7433
+ createProblem = (data, params = {}) => this.http.request({
7434
+ path: `/api/v1/scheduling/problems`,
7435
+ method: "POST",
7436
+ body: data,
7437
+ type: "application/json" /* Json */,
7438
+ format: "json",
7439
+ ...params
7440
+ });
7393
7441
  /**
7394
7442
  * @description Classify every `(agent, day, shift)` cell in the input grid as confirmed-true, confirmed-false, or free, and list the role(s) each cell could cover. Input validation errors (duplicate agent IDs, out-of-range pins, role minima exceeding total demand, pin role the agent doesn't have, pin on a multi-role agent where the role is ambiguous, etc.) return HTTP 400. Infeasibility of a well-formed problem is a valid answer and returns HTTP 200 with `status = "infeasible"` and an empty `assignments` list.
7395
7443
  *
@@ -7407,7 +7455,35 @@ var Scheduling = class {
7407
7455
  ...params
7408
7456
  });
7409
7457
  /**
7410
- * @description Same hard constraints as `/scheduling/feasibility` plus a list of soft `preferences` (each a per-cell score added to the optimizer's objective). Returns the per-cell trichotomy across the space of **optimal** schedules, plus `total_score` (sum of preference scores at chosen cells in the optimum). `confirmed_true` / `confirmed_false` here are stronger than in `/feasibility`: they hold across every optimum, not every feasible schedule. Cells with status `free` indicate ties — multiple optima exist and the cell varies between them. Preferences targeting cells that are already pinned, blocked by a day-off, restricted-to-shift, or otherwise structurally fixed are silently ignored — those cells are not the optimizer's choice to make.
7458
+ * No description
7459
+ *
7460
+ * @tags scheduling
7461
+ * @name GetProblem
7462
+ * @summary `GET /api/v1/scheduling/problems/{id}` — read the current state.
7463
+ * @request GET:/api/v1/scheduling/problems/{problem_id}
7464
+ */
7465
+ getProblem = (problemId, params = {}) => this.http.request({
7466
+ path: `/api/v1/scheduling/problems/${problemId}`,
7467
+ method: "GET",
7468
+ format: "json",
7469
+ ...params
7470
+ });
7471
+ /**
7472
+ * @description Retrieve the derived `scheduling.assignment` Ψ-terms produced by the most recent solve. Returns an empty list when the problem has never been solved, or when the problem ID isn't known for this tenant. Includes `free` cells (per the materialise decision) so consumers can residuate on them.
7473
+ *
7474
+ * @tags scheduling
7475
+ * @name ListAssignments
7476
+ * @summary `GET /api/v1/scheduling/problems/{id}/assignments`
7477
+ * @request GET:/api/v1/scheduling/problems/{problem_id}/assignments
7478
+ */
7479
+ listAssignments = (problemId, params = {}) => this.http.request({
7480
+ path: `/api/v1/scheduling/problems/${problemId}/assignments`,
7481
+ method: "GET",
7482
+ format: "json",
7483
+ ...params
7484
+ });
7485
+ /**
7486
+ * @description Same hard constraints as `/scheduling/feasibility` plus a list of soft `preferences` (each a per-cell score added to the optimizer's objective). Returns the per-cell trichotomy across the space of **optimal** schedules, plus `total_score` (sum of preference scores at chosen cells in the optimum). `confirmed_true` / `confirmed_false` here are stronger than in `/feasibility`: they hold across every optimum, not every feasible schedule. Cells with status `free` indicate ties — multiple optima exist and the cell varies between them. Preferences targeting structurally infeasible cells (agent has a day-off on the day, is restricted to a different shift, or otherwise cannot occupy the slot) are silently ignored — the preference cannot fire when the agent cannot be there. Preferences targeting **pinned** cells DO contribute to `total_score`: pins force the agent into the cell, so the preference is realised by the chosen schedule.
7411
7487
  *
7412
7488
  * @tags scheduling
7413
7489
  * @name Optimize
@@ -7422,6 +7498,46 @@ var Scheduling = class {
7422
7498
  format: "json",
7423
7499
  ...params
7424
7500
  });
7501
+ /**
7502
+ * No description
7503
+ *
7504
+ * @tags scheduling
7505
+ * @name RemovePin
7506
+ * @summary `DELETE /api/v1/scheduling/problems/{id}/pins/{pin_id}`
7507
+ * @request DELETE:/api/v1/scheduling/problems/{problem_id}/pins/{pin_id}
7508
+ */
7509
+ removePin = (problemId, pinId, params = {}) => this.http.request({
7510
+ path: `/api/v1/scheduling/problems/${problemId}/pins/${pinId}`,
7511
+ method: "DELETE",
7512
+ ...params
7513
+ });
7514
+ /**
7515
+ * No description
7516
+ *
7517
+ * @tags scheduling
7518
+ * @name RemovePreference
7519
+ * @summary `DELETE /api/v1/scheduling/problems/{id}/preferences/{preference_id}`
7520
+ * @request DELETE:/api/v1/scheduling/problems/{problem_id}/preferences/{preference_id}
7521
+ */
7522
+ removePreference = (problemId, preferenceId, params = {}) => this.http.request({
7523
+ path: `/api/v1/scheduling/problems/${problemId}/preferences/${preferenceId}`,
7524
+ method: "DELETE",
7525
+ ...params
7526
+ });
7527
+ /**
7528
+ * @description Re-solve the stored snapshot: project it back into a domain `SchedulingProblem`, run the optimizer, and lift the per-cell trichotomy into `scheduling.assignment` Ψ-terms (idempotent — previous derived assignments for this problem are replaced). Returns only `status` and `total_score`; fetch the per-cell trichotomy via `/assignments`.
7529
+ *
7530
+ * @tags scheduling
7531
+ * @name SolveProblem
7532
+ * @summary `POST /api/v1/scheduling/problems/{id}/solve`
7533
+ * @request POST:/api/v1/scheduling/problems/{problem_id}/solve
7534
+ */
7535
+ solveProblem = (problemId, params = {}) => this.http.request({
7536
+ path: `/api/v1/scheduling/problems/${problemId}/solve`,
7537
+ method: "POST",
7538
+ format: "json",
7539
+ ...params
7540
+ });
7425
7541
  };
7426
7542
 
7427
7543
  // src/api-spec/generated/Admin.ts
@@ -20581,6 +20697,122 @@ function SchedulingOptimizeResponseFromApiToFront(dto) {
20581
20697
  assignments: dto.assignments.map(AssignmentFromApiToFront)
20582
20698
  };
20583
20699
  }
20700
+ function CreateSchedulingProblemRequestFromFrontToApi(request) {
20701
+ const hasInline = request.agents !== void 0;
20702
+ const hasRefs = request.agentIds !== void 0;
20703
+ if (hasInline && hasRefs) {
20704
+ throw new Error(
20705
+ "CreateSchedulingProblemRequest: supply exactly one of `agents` (inline) or `agentIds` (TermId refs), not both"
20706
+ );
20707
+ }
20708
+ if (!hasInline && !hasRefs) {
20709
+ throw new Error(
20710
+ "CreateSchedulingProblemRequest: must supply either `agents` (inline) or `agentIds` (TermId refs)"
20711
+ );
20712
+ }
20713
+ const dto = {
20714
+ days: request.days,
20715
+ shifts_per_day: request.shiftsPerDay,
20716
+ demands: request.demands.map(ShiftDemandFromFrontToApi)
20717
+ };
20718
+ if (request.agents !== void 0) {
20719
+ dto.agents = request.agents.map(AgentSpecFromFrontToApi);
20720
+ }
20721
+ if (request.agentIds !== void 0) {
20722
+ dto.agent_ids = request.agentIds;
20723
+ }
20724
+ if (request.pins !== void 0) {
20725
+ dto.pins = request.pins.map(PinFromFrontToApi);
20726
+ }
20727
+ if (request.preferences !== void 0) {
20728
+ dto.preferences = request.preferences.map(PreferenceFromFrontToApi);
20729
+ }
20730
+ return dto;
20731
+ }
20732
+ function CreateSchedulingProblemResponseFromApiToFront(dto) {
20733
+ return {
20734
+ problemId: dto.problem_id
20735
+ };
20736
+ }
20737
+ function SolveSchedulingProblemResponseFromApiToFront(dto) {
20738
+ return {
20739
+ status: dto.status,
20740
+ totalScore: dto.total_score
20741
+ };
20742
+ }
20743
+ function SchedulingAssignmentsResponseFromApiToFront(dto) {
20744
+ return {
20745
+ totalScore: dto.total_score,
20746
+ assignments: dto.assignments.map(AssignmentFromApiToFront)
20747
+ };
20748
+ }
20749
+ function AddPinRequestFromFrontToApi(request) {
20750
+ const dto = {
20751
+ agent_id: request.agentId,
20752
+ day: request.day,
20753
+ shift: request.shift
20754
+ };
20755
+ if (request.role !== void 0) {
20756
+ dto.role = request.role;
20757
+ }
20758
+ return dto;
20759
+ }
20760
+ function AddPinResponseFromApiToFront(dto) {
20761
+ return {
20762
+ pinId: dto.pin_id,
20763
+ version: dto.version
20764
+ };
20765
+ }
20766
+ function AddPreferenceRequestFromFrontToApi(request) {
20767
+ return {
20768
+ agent_id: request.agentId,
20769
+ day: request.day,
20770
+ shift: request.shift,
20771
+ score: request.score
20772
+ };
20773
+ }
20774
+ function AddPreferenceResponseFromApiToFront(dto) {
20775
+ return {
20776
+ preferenceId: dto.preference_id,
20777
+ version: dto.version
20778
+ };
20779
+ }
20780
+ function PinEntryFromApiToFront(dto) {
20781
+ const entry = {
20782
+ pinId: dto.pin_id,
20783
+ agentId: dto.agent_id,
20784
+ day: dto.day,
20785
+ shift: dto.shift
20786
+ };
20787
+ if (dto.role !== void 0 && dto.role !== null) {
20788
+ entry.role = dto.role;
20789
+ }
20790
+ return entry;
20791
+ }
20792
+ function PreferenceEntryFromApiToFront(dto) {
20793
+ return {
20794
+ preferenceId: dto.preference_id,
20795
+ agentId: dto.agent_id,
20796
+ day: dto.day,
20797
+ shift: dto.shift,
20798
+ score: dto.score
20799
+ };
20800
+ }
20801
+ function SchedulingProblemFromApiToFront(dto) {
20802
+ const problem = {
20803
+ problemId: dto.problem_id,
20804
+ days: dto.days,
20805
+ shiftsPerDay: dto.shifts_per_day,
20806
+ version: dto.version,
20807
+ pins: dto.pins.map(PinEntryFromApiToFront),
20808
+ preferences: dto.preferences.map(PreferenceEntryFromApiToFront),
20809
+ totalScore: dto.total_score
20810
+ };
20811
+ if (dto.latest_solve_status !== void 0 && dto.latest_solve_status !== null) {
20812
+ problem.latestSolveStatus = dto.latest_solve_status;
20813
+ }
20814
+ return problem;
20815
+ }
20584
20816
 
20585
20817
  // src/resources/scheduling.ts
20586
20818
  var SchedulingClient = class {
@@ -20675,6 +20907,159 @@ var SchedulingClient = class {
20675
20907
  );
20676
20908
  return SchedulingOptimizeResponseFromApiToFront(response.data);
20677
20909
  }
20910
+ // ── Snapshot-driven endpoints (POST /scheduling/problems/*) ───────
20911
+ /**
20912
+ * Freeze the inline scheduling inputs into a `scheduling.problem`
20913
+ * Ψ-term snapshot stored under the caller's tenant, and return the
20914
+ * snapshot's `problemId`. The endpoint does NOT solve — call
20915
+ * {@link SchedulingClient.solveProblem} afterwards to compute the
20916
+ * optimum, then {@link SchedulingClient.listAssignments} to fetch
20917
+ * the per-cell trichotomy.
20918
+ *
20919
+ * @param request - same inline shape as
20920
+ * {@link SchedulingClient.optimize}.
20921
+ * @returns the snapshot ID, useful for subsequent re-solves and
20922
+ * provenance lookups.
20923
+ * @throws HTTP 400 on malformed input (duplicate agent IDs,
20924
+ * ambiguous pin role, unknown pin or preference agent ID,
20925
+ * role minima exceeding total demand, etc.).
20926
+ *
20927
+ * @remarks
20928
+ * Re-solves read only the snapshot, so the optimum is reproducible
20929
+ * and auditable from the moment the problem is created. The
20930
+ * snapshot persists across solves — pin a problem once, re-solve
20931
+ * many times.
20932
+ *
20933
+ * @example
20934
+ * ```typescript
20935
+ * const { problemId } = await client.scheduling.createProblem({
20936
+ * agents: [{ id: 'alice', roles: ['icu'], maxAssignments: 3 }],
20937
+ * days: 7,
20938
+ * shiftsPerDay: 3,
20939
+ * demands: [{ day: 0, shift: 0, total: 1, roleMinimums: { icu: 1 } }],
20940
+ * preferences: [{ agentId: 'alice', day: 0, shift: 0, score: 5 }],
20941
+ * });
20942
+ * await client.scheduling.solveProblem(problemId);
20943
+ * const { totalScore, assignments } =
20944
+ * await client.scheduling.listAssignments(problemId);
20945
+ * ```
20946
+ */
20947
+ async createProblem(request) {
20948
+ const response = await this.api.createProblem(
20949
+ CreateSchedulingProblemRequestFromFrontToApi(request)
20950
+ );
20951
+ return CreateSchedulingProblemResponseFromApiToFront(response.data);
20952
+ }
20953
+ /**
20954
+ * Re-solve a previously-stored snapshot, lift the per-cell
20955
+ * trichotomy into `scheduling.assignment` Ψ-terms (idempotent —
20956
+ * previously lifted assignments are replaced), and return the
20957
+ * optimum's `totalScore`.
20958
+ *
20959
+ * @param problemId - the ID returned by
20960
+ * {@link SchedulingClient.createProblem}.
20961
+ * @throws HTTP 404 when the problem doesn't exist for the caller's
20962
+ * tenant. HTTP 400 for malformed problem IDs.
20963
+ *
20964
+ * @remarks
20965
+ * Returns only `status` and `totalScore`; fetch the per-cell
20966
+ * trichotomy with {@link SchedulingClient.listAssignments}.
20967
+ * Re-running this method on the same `problemId` is safe — the
20968
+ * lifted assignment terms are replaced atomically.
20969
+ */
20970
+ async solveProblem(problemId) {
20971
+ const response = await this.api.solveProblem(problemId);
20972
+ return SolveSchedulingProblemResponseFromApiToFront(response.data);
20973
+ }
20974
+ /**
20975
+ * Retrieve the lifted `scheduling.assignment` Ψ-terms produced by
20976
+ * the most recent solve.
20977
+ *
20978
+ * @param problemId - the ID returned by
20979
+ * {@link SchedulingClient.createProblem}.
20980
+ * @throws HTTP 404 when the problem doesn't exist for the caller's
20981
+ * tenant. HTTP 400 for malformed problem IDs.
20982
+ *
20983
+ * @remarks
20984
+ * Returns one entry per `(agent, day, shift)` cell — including
20985
+ * `free` cells, so consumers can residuate on cells the optimizer
20986
+ * is indifferent about. `assignments` is empty when the problem
20987
+ * exists but hasn't been solved yet.
20988
+ *
20989
+ * `totalScore` mirrors the most recent solve's optimum value, or
20990
+ * `0` when the problem hasn't been solved.
20991
+ */
20992
+ async listAssignments(problemId) {
20993
+ const response = await this.api.listAssignments(problemId);
20994
+ return SchedulingAssignmentsResponseFromApiToFront(response.data);
20995
+ }
20996
+ // ── Mutation methods on the live problem ──────────────────────────
20997
+ /**
20998
+ * Read the current state of a stored problem — its pins,
20999
+ * preferences, version counter, and latest-solve metadata.
21000
+ *
21001
+ * @remarks
21002
+ * Pin and preference entries carry stable IDs (`pinId`,
21003
+ * `preferenceId`) — pass those to {@link SchedulingClient.removePin}
21004
+ * / {@link SchedulingClient.removePreference} to delete them.
21005
+ *
21006
+ * @throws HTTP 404 when the problem doesn't exist for the
21007
+ * caller's tenant.
21008
+ */
21009
+ async getProblem(problemId) {
21010
+ const response = await this.api.getProblem(problemId);
21011
+ return SchedulingProblemFromApiToFront(response.data);
21012
+ }
21013
+ /**
21014
+ * Append a pin to a stored problem. Returns the pin's stable
21015
+ * ID and the problem's new version. Multiple pins on the same
21016
+ * `(agent, day, shift)` are not deduplicated server-side; if you
21017
+ * want at-most-one-pin-per-cell semantics, enforce it on the
21018
+ * client by checking the pin entries from
21019
+ * {@link SchedulingClient.getProblem} first.
21020
+ *
21021
+ * @throws HTTP 400 when the agent isn't on the problem's roster
21022
+ * or the (day, shift) is outside the grid. HTTP 404 when the
21023
+ * problem doesn't exist for the caller's tenant.
21024
+ */
21025
+ async addPin(problemId, request) {
21026
+ const response = await this.api.addPin(
21027
+ problemId,
21028
+ AddPinRequestFromFrontToApi(request)
21029
+ );
21030
+ return AddPinResponseFromApiToFront(response.data);
21031
+ }
21032
+ /**
21033
+ * Remove a pin previously added via
21034
+ * {@link SchedulingClient.addPin}.
21035
+ *
21036
+ * @throws HTTP 404 when the problem doesn't exist for the
21037
+ * tenant or the `pinId` doesn't match any current pin
21038
+ * (already removed, stale ID).
21039
+ */
21040
+ async removePin(problemId, pinId) {
21041
+ await this.api.removePin(problemId, pinId);
21042
+ }
21043
+ /**
21044
+ * Append a preference to a stored problem. Same return shape as
21045
+ * {@link SchedulingClient.addPin} — `preferenceId` is the stable
21046
+ * handle for removal. Multiple preferences targeting the same
21047
+ * cell sum on the next solve.
21048
+ */
21049
+ async addPreference(problemId, request) {
21050
+ const response = await this.api.addPreference(
21051
+ problemId,
21052
+ AddPreferenceRequestFromFrontToApi(request)
21053
+ );
21054
+ return AddPreferenceResponseFromApiToFront(response.data);
21055
+ }
21056
+ /**
21057
+ * Remove a preference previously added via
21058
+ * {@link SchedulingClient.addPreference}.
21059
+ */
21060
+ async removePreference(problemId, preferenceId) {
21061
+ await this.api.removePreference(problemId, preferenceId);
21062
+ }
20678
21063
  };
20679
21064
 
20680
21065
  // src/normalizers/osfql.ts