@overaihq/cli 0.14.5 → 0.14.6

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.
Files changed (2) hide show
  1. package/dist/index.js +295 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -27703,22 +27703,7 @@ var whoami = (args = []) => {
27703
27703
  };
27704
27704
 
27705
27705
  // src/commands/agent.ts
27706
- var runAgent = async (args) => {
27707
- const [operation, id] = args;
27708
- if (operation !== "generate" || id == null) throw new Error("Usage: overai agent generate <id> --message <text|@file|@->");
27709
- const message = await readValue(flagValue(args, "--message", "-m"), "--message");
27710
- if (message == null) throw new Error("Agent generate requires --message.");
27711
- const { organizationId } = await getAccessToken();
27712
- const response = await v2Fetch(`/v2/agents/${organizationId}/${id}/generate/text`, {
27713
- method: "POST",
27714
- headers: { "Content-Type": "application/json" },
27715
- body: JSON.stringify({ message })
27716
- });
27717
- const raw2 = await response.text();
27718
- if (!response.ok) throw v2Error("agent generate", response, raw2);
27719
- const body = JSON.parse(raw2);
27720
- printResult(body, resolveFormat(flagValue(args, "-o", "--output")));
27721
- };
27706
+ import { createInterface } from "readline";
27722
27707
 
27723
27708
  // src/gql.ts
