ql-agent-sdk 1.3.3 → 1.4.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/README.md CHANGED
@@ -78,7 +78,7 @@ Create keys in your Quanton Labs dashboard → **API Keys** page. Each key is sc
78
78
  | `agents` | `ql.agents.list()`, `ql.agents.get()` |
79
79
  | `capabilities` | `ql.agents.capabilities()`, `ql.agents.runCapability()` |
80
80
  | `chat` | `ql.agents.chat()`, `ql.agents.chatStream()` |
81
- | `messages` | `ql.agents.history()` |
81
+ | `messages` | `ql.agents.history()`, `ql.agents.listMessages()` |
82
82
  | `workflows` | `ql.workflows.run()`, `ql.workflows.getRun()` |
83
83
  | `tasks` | `ql.tasks.create()`, `ql.tasks.get()` |
84
84
  | `*` | All of the above (default for new keys) |
@@ -485,6 +485,74 @@ do {
485
485
  console.log(`${allMessages.length} total messages`);
486
486
  ```
487
487
 
488
+ #### `ql.agents.listMessages(params)` → `Promise<AgentMessagesPage>`
489
+
490
+ **Scope:** `messages`
491
+
492
+ Returns the **chronological message feed** for a conversation — chat turns plus workflow artifacts (tool results, step progress, approval requests). Use this to poll live progress of a background run: call it without `after` for the latest N, then page forward with `after`.
493
+
494
+ **Parameters:**
495
+ - `params.agentId: string` — agent slug or ObjectId (required)
496
+ - `params.after?: string` — cursor = id of the last item you received (forward pagination). Omit for the latest N.
497
+ - `params.limit?: number` — page size, 1–50 (default 20)
498
+ - `params.userId?: string` — optional filter by user (defaults to the workspace id)
499
+
500
+ **Response (200):**
501
+ ```json
502
+ {
503
+ "items": [
504
+ {
505
+ "id": "6ae0d963...",
506
+ "role": "user",
507
+ "kind": "chat",
508
+ "content": "Import this CSV into users",
509
+ "status": "completed",
510
+ "timestamp": "2026-11-05T10:00:00.000Z"
511
+ },
512
+ {
513
+ "id": "6ae0d964...",
514
+ "role": "assistant",
515
+ "kind": "workflow",
516
+ "content": null,
517
+ "taskId": "6ae0d965...",
518
+ "toolCalls": [{ "name": "fetch_schema", "status": "completed", "result": { "collections": ["users"] } }],
519
+ "status": "completed",
520
+ "timestamp": "2026-11-05T10:00:02.000Z"
521
+ },
522
+ {
523
+ "id": "6ae0d966...",
524
+ "role": "assistant",
525
+ "kind": "approval_request",
526
+ "content": "Delete 3 rows from `users`? ...",
527
+ "outputFormat": "json",
528
+ "status": "completed",
529
+ "timestamp": "2026-11-05T10:00:05.000Z"
530
+ }
531
+ ],
532
+ "hasMore": true,
533
+ "nextAfter": "6ae0d966..."
534
+ }
535
+ ```
536
+
537
+ | Field | Description |
538
+ |-------|-------------|
539
+ | `items[].kind` | `"chat"` (default), `"tool_result"`, `"workflow"`, or `"approval_request"` |
540
+ | `items[].content` | Message text (may be null for artifact-only entries) |
541
+ | `items[].outputFormat` | Declared format of `content`: `"text"`, `"json"`, or `"html"` |
542
+ | `items[].toolCalls` | Tool invocations; each may carry a truncated `result` once complete |
543
+ | `items[].taskId` | Task id for entries produced by a background workflow run |
544
+ | `hasMore` / `nextAfter` | Forward pagination: pass `nextAfter` as the next `after` |
545
+
546
+ **Polling a live run (e.g. every 4s):**
547
+ ```ts
548
+ let after: string | undefined;
549
+ const timer = setInterval(async () => {
550
+ const page = await ql.agents.listMessages({ agentId: "operations", limit: 20, after });
551
+ for (const item of page.items) renderFeedItem(item); // tool chips, step progress, approvals…
552
+ after = page.nextAfter;
553
+ }, 4000);
554
+ ```
555
+
488
556
  ---
489
557
 
490
558
  ### Workflows
@@ -799,6 +867,118 @@ const uploaded = await ql.files.upload(new Blob([blob], { type: "video/mp4" }),
799
867
  });
800
868
  ```
801
869
 
870
+ ### Architecture (Approvals · Policies · Events · Subagents · Skills · Executions)
871
+
872
+ The platform enforces a policy engine over every protected action (agent tool calls, workflow
873
+ nodes, skill runs, subagent tools). Protected actions that are not fully autonomous produce an
874
+ **approval request**; approved actions execute exactly once. All of this is observable and
875
+ controllable through the namespaces below. List endpoints return *list-safe* views (no bound
876
+ payloads); detail endpoints include full records.
877
+
878
+ #### `ql.approvals.list(params?)` → `Promise<ApprovalsListResult>`
879
+
880
+ **Scope:** `approvals`
881
+
882
+ Lists approval requests, newest first. `params?: { status?: ApprovalStatus[], limit?, beforeCreatedAt?: string | Date }`
883
+ — statuses: `pending`, `approved`, `rejected`, `expired`, `consumed`.
884
+
885
+ #### `ql.approvals.get(approvalId)` → `Promise<ApprovalDetail>`
886
+
887
+ **Scope:** `approvals`
888
+
889
+ Full record including the bound action payload, evaluation (rule pack / rule / severity / reason),
890
+ evidence, and decision metadata.
891
+
892
+ #### `ql.approvals.decide(approvalId, input)` → `Promise<DecideApprovalResult>`
893
+
894
+ **Scope:** `approvals`
895
+
896
+ Records an authorized workspace member's decision. `input: { decision: "approve" | "reject", decidedBy, note?, evidence? }`.
897
+ A user cannot approve their own request (403). State errors (pending/expired/consumed/…) → 409; unknown id → 404.
898
+
899
+ #### `ql.approvals.execute(approvalId)` → `Promise<ExecuteApprovalResult>`
900
+
901
+ **Scope:** `approvals`
902
+
903
+ Executes the bound action of an approved approval, consuming it atomically (no replays).
904
+ Returns `{ ok, approvalId, action, status: "consumed", result?, error? }` — executor failures return
905
+ `ok: false` with the error while the approval is still consumed.
906
+
907
+ #### `ql.policies.get()` → `Promise<PoliciesResult>`
908
+
909
+ **Scope:** `policies`
910
+
911
+ Returns active rule packs with their rules, the documented roadmap client packs (registered but
912
+ inactive), and honest stats `{ total, active, roadmap, rulesTotal }`.
913
+
914
+ #### `ql.events.list(params?)` → `Promise<EventsPage>`
915
+
916
+ **Scope:** `events`
917
+
918
+ Paginated read of the hash-chained audit ledger, newest first. `params?: { limit?, beforeSeq?, types?: string[] }`.
919
+ Returns `{ items, hasMore, nextBeforeSeq?, total? }` — walk pages by passing `nextBeforeSeq` back as `beforeSeq`.
920
+
921
+ #### `ql.events.verify(params?)` → `Promise<VerifyChainResult>`
922
+
923
+ **Scope:** `events`
924
+
925
+ Recomputes every event hash and checks each `prevHash` link over the window `seq <= afterSeq`
926
+ (all events when omitted). Returns `{ valid, checkedCount, firstBadSeq?, reason? }`.
927
+
928
+ #### `ql.events.retention()` → `Promise<RetentionReport>`
929
+
930
+ **Scope:** `events`
931
+
932
+ Retention report: `{ retentionDays: 365, oldestEventAt?, eventsInsideRetentionWindow,
933
+ eventsOutsideRetentionWindow, autoDeletionEnabled: false, note }`. No automatic deletion runs.
934
+
935
+ #### `ql.subagents.list(agentId?)` → `Promise<SubagentsListResult>`
936
+
937
+ **Scope:** `subagents`
938
+
939
+ Specialist definitions owned by the eight catalog agents (optionally filtered by owner) plus honest
940
+ stats `{ total, enabled, disabled, withHttp, byAgent }`. 54 definitions ship; 4 permit `http_request`.
941
+
942
+ #### `ql.subagents.get(subagentId)` → `Promise<SubagentDefinition>`
943
+
944
+ **Scope:** `subagents`
945
+
946
+ One definition: permitted tools, I/O contracts, execution constraints, applicability notes.
947
+
948
+ #### `ql.skills.list(domain?)` → `Promise<SkillsListResult>`
949
+
950
+ **Scope:** `skills`
951
+
952
+ Skill definitions (no implementation functions) plus honest stats `{ total, readOnly, write, enabled, byDomain }`.
953
+ 3 skills ship, all read-class and enabled.
954
+
955
+ #### `ql.skills.get(skillId)` → `Promise<SkillDefinition>`
956
+
957
+ **Scope:** `skills`
958
+
959
+ One definition: I/O contract, execution class, version, description.
960
+
961
+ #### `ql.skills.run(input)` → `Promise<SkillRunResult>`
962
+
963
+ **Scope:** `skills`
964
+
965
+ Runs a skill through validation → authorization → policy → audit → execution.
966
+ `input: { skillId, input: Record<string, unknown>, actorUserId, idempotencyKey? }`.
967
+ Unknown/disabled skills → 404; invalid or oversized input → 400.
968
+
969
+ #### `ql.executions.list(params?)` → `Promise<ExecutionsListResult>`
970
+
971
+ **Scope:** `executions`
972
+
973
+ Execution history (list-safe views). `params?: { agentId?, status?: ExecutionStatus[], limit?, beforeCreatedAt?: string | Date }`.
974
+
975
+ #### `ql.executions.get(executionId)` → `Promise<ExecutionDetail>`
976
+
977
+ **Scope:** `executions`
978
+
979
+ Full trace: ordered tool calls (seq, toolName, ok, durationMs, error, approvalId, ledgerSeq), token
980
+ usage, approval/ledger back-references, and direct child executions (subagent runs).
981
+
802
982
  ---
803
983
 
804
984
  ## Error Handling
@@ -969,18 +1149,18 @@ export async function POST(req: Request) {
969
1149
 
970
1150
  ## Agent Reference
971
1151
 
972
- The platform includes 8 specialized agents. Each has 20 capabilities in its domain:
973
-
974
- | ID | Domain | Examples |
975
- |----|--------|----------|
976
- | `governing` | Orchestration | Coordinates other agents, complex multi-step reasoning |
977
- | `finance` | Finance | Invoices, P&L, budgeting, cash flow, tax estimates |
978
- | `marketing` | Marketing | Social media content, ad copy, SEO, campaign planning |
979
- | `inventory` | Supply Chain | Stock levels, reorder points, supplier management |
980
- | `customer` | Customer Success | Support drafts, onboarding sequences, churn analysis |
981
- | `developer` | Engineering | Code generation, API docs, bug triage, test writing |
982
- | `operations` | Operations | SOPs, process mapping, KPI dashboards, compliance |
983
- | `research` | Research | Market analysis, competitor intel, literature reviews |
1152
+ The platform includes 8 specialized agents:
1153
+
1154
+ | ID | Domain | Role |
1155
+ |----|--------|------|
1156
+ | `governing` | Orchestration | The orchestrator: reasons over the goal, plans execution, dispatches subtasks to the other agents (and specialist subagents), and synthesizes the final answer |
1157
+ | `marketing` | Marketing & Content | Plans, creates, distributes, and optimizes content across all channels |
1158
+ | `sales` | Sales | Manages the revenue pipeline from inbound lead to closed deal |
1159
+ | `cx` | Customer Experience | Post-acquisition service, retention, and support quality |
1160
+ | `people` | People & Team | Employee lifecycle: hiring, onboarding, performance, scheduling |
1161
+ | `operations` | Operations | Internal execution infrastructure: tasks, SOPs, vendors, QA |
1162
+ | `inventory` | Inventory & Supply Chain | Stock levels, suppliers, reorder logic, delivery tracking |
1163
+ | `finance` | Finance | Invoices, P&L, cash flow, budgets, financial reporting |
984
1164
 
985
1165
  Discover available capabilities at runtime:
986
1166
  ```ts
package/dist/index.cjs CHANGED
@@ -21,13 +21,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  API_ERROR_CODES: () => API_ERROR_CODES,
24
+ APPROVAL_STATUSES: () => APPROVAL_STATUSES,
24
25
  AgentsApi: () => AgentsApi,
26
+ ApprovalsApi: () => ApprovalsApi,
25
27
  AudioApi: () => AudioApi,
26
28
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
29
+ EXECUTION_STATUSES: () => EXECUTION_STATUSES,
30
+ EventsApi: () => EventsApi,
31
+ ExecutionsApi: () => ExecutionsApi,
27
32
  FilesApi: () => FilesApi,
28
33
  ImagesApi: () => ImagesApi,
34
+ PoliciesApi: () => PoliciesApi,
29
35
  QLClient: () => QLClient,
30
36
  QLError: () => QLError,
37
+ SkillsApi: () => SkillsApi,
38
+ SubagentsApi: () => SubagentsApi,
31
39
  TaskHandle: () => TaskHandle,
32
40
  TasksApi: () => TasksApi,
33
41
  VideoTaskHandle: () => VideoTaskHandle,
@@ -517,6 +525,18 @@ var AgentsApi = class {
517
525
  query: { limit: params.limit, before: params.before, userId: params.userId }
518
526
  });
519
527
  }
528
+ /**
529
+ * GET /api/v1/agents/messages — chronological message feed for a conversation.
530
+ *
531
+ * Returns the latest N entries in chronological order (omit `after`), or page
532
+ * forward with `after` = id of the last item you received. Includes workflow
533
+ * artifacts: tool results, step progress, and approval requests.
534
+ */
535
+ listMessages(params) {
536
+ return this.t.json("GET", "/api/v1/agents/messages", {
537
+ query: { agentId: params.agentId, after: params.after, limit: params.limit, userId: params.userId }
538
+ });
539
+ }
520
540
  async *chatStreamImpl(input, opts) {
521
541
  const body = await this.t.stream("POST", "/api/v1/agents/chat/stream", { body: input, signal: opts.signal });
522
542
  let content = "";
@@ -637,6 +657,115 @@ var FilesApi = class {
637
657
  return result;
638
658
  }
639
659
  };
660
+ var ApprovalsApi = class {
661
+ constructor(t) {
662
+ this.t = t;
663
+ }
664
+ /** GET /api/v1/approvals — list policy approval requests (list-safe views, no payload). */
665
+ list(params) {
666
+ return this.t.json("GET", "/api/v1/approvals", {
667
+ query: {
668
+ status: params?.status?.join(","),
669
+ limit: params?.limit,
670
+ beforeCreatedAt: toIso(params?.beforeCreatedAt)
671
+ }
672
+ });
673
+ }
674
+ /** GET /api/v1/approvals/:id — full approval record incl. bound payload + evidence. */
675
+ get(approvalId) {
676
+ return this.t.json("GET", `/api/v1/approvals/${encodeURIComponent(approvalId)}`);
677
+ }
678
+ /** POST /api/v1/approvals/:id/decide — record an authorized workspace member's decision. */
679
+ decide(approvalId, input) {
680
+ return this.t.json("POST", `/api/v1/approvals/${encodeURIComponent(approvalId)}/decide`, { body: input });
681
+ }
682
+ /** POST /api/v1/approvals/:id/execute — execute the bound action of an approved approval, exactly once. */
683
+ execute(approvalId) {
684
+ return this.t.json("POST", `/api/v1/approvals/${encodeURIComponent(approvalId)}/execute`);
685
+ }
686
+ };
687
+ var PoliciesApi = class {
688
+ constructor(t) {
689
+ this.t = t;
690
+ }
691
+ /** GET /api/v1/policies — active rule packs with their rules + documented roadmap packs. */
692
+ get() {
693
+ return this.t.json("GET", "/api/v1/policies");
694
+ }
695
+ };
696
+ var EventsApi = class {
697
+ constructor(t) {
698
+ this.t = t;
699
+ }
700
+ /** GET /api/v1/events — paginated ledger read, newest first (`beforeSeq` pages backwards). */
701
+ list(params) {
702
+ return this.t.json("GET", "/api/v1/events", {
703
+ query: { limit: params?.limit, beforeSeq: params?.beforeSeq, types: params?.types?.join(",") }
704
+ });
705
+ }
706
+ /** GET /api/v1/events/verify — recompute every hash and check each prevHash link (audit retrieval). */
707
+ verify(params) {
708
+ return this.t.json("GET", "/api/v1/events/verify", { query: { afterSeq: params?.afterSeq } });
709
+ }
710
+ /** GET /api/v1/events/retention — retention report (no automatic deletion runs). */
711
+ retention() {
712
+ return this.t.json("GET", "/api/v1/events/retention");
713
+ }
714
+ };
715
+ var SubagentsApi = class {
716
+ constructor(t) {
717
+ this.t = t;
718
+ }
719
+ /** GET /api/v1/subagents — specialist definitions + honest stats (optionally filtered by owning agent). */
720
+ list(agentId) {
721
+ return this.t.json("GET", "/api/v1/subagents", { query: { agentId } });
722
+ }
723
+ /** GET /api/v1/subagents/:id — one specialist definition. */
724
+ get(subagentId) {
725
+ return this.t.json("GET", `/api/v1/subagents/${encodeURIComponent(subagentId)}`);
726
+ }
727
+ };
728
+ var SkillsApi = class {
729
+ constructor(t) {
730
+ this.t = t;
731
+ }
732
+ /** GET /api/v1/skills — skill definitions (no implementation functions) + honest stats. */
733
+ list(domain) {
734
+ return this.t.json("GET", "/api/v1/skills", { query: { domain } });
735
+ }
736
+ /** GET /api/v1/skills/:id — one skill definition. */
737
+ get(skillId) {
738
+ return this.t.json("GET", `/api/v1/skills/${encodeURIComponent(skillId)}`);
739
+ }
740
+ /** POST /api/v1/skills/run — run a skill through the full validation → authorization → policy → audit → execution pipeline. */
741
+ run(input) {
742
+ return this.t.json("POST", "/api/v1/skills/run", { body: input });
743
+ }
744
+ };
745
+ var ExecutionsApi = class {
746
+ constructor(t) {
747
+ this.t = t;
748
+ }
749
+ /** GET /api/v1/executions — execution history (list-safe views, no tool-call log). */
750
+ list(params) {
751
+ return this.t.json("GET", "/api/v1/executions", {
752
+ query: {
753
+ agentId: params?.agentId,
754
+ status: params?.status?.join(","),
755
+ limit: params?.limit,
756
+ beforeCreatedAt: toIso(params?.beforeCreatedAt)
757
+ }
758
+ });
759
+ }
760
+ /** GET /api/v1/executions/:id — full execution trace incl. tool calls + direct children. */
761
+ get(executionId) {
762
+ return this.t.json("GET", `/api/v1/executions/${encodeURIComponent(executionId)}`);
763
+ }
764
+ };
765
+ function toIso(value) {
766
+ if (value === void 0) return void 0;
767
+ return value instanceof Date ? value.toISOString() : value;
768
+ }
640
769
  function readEnvBaseUrl() {
641
770
  try {
642
771
  if (typeof process !== "undefined" && process?.env) {
@@ -661,6 +790,12 @@ var QLClient = class {
661
790
  this.images = new ImagesApi(this.transport);
662
791
  this.videos = new VideosApi(this.transport);
663
792
  this.audio = new AudioApi(this.transport);
793
+ this.approvals = new ApprovalsApi(this.transport);
794
+ this.policies = new PoliciesApi(this.transport);
795
+ this.events = new EventsApi(this.transport);
796
+ this.subagents = new SubagentsApi(this.transport);
797
+ this.skills = new SkillsApi(this.transport);
798
+ this.executions = new ExecutionsApi(this.transport);
664
799
  this.files = new FilesApi(this.transport);
665
800
  }
666
801
  /** The normalized base URL in use (not secret). */
@@ -678,4 +813,14 @@ var API_ERROR_CODES = {
678
813
  conflict: "conflict",
679
814
  internalError: "internal_error"
680
815
  };
816
+ var APPROVAL_STATUSES = [
817
+ "pending",
818
+ "approved",
819
+ "rejected",
820
+ "expired",
821
+ "consumed",
822
+ "invalidated",
823
+ "cancelled"
824
+ ];
825
+ var EXECUTION_STATUSES = ["running", "completed", "failed", "cancelled", "timeout"];
681
826
  //# sourceMappingURL=index.cjs.map