@gravity-rail/sdk 0.7.3 → 0.7.4

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
@@ -11418,6 +11418,11 @@ var RoleUpdate = class extends WorkspaceBuilderResource {
11418
11418
  }
11419
11419
  };
11420
11420
 
11421
+ // src/constants/models.ts
11422
+ var DEFAULT_CHAT_MODEL = "aws:bedrock:claude-4-5-haiku";
11423
+ var DEFAULT_VOICE_INFERENCE_MODEL = "google:vertex:gemini-3-flash";
11424
+ var DEFAULT_CUSTOM_VOICE_MODEL = "elevenlabs:voice:river";
11425
+
11421
11426
  // src/workspace-builder/workflows.ts
11422
11427
  var PERM_KEYS = {
11423
11428
  canRead: "canRead",
@@ -11561,6 +11566,12 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
11561
11566
  if (this.abilities.length) details.push(`${this.abilities.length} abilities`);
11562
11567
  return `Workflow: ${this.name}${details.length ? ` (${details.join(", ")})` : ""}`;
11563
11568
  }
11569
+ needsDefaultAgent() {
11570
+ return !this._existed && this.agentId === void 0;
11571
+ }
11572
+ setAgentId(agentId) {
11573
+ this.agentId = agentId;
11574
+ }
11564
11575
  async apply(client) {
11565
11576
  if (this._existed) return;
11566
11577
  const payload = {
@@ -11577,6 +11588,54 @@ var WorkflowBuilder = class extends WorkspaceBuilderResource {
11577
11588
  this._created = true;
11578
11589
  }
11579
11590
  };
11591
+ var WORKSPACE_BUILDER_DEFAULT_AGENT_NAME = "Workspace Setup Agent";
11592
+ var WORKSPACE_BUILDER_DEFAULT_AGENT_PROMPT = "You help workspace members complete the workflow you are assigned to. Follow the task prompts, collect requested information accurately, and escalate when the workflow asks you to.";
11593
+ async function getOrCreateDefaultWorkflowAgent(client) {
11594
+ const existingAgents = recordsFromResponse(
11595
+ await client.getAgents({ pageSize: 100, includeArchived: false })
11596
+ );
11597
+ const existing = existingAgents.find((agent) => !agent.isArchived) ?? existingAgents[0];
11598
+ if (existing) {
11599
+ return {
11600
+ id: numberField(existing, "id"),
11601
+ name: stringField(existing, "name"),
11602
+ created: false
11603
+ };
11604
+ }
11605
+ const roles = recordsFromResponse(await client.getMemberRoles());
11606
+ const role = roles.find((candidate) => stringField(candidate, "name").toLowerCase() === "agent") ?? roles[0];
11607
+ if (!role) {
11608
+ throw new Error("Cannot create default workflow agent: workspace has no member roles");
11609
+ }
11610
+ const payload = {
11611
+ name: WORKSPACE_BUILDER_DEFAULT_AGENT_NAME,
11612
+ memberRoleId: numberField(role, "id"),
11613
+ chatModelId: DEFAULT_CHAT_MODEL,
11614
+ systemPrompt: WORKSPACE_BUILDER_DEFAULT_AGENT_PROMPT
11615
+ };
11616
+ const created = await client.createAgent(payload);
11617
+ return {
11618
+ id: created.id,
11619
+ name: created.name ?? WORKSPACE_BUILDER_DEFAULT_AGENT_NAME,
11620
+ created: true
11621
+ };
11622
+ }
11623
+ function recordsFromResponse(value) {
11624
+ if (Array.isArray(value)) return value;
11625
+ if (value && typeof value === "object" && Array.isArray(value.items)) {
11626
+ return value.items;
11627
+ }
11628
+ return [];
11629
+ }
11630
+ function numberField(record, key) {
11631
+ const value = record[key];
11632
+ if (typeof value !== "number") throw new Error(`Expected numeric ${key}`);
11633
+ return value;
11634
+ }
11635
+ function stringField(record, key) {
11636
+ const value = record[key];
11637
+ return typeof value === "string" ? value : "";
11638
+ }
11580
11639
  var AgentBuilder = class extends WorkspaceBuilderResource {
11581
11640
  constructor(name, options = {}) {
11582
11641
  super();
@@ -11741,6 +11800,7 @@ ${"=".repeat(50)}`);
11741
11800
  await this.resolveExisting(resources);
11742
11801
  const summary = {};
11743
11802
  writeLine("Applying...");
11803
+ await this.ensureWorkflowAgents(resources, summary);
11744
11804
  for (const resource of resources) {
11745
11805
  try {
11746
11806
  if (resource._existed) {
@@ -11834,6 +11894,21 @@ Done! Created ${count} resources.`);
11834
11894
  }
11835
11895
  }
11836
11896
  }
11897
+ async ensureWorkflowAgents(resources, summary) {
11898
+ const workflows = resources.filter(
11899
+ (resource) => resource instanceof WorkflowBuilder && resource.needsDefaultAgent()
11900
+ );
11901
+ if (!workflows.length) return;
11902
+ const agent = await getOrCreateDefaultWorkflowAgent(this.client);
11903
+ for (const workflow of workflows) workflow.setAgentId(agent.id);
11904
+ if (agent.created) {
11905
+ summary.agents ??= [];
11906
+ summary.agents.push(agent.id);
11907
+ writeLine(` Created Agent: ${agent.name} -> id=${agent.id}`);
11908
+ } else {
11909
+ writeLine(` Using Agent: ${agent.name || agent.id} -> id=${agent.id}`);
11910
+ }
11911
+ }
11837
11912
  sortedResources() {
11838
11913
  const all = [];
11839
11914
  for (const resource of this.resources) {
@@ -12454,11 +12529,6 @@ function isChatType(value) {
12454
12529
  return Object.values(CHAT_TYPES).includes(value);
12455
12530
  }
12456
12531
 
12457
- // src/constants/models.ts
12458
- var DEFAULT_CHAT_MODEL = "aws:bedrock:claude-4-5-haiku";
12459
- var DEFAULT_VOICE_INFERENCE_MODEL = "google:vertex:gemini-3-flash";
12460
- var DEFAULT_CUSTOM_VOICE_MODEL = "elevenlabs:voice:river";
12461
-
12462
12532
  // src/types/resource-metadata.ts
12463
12533
  var RESOURCE_METADATA = {
12464
12534
  ["credit" /* CREDIT */]: {