27724
27709
  var gqlRequest = async (query, variables) => {
@@ -27748,6 +27733,283 @@ var gqlRequest = async (query, variables) => {
27748
27733
  return body.data;
27749
27734
  };
27750
27735
 
27736
+ // src/commands/agent.ts
27737
+ var USAGE = [
27738
+ "Usage:",
27739
+ " overai agent generate <id> --message <text|@file|@->",
27740
+ " overai agent tools <id> [--version <n>] [-o json|table|csv]",
27741
+ " overai agent chat <id> [--conversation <id>] [--message <text>]"
27742
+ ].join("\n");
27743
+ var generate = async (args, id) => {
27744
+ const message = await readValue(
27745
+ flagValue(args, "--message", "-m"),
27746
+ "--message"
27747
+ );
27748
+ if (message == null) throw new Error("Agent generate requires --message.");
27749
+ const { organizationId } = await getAccessToken();
27750
+ const response = await v2Fetch(
27751
+ `/v2/agents/${organizationId}/${id}/generate/text`,
27752
+ {
27753
+ method: "POST",
27754
+ headers: { "Content-Type": "application/json" },
27755
+ body: JSON.stringify({ message })
27756
+ }
27757
+ );
27758
+ const raw2 = await response.text();
27759
+ if (!response.ok) throw v2Error("agent generate", response, raw2);
27760
+ printResult(
27761
+ JSON.parse(raw2),
27762
+ resolveFormat(flagValue(args, "-o", "--output"))
27763
+ );
27764
+ };
27765
+ var deployedVersionNumber = async (id) => {
27766
+ const deployed = await gqlRequest(
27767
+ `query CliAgentDeployedVersion($id: String!) {
27768
+ agentDeployedVersions(condition: { agentId: $id }) { nodes { versionNumber } }
27769
+ }`,
27770
+ { id }
27771
+ );
27772
+ const versionNumber = deployed.agentDeployedVersions?.nodes[0]?.versionNumber;
27773
+ if (versionNumber == null) {
27774
+ throw new Error(
27775
+ `Agent ${id} has no deployed version; pass --version <n> to inspect a saved one.`
27776
+ );
27777
+ }
27778
+ return versionNumber;
27779
+ };
27780
+ var tools = async (args, id) => {
27781
+ const versionFlag = flagValue(args, "--version", "-v");
27782
+ if (versionFlag != null && !Number.isInteger(Number(versionFlag))) {
27783
+ throw new Error("--version must be an integer.");
27784
+ }
27785
+ const version = versionFlag == null ? await deployedVersionNumber(id) : Number(versionFlag);
27786
+ const data = await gqlRequest(
27787
+ `query CliAgentTools($id: String!, $version: Int!) {
27788
+ agent(id: $id) {
27789
+ name
27790
+ agentVersions(first: 1, condition: { versionNumber: $version }) {
27791
+ nodes {
27792
+ versionNumber
27793
+ model
27794
+ agentVersionFunctionsByAgentIdAndVersionNumber(orderBy: [FUNCTION_ID_ASC]) {
27795
+ nodes { functionId function { name } }
27796
+ }
27797
+ agentVersionTableSpacesByAgentIdAndVersionNumber(orderBy: [TABLE_SPACE_ID_ASC]) {
27798
+ nodes { tableSpaceId accessMode }
27799
+ }
27800
+ agentVersionAgentsByAgentIdAndVersionNumber(orderBy: [ATTACHED_AGENT_ID_ASC]) {
27801
+ nodes { attachedAgentId }
27802
+ }
27803
+ agentVersionKnowledgeBasesByAgentIdAndVersionNumber(orderBy: [KNOWLEDGE_BASE_ID_ASC]) {
27804
+ nodes { knowledgeBaseId }
27805
+ }
27806
+ agentVersionBuiltinToolSetsByAgentIdAndVersionNumber(orderBy: [TOOL_SET_ASC]) {
27807
+ nodes { toolSet }
27808
+ }
27809
+ }
27810
+ }
27811
+ }
27812
+ }`,
27813
+ { id, version }
27814
+ );
27815
+ if (data.agent == null) throw new Error(`Agent ${id} not found.`);
27816
+ const agentVersion = data.agent.agentVersions.nodes[0];
27817
+ if (agentVersion == null) {
27818
+ throw new Error(`Agent ${id} has no version ${String(version)}.`);
27819
+ }
27820
+ const rows = [
27821
+ ...agentVersion.agentVersionFunctionsByAgentIdAndVersionNumber.nodes.map(
27822
+ (link) => ({
27823
+ kind: "function",
27824
+ name: link.function?.name ?? link.functionId,
27825
+ detail: link.functionId
27826
+ })
27827
+ ),
27828
+ ...agentVersion.agentVersionTableSpacesByAgentIdAndVersionNumber.nodes.map(
27829
+ (link) => ({
27830
+ kind: "table space",
27831
+ name: link.tableSpaceId,
27832
+ detail: link.accessMode
27833
+ })
27834
+ ),
27835
+ ...agentVersion.agentVersionAgentsByAgentIdAndVersionNumber.nodes.map(
27836
+ (link) => ({
27837
+ kind: "sub-agent",
27838
+ name: link.attachedAgentId,
27839
+ detail: ""
27840
+ })
27841
+ ),
27842
+ ...agentVersion.agentVersionKnowledgeBasesByAgentIdAndVersionNumber.nodes.map(
27843
+ (link) => ({
27844
+ kind: "knowledge base",
27845
+ name: link.knowledgeBaseId,
27846
+ detail: ""
27847
+ })
27848
+ ),
27849
+ ...agentVersion.agentVersionBuiltinToolSetsByAgentIdAndVersionNumber.nodes.map(
27850
+ (link) => ({ kind: "built-in", name: link.toolSet, detail: "" })
27851
+ )
27852
+ ];
27853
+ const format2 = resolveFormat(flagValue(args, "-o", "--output"));
27854
+ if (format2 === "json") {
27855
+ printResult(
27856
+ {
27857
+ agent: data.agent.name,
27858
+ version: agentVersion.versionNumber,
27859
+ model: agentVersion.model,
27860
+ tools: rows
27861
+ },
27862
+ format2
27863
+ );
27864
+ return;
27865
+ }
27866
+ if (format2 === "table") {
27867
+ process.stdout.write(
27868
+ `${data.agent.name} \xB7 version ${String(agentVersion.versionNumber)} \xB7 ${agentVersion.model}
27869
+ `
27870
+ );
27871
+ }
27872
+ printResult(rows, format2);
27873
+ };
27874
+ var printStreamLine = (line) => {
27875
+ if (!line.startsWith("data: ")) return;
27876
+ const payload = line.slice(6);
27877
+ if (payload === "[DONE]") return;
27878
+ let event;
27879
+ try {
27880
+ event = JSON.parse(payload);
27881
+ } catch {
27882
+ return;
27883
+ }
27884
+ if (event.type === "text-delta" && event.delta != null) {
27885
+ process.stdout.write(event.delta);
27886
+ }
27887
+ if (event.type === "error") {
27888
+ process.stderr.write(`
27889
+ ${event.errorText ?? "agent turn failed"}
27890
+ `);
27891
+ }
27892
+ };
27893
+ var streamReply = async (response) => {
27894
+ const body = response.body;
27895
+ if (body == null) return;
27896
+ const decoder = new TextDecoder();
27897
+ let buffer = "";
27898
+ for await (const chunk of body) {
27899
+ buffer += decoder.decode(chunk, { stream: true });
27900
+ const lines = buffer.split("\n");
27901
+ buffer = lines.pop() ?? "";
27902
+ lines.forEach(printStreamLine);
27903
+ }
27904
+ printStreamLine(buffer + decoder.decode());
27905
+ };
27906
+ var send = async (organizationId, id, message, conversationId) => {
27907
+ const response = await v2Fetch(`/v2/agents/${organizationId}/${id}`, {
27908
+ method: "POST",
27909
+ headers: { "Content-Type": "application/json" },
27910
+ body: JSON.stringify({
27911
+ messages: [{ role: "user", parts: [{ type: "text", text: message }] }],
27912
+ conversationId
27913
+ })
27914
+ });
27915
+ if (!response.ok) {
27916
+ throw v2Error("agent chat", response, await response.text());
27917
+ }
27918
+ await streamReply(response);
27919
+ process.stdout.write("\n");
27920
+ };
27921
+ var createConversation = async (id, firstMessage) => {
27922
+ const versionNumber = await deployedVersionNumber(id);
27923
+ const created = await gqlRequest(
27924
+ `mutation CliCreateAgentConversation($input: CreateAgentConversationInput!) {
27925
+ createAgentConversation(input: $input) { agentConversation { id } }
27926
+ }`,
27927
+ {
27928
+ input: {
27929
+ agentConversation: {
27930
+ agentId: id,
27931
+ versionNumber,
27932
+ title: firstMessage.length > 50 ? `${firstMessage.slice(0, 47)}...` : firstMessage
27933
+ }
27934
+ }
27935
+ }
27936
+ );
27937
+ const conversationId = created.createAgentConversation?.agentConversation?.id;
27938
+ if (conversationId == null)
27939
+ throw new Error("Failed to create a conversation.");
27940
+ return conversationId;
27941
+ };
27942
+ var chat = async (args, id) => {
27943
+ const { organizationId } = await getAccessToken();
27944
+ let conversationId = flagValue(args, "--conversation", "-c") ?? null;
27945
+ const single = await readValue(
27946
+ flagValue(args, "--message", "-m"),
27947
+ "--message"
27948
+ );
27949
+ if (single != null) {
27950
+ conversationId ??= await createConversation(id, single);
27951
+ try {
27952
+ await send(organizationId, id, single, conversationId);
27953
+ } finally {
27954
+ process.stderr.write(`Conversation: ${conversationId}
27955
+ `);
27956
+ }
27957
+ return;
27958
+ }
27959
+ const interactive = process.stdin.isTTY;
27960
+ const rl = createInterface({
27961
+ input: process.stdin,
27962
+ ...interactive ? { output: process.stdout, historySize: 1e3, terminal: true } : {}
27963
+ });
27964
+ if (interactive) {
27965
+ process.stdout.write(
27966
+ `Chatting with ${id}. Ctrl-C to leave; each reply prints as it streams.
27967
+ `
27968
+ );
27969
+ rl.setPrompt("> ");
27970
+ rl.prompt();
27971
+ }
27972
+ for await (const line of rl) {
27973
+ const message = line.trim();
27974
+ if (message.length === 0) {
27975
+ if (interactive) rl.prompt();
27976
+ continue;
27977
+ }
27978
+ try {
27979
+ conversationId ??= await createConversation(id, message);
27980
+ await send(organizationId, id, message, conversationId);
27981
+ } catch (error) {
27982
+ process.stderr.write(
27983
+ `${error instanceof Error ? error.message : String(error)}
27984
+ `
27985
+ );
27986
+ }
27987
+ if (interactive) rl.prompt();
27988
+ }
27989
+ if (conversationId != null) {
27990
+ process.stderr.write(`
27991
+ Conversation: ${conversationId}
27992
+ `);
27993
+ }
27994
+ };
27995
+ var runAgent = async (args) => {
27996
+ const [operation, id] = args;
27997
+ if (id == null) throw new Error(USAGE);
27998
+ switch (operation) {
27999
+ case "generate":
28000
+ await generate(args, id);
28001
+ return;
28002
+ case "tools":
28003
+ await tools(args, id);
28004
+ return;
28005
+ case "chat":
28006
+ await chat(args, id);
28007
+ return;
28008
+ default:
28009
+ throw new Error(USAGE);
28010
+ }
28011
+ };
28012
+
27751
28013
  // src/commands/automation.ts
27752
28014
  var runRuns = async (automationId, args) => {
27753
28015
  const limit2 = Number(flagValue(args, "--limit") ?? 20);
@@ -28693,7 +28955,7 @@ var runList = async (args) => {
28693
28955
  resolveFormat(flagValue(args, "-o", "--output"))
28694
28956
  );
28695
28957
  };
28696
- var USAGE = "Usage: overai runner create <workspaceId> [--name <name>]\n overai runner token <runnerId> [--note <note>]\n overai runner run <runnerId> [--interpreter shell|powershell] --code '<code>'\n overai runner upload <runnerId> --path '<path>'\n overai runner list [workspaceId] [--limit <n>]\n";
28958
+ var USAGE2 = "Usage: overai runner create <workspaceId> [--name <name>]\n overai runner token <runnerId> [--note <note>]\n overai runner run <runnerId> [--interpreter shell|powershell] --code '<code>'\n overai runner upload <runnerId> --path '<path>'\n overai runner list [workspaceId] [--limit <n>]\n";
28697
28959
  var runRunner = async (args) => {
28698
28960
  const [sub, id, ...rest] = args;
28699
28961
  if (sub === "create" && id != null) return runCreate(id, rest);
@@ -28701,7 +28963,7 @@ var runRunner = async (args) => {
28701
28963
  if (sub === "run" && id != null) return runRun(id, rest);
28702
28964
  if (sub === "upload" && id != null) return runUpload(id, rest);
28703
28965
  if (sub === "list") return runList([id, ...rest].filter((a) => a != null));
28704
- process.stderr.write(USAGE);
28966
+ process.stderr.write(USAGE2);
28705
28967
  process.exitCode = 1;
28706
28968
  };
28707
28969
 
@@ -35297,7 +35559,7 @@ var runGraphql = async (args) => {
35297
35559
  };
35298
35560
 
35299
35561
  // src/commands/integration.ts
35300
- var USAGE2 = "Usage: overai integration configure <id> --config <json|@file|@-> | integration config <id> | integration secret set <id> <KEY> --value <@file|@-> | integration secret unset <id> <KEY>";
35562
+ var USAGE3 = "Usage: overai integration configure <id> --config <json|@file|@-> | integration config <id> | integration secret set <id> <KEY> --value <@file|@-> | integration secret unset <id> <KEY>";
35301
35563
  var setSecret = async (integrationId, key, rawValue) => {
35302
35564
  if (rawValue == null) {
35303
35565
  throw new Error("Integration secret set requires --value.");
@@ -35331,7 +35593,7 @@ var runIntegration = async (args) => {
35331
35593
  if (operation === "secret") {
35332
35594
  const [, action, id2, key] = args;
35333
35595
  if (action !== "set" && action !== "unset" || id2 == null || key == null || key.startsWith("-")) {
35334
- throw new Error(USAGE2);
35596
+ throw new Error(USAGE3);
35335
35597
  }
35336
35598
  if (action === "set") {
35337
35599
  await setSecret(id2, key, flagValue(args, "--value"));
@@ -35347,7 +35609,7 @@ var runIntegration = async (args) => {
35347
35609
  }
35348
35610
  const [, id] = args;
35349
35611
  if (id == null || operation !== "configure" && operation !== "config") {
35350
- throw new Error(USAGE2);
35612
+ throw new Error(USAGE3);
35351
35613
  }
35352
35614
  if (operation === "configure") {
35353
35615
  const raw2 = await readValue(flagValue(args, "--config"), "--config");
@@ -35640,7 +35902,7 @@ var runOpen = async (args) => {
35640
35902
  };
35641
35903
 
35642
35904
  // src/commands/org.ts
35643
- import { createInterface } from "readline/promises";
35905
+ import { createInterface as createInterface2 } from "readline/promises";
35644
35906
  var USER_ORGS_QUERY = `
35645
35907
  query UserOrganizations($identityId: String!) {
35646
35908
  identityOrganizations(condition: { identityId: $identityId }) {
@@ -35770,7 +36032,7 @@ var promptForOrg = async () => {
35770
36032
  `
35771
36033
  );
35772
36034
  });
35773
- const rl = createInterface({ input: process.stdin, output: process.stdout });
36035
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
35774
36036
  try {
35775
36037
  const answer = await rl.question("Switch to: ");
35776
36038
  const chosen = rows[Number(answer.trim()) - 1];
@@ -37172,7 +37434,7 @@ var runReview = async () => {
37172
37434
  };
37173
37435
 
37174
37436
  // src/commands/sql.ts
37175
- import { createInterface as createInterface2 } from "readline";
37437
+ import { createInterface as createInterface3 } from "readline";
37176
37438
 
37177
37439
  // src/commands/sqlCredential.ts
37178
37440
  var connectionString = async (tableSpaceId, secret) => {
@@ -37316,7 +37578,7 @@ transaction \u2014 BEGIN/SET/temp tables don't carry across statements.
37316
37578
  `;
37317
37579
  var runRepl = async (organizationId, tableSpaceId, format2) => {
37318
37580
  const interactive = process.stdin.isTTY;
37319
- const rl = createInterface2({
37581
+ const rl = createInterface3({
37320
37582
  input: process.stdin,
37321
37583
  ...interactive ? { output: process.stdout, historySize: 1e3, terminal: true } : {}
37322
37584
  });
@@ -37462,10 +37724,10 @@ var runSql = async (args) => {
37462
37724
 
37463
37725
  // src/commands/storage.ts
37464
37726
  import { openAsBlob, writeFileSync as writeFileSync6 } from "fs";
37465
- var USAGE3 = "Usage: overai storage upload <path> [--no-random-prefix] | storage download <key> [path|-] | storage exists <key> | storage head <key> [--lines N] | storage presign <key> [--expires-in <seconds>]";
37727
+ var USAGE4 = "Usage: overai storage upload <path> [--no-random-prefix] | storage download <key> [path|-] | storage exists <key> | storage head <key> [--lines N] | storage presign <key> [--expires-in <seconds>]";
37466
37728
  var runStorage = async (args) => {
37467
37729
  const [operation, first2, second] = args;
37468
- if (operation == null) throw new Error(USAGE3);
37730
+ if (operation == null) throw new Error(USAGE4);
37469
37731
  const { organizationId } = await getAccessToken();
37470
37732
  const segment = (key) => encodeURIComponent(key);
37471
37733
  if (operation === "upload") {
@@ -37496,7 +37758,7 @@ var runStorage = async (args) => {
37496
37758
  `);
37497
37759
  return;
37498
37760
  }
37499
- if (first2 == null) throw new Error(USAGE3);
37761
+ if (first2 == null) throw new Error(USAGE4);
37500
37762
  if (operation === "download") {
37501
37763
  const response = await v2Fetch(
37502
37764
  `/v2/storage/${organizationId}/${segment(first2)}`,
@@ -37553,7 +37815,7 @@ var runStorage = async (args) => {
37553
37815
  `);
37554
37816
  return;
37555
37817
  }
37556
- throw new Error(USAGE3);
37818
+ throw new Error(USAGE4);
37557
37819
  };
37558
37820
 
37559
37821
  // src/commands/workspace.ts
@@ -37639,7 +37901,7 @@ var listWorkspaceUsers = async (args) => {
37639
37901
  resolveFormat(flagValue(args, "-o", "--output"))
37640
37902
  );
37641
37903
  };
37642
- var USAGE4 = `Usage:
37904
+ var USAGE5 = `Usage:
37643
37905
  overai workspace list [--archived] [--limit <n>]
37644
37906
  overai workspace show [workspaceId]
37645
37907
  overai workspace users [workspaceId]
@@ -37657,7 +37919,7 @@ var runWorkspace = async (args) => {
37657
37919
  await listWorkspaceUsers(args.slice(1));
37658
37920
  return;
37659
37921
  }
37660
- process.stderr.write(USAGE4);
37922
+ process.stderr.write(USAGE5);
37661
37923
  process.exitCode = 1;
37662
37924
  };
37663
37925
 
@@ -37815,6 +38077,8 @@ Automations:
37815
38077
 
37816
38078
  Other resources:
37817
38079
  overai agent generate <agentId> --message <text|@file|@->
38080
+ overai agent tools <agentId> [--version <n>]
38081
+ overai agent chat <agentId> [--conversation <id>] [--message <text>]
37818
38082
  overai data-stream append <id> <json|@file|@->
37819
38083
  overai data-stream query <id> --start <date> --end <date> [--query <filter>]
37820
38084
  overai data-file upload <id> <path> [-m <message>]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overaihq/cli",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "description": "Create, edit, deploy, and run OverAI workspace resources from the command line",
5
5
  "type": "module",
6
6
  "homepage": "https://overai.com",