@javargasm/opencode-kiro-auth 0.3.0 → 0.3.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.js CHANGED
@@ -3790,6 +3790,32 @@ function anthropicError(status, type, message) {
3790
3790
  }
3791
3791
  });
3792
3792
  }
3793
+ function isTitleGenerationRequest(messages) {
3794
+ for (const m of messages) {
3795
+ if (m?.role !== "user")
3796
+ continue;
3797
+ const text = typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((b) => typeof b === "string" ? b : b?.text || "").join(" ") : "";
3798
+ if (/generate a title for this conversation/i.test(text))
3799
+ return true;
3800
+ }
3801
+ return false;
3802
+ }
3803
+ function stripTitleMarkdown(text) {
3804
+ let t = text.trim();
3805
+ let prev;
3806
+ do {
3807
+ prev = t;
3808
+ t = t.replace(/^\*\*([\s\S]+?)\*\*$/, "$1").trim();
3809
+ t = t.replace(/^\*([\s\S]+?)\*$/, "$1").trim();
3810
+ t = t.replace(/^__([\s\S]+?)__$/, "$1").trim();
3811
+ t = t.replace(/^_([\s\S]+?)_$/, "$1").trim();
3812
+ t = t.replace(/^`([\s\S]+?)`$/, "$1").trim();
3813
+ t = t.replace(/^["'“”]([\s\S]+?)["'“”]$/, "$1").trim();
3814
+ t = t.replace(/^#{1,6}\s+/, "").trim();
3815
+ t = t.replace(/^[-*]\s+/, "").trim();
3816
+ } while (t !== prev && t.length > 0);
3817
+ return t;
3818
+ }
3793
3819
  function startGatewayServer(port = 0) {
3794
3820
  return new Promise((resolve2) => {
3795
3821
  const server = Bun.serve({
@@ -3900,6 +3926,7 @@ function startGatewayServer(port = 0) {
3900
3926
  };
3901
3927
  log.debug("[gateway] body-keys", Object.keys(body));
3902
3928
  const reasoningEffort = body.output_config?.effort ?? body.reasoning_effort ?? undefined;
3929
+ const isTitleTurn = isTitleGenerationRequest(anthropicMessages);
3903
3930
  log.info(`[gateway] → ${kiroEndpoint} model=${anthropicModelId} region=${apiRegion} stream=${streamRequested}`);
3904
3931
  if (_creds.profileArn) {
3905
3932
  seedProfileArn(_creds.profileArn);
@@ -3963,6 +3990,7 @@ data: ` + JSON.stringify({
3963
3990
  `);
3964
3991
  let contentBlockIndex = 0;
3965
3992
  let activeBlockType = null;
3993
+ let titleTextBuffer = "";
3966
3994
  const closeActiveBlock = () => {
3967
3995
  if (activeBlockType !== null) {
3968
3996
  controller.enqueue(`event: content_block_stop
@@ -4008,6 +4036,10 @@ data: ` + JSON.stringify({
4008
4036
  `);
4009
4037
  } else if (event.type === "text_delta") {
4010
4038
  ensureBlockStarted("text");
4039
+ if (isTitleTurn) {
4040
+ titleTextBuffer += event.delta;
4041
+ return;
4042
+ }
4011
4043
  controller.enqueue(`event: content_block_delta
4012
4044
  data: ` + JSON.stringify({
4013
4045
  type: "content_block_delta",
@@ -4058,6 +4090,17 @@ data: ` + JSON.stringify({
4058
4090
  for await (const event of { [Symbol.asyncIterator]: () => iter }) {
4059
4091
  processEvent(event);
4060
4092
  }
4093
+ if (isTitleTurn && titleTextBuffer.length > 0) {
4094
+ const cleanTitle = stripTitleMarkdown(titleTextBuffer);
4095
+ controller.enqueue(`event: content_block_delta
4096
+ data: ` + JSON.stringify({
4097
+ type: "content_block_delta",
4098
+ index: contentBlockIndex - 1,
4099
+ delta: { type: "text_delta", text: cleanTitle }
4100
+ }) + `
4101
+
4102
+ `);
4103
+ }
4061
4104
  closeActiveBlock();
4062
4105
  let finishReason = "end_turn";
4063
4106
  const finalMsg = await kiroStream.result();
@@ -4127,7 +4170,7 @@ data: ` + JSON.stringify({
4127
4170
  if (part.type === "text") {
4128
4171
  anthropicContent.push({
4129
4172
  type: "text",
4130
- text: part.text
4173
+ text: isTitleTurn ? stripTitleMarkdown(part.text) : part.text
4131
4174
  });
4132
4175
  } else if (part.type === "thinking") {
4133
4176
  anthropicContent.push({
package/dist/server.d.ts CHANGED
@@ -4,5 +4,16 @@ export declare function getAuthRegion(): string;
4
4
  export declare function initGatewayAuth(): Promise<void>;
5
5
  /** @internal — test helper to inject credentials without Kiro CLI */
6
6
  export declare function _seedCredentials(token: string, region?: string): void;
7
+ /**
8
+ * Strip wrapping markdown/quotes from a generated title. Kiro models often
9
+ * return titles wrapped in bold (`**Title**`), quotes, backticks, or with a
10
+ * leading heading/list marker, despite OpenCode's title prompt asking for
11
+ * plain text. OpenCode's own cleanup only strips <think> tags and takes the
12
+ * first non-empty line, so the wrapping survives into the session title.
13
+ *
14
+ * Applied ONLY to title-generation turns (see isTitleGenerationRequest), so
15
+ * normal assistant responses keep their markdown intact.
16
+ */
17
+ export declare function stripTitleMarkdown(text: string): string;
7
18
  export declare function startGatewayServer(port?: number): Promise<Server<any>>;
8
19
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AA2BlC,wBAAgB,aAAa,IAAI,MAAM,CAA0C;AAEjF,kDAAkD;AAClD,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CA+DrD;AAsBD,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAc,QAQnE;AAwBD,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CA2ezE"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AA2BlC,wBAAgB,aAAa,IAAI,MAAM,CAA0C;AAEjF,kDAAkD;AAClD,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CA+DrD;AAsBD,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAc,QAQnE;AA6CD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAevD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CA2gBzE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@javargasm/opencode-kiro-auth",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Kiro provider plugin for OpenCode: AWS Builder ID / Identity Center login and OpenAI compatible local gateway for CodeWhisperer streaming.",
5
5
  "type": "module",
6
6
  "license": "MIT",