@magpie-community/opencode-trae-auth 0.2.7 → 0.2.8

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/index.mjs +30 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1338,6 +1338,31 @@ function toolNamed(name, tools) {
1338
1338
  return names.find((n) => norm(n) === norm(name)) ?? name
1339
1339
  }
1340
1340
 
1341
+ // unwrapped is a call's arguments with the layer a model put around them
1342
+ // taken off: asked for {"name":…,"arguments":{…}}, some write the
1343
+ // arguments as {"arguments":{…}} again, natively or in the block, and the
1344
+ // agent got {"arguments":{"content":…,"path":…}} for its write (bee2an on
1345
+ // X). A lone arguments, input, parameters or args key holding an object is
1346
+ // that layer when the tool has no parameter of that name.
1347
+ const WRAPS = ["arguments", "input", "parameters", "args"]
1348
+ function unwrapped(args, name, tools) {
1349
+ const t = tools.map((x) => x.function ?? x).find((f) => f?.name === name)
1350
+ if (!t) return args
1351
+ const props = t.parameters?.properties ?? {}
1352
+ let v = looseJSON(args)
1353
+ let changed = false
1354
+ for (let k = 0; k < 3 && v && typeof v === "object" && !Array.isArray(v); k++) {
1355
+ const keys = Object.keys(v)
1356
+ if (keys.length !== 1 || !WRAPS.includes(keys[0]) || keys[0] in props) break
1357
+ let inner = v[keys[0]]
1358
+ if (typeof inner === "string") inner = looseJSON(inner)
1359
+ if (!inner || typeof inner !== "object" || Array.isArray(inner)) break
1360
+ v = inner
1361
+ changed = true
1362
+ }
1363
+ return changed ? JSON.stringify(v) : args
1364
+ }
1365
+
1341
1366
  // DeepSeek's tags, with its full-width bar or a plain one
1342
1367
  const DSML = String.raw`<\s*\/?\s*[||][\s||]*DSML[\s||]*`
1343
1368
  const DSML_AT = new RegExp(DSML)
@@ -1569,7 +1594,10 @@ async function* parts(events, tools = []) {
1569
1594
  const tt = new TextTools(tools)
1570
1595
  const nc = new NativeCalls()
1571
1596
  const th = new Thoughts()
1572
- const call = (c) => ({ call: { ...c, name: toolNamed(c.name, tools) } })
1597
+ const call = (c) => {
1598
+ const name = toolNamed(c.name, tools)
1599
+ return { call: { ...c, name, arguments: unwrapped(c.arguments, name, tools) } }
1600
+ }
1573
1601
  let finish = ""
1574
1602
  for await (const { event, data } of events) {
1575
1603
  const name = eventName(event)
@@ -2301,4 +2329,4 @@ const makePlugin = (site) => async ({ client }) => {
2301
2329
  export const TraeCNAuthPlugin = makePlugin(SITES["trae-cn"])
2302
2330
  export const TraeGlobalAuthPlugin = makePlugin(SITES["trae-global"])
2303
2331
 
2304
- export const _internal = { HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, toolNamed, traeMessages, chatBody, credits, dollarUsageOf, whenOf, newDevice, proofOf, SITES, SESSION, conversationID }
2332
+ export const _internal = { HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, toolNamed, unwrapped, traeMessages, chatBody, credits, dollarUsageOf, whenOf, newDevice, proofOf, SITES, SESSION, conversationID }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-trae-auth",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